Need short help

I have a nervous line and if a short event occurs the it should be saved. For the next round.The countertrade should reset this. Vise Versa.I did this with statichvar and it works so far. I Test it with
paramtrigger Signal by hand. If i use the Trading Rule, it will not work. I try Lastvalue() and IIF but without success. Is there a way to do this better?.
If anyone can help, I would be grateful for that.

Regard DB

Her my Test Snipe:

WMA_1=WMA(C,4);
WMA_2=WMA(C,8);
WMA_3=WMA(C,20);
Plot(WMA_1,"",colorwhite,styleline);//4
Plot(WMA_2,"",colorred,styleline);//8
Plot(WMA_3,"",colorgreen,styleline);//12

Buy_Trig_P=ParamTrigger("Test_Buy","Test_Buy");   // For Debug
Sell_Trig_P=ParamTrigger("Test_Sell","Test_Sell");// For Debug

/*--------------------Tade Rule ----------------------------*/

Buy_sig   =Cross (WMA_1,WMA_2) AND Cross (WMA_2,WMA_3) OR Buy_Trig_P; 
Sell_sig  =Cross (WMA_2,WMA_1) AND Cross (WMA_3,WMA_2) OR Sell_Trig_P; 

//................................................

if(LastValue(Buy_sig)) {StaticVarSet("Buy_status",1);StaticVarSet("Sell_status",0);}
Buy_sig = StaticVarGet("Buy_status"); 

//................................................


if(LastValue(Sell_sig)) {StaticVarSet("Buy_status",0) ;StaticVarSet("Sell_status",1);}	             	
Sell_sig = StaticVarGet("Sell_status");
//...........Transfer Tadesig to Buy/Sell .........

Buy  = flip(Buy_sig , Sell_sig );
Sell = flip(Sell_sig, buy_sig ); 


//printf("Buy_Trig  =  "+Buy_Trig+"\n"+"Sell_Trig  =  "+Sell_Trig+"\n"+"\n");
printf("Buy_sig  =  "+Buy_sig+"\n"+"Sell_sig  =  "+Sell_sig+"\n"+"\n");
printf("Buy  =  "+Buy+"\n"+"Sell  =  "+Sell+"\n");
//...............................................................ENDE

Hello @dbrumm

You may try the function ValueWhen()

WMA_1=WMA(C,4);
WMA_2=WMA(C,8);
WMA_3=WMA(C,20);
Plot(WMA_1,"",colorwhite,styleline);//4
Plot(WMA_2,"",colorred,styleline);//8
Plot(WMA_3,"",colorgreen,styleline);//12

/*--------------------Tade Rule ----------------------------*/

Buy_sig   =(Cross (WMA_1,WMA_2) AND Cross (WMA_2,WMA_3));  
Sell_sig  =(Cross (WMA_2,WMA_1) AND Cross (WMA_3,WMA_2)); 

//................................................
//  
Last_Buy_sig = ValueWhen(Buy_sig,close,1);  printf(" Close of Last_Buy_sig =\t" + Last_Buy_sig + "\n"); 
Last_Sell_sig = ValueWhen(Sell_sig,close,1);  printf(" Close of Last_Buy_sig =\t" + Last_Sell_sig + "\n"); 

// Also you can keep the last value of the ARRAY. Example below line
event_last_close=  LastValue( ValueWhen(Sell_sig,close,1)  ); 

//................................................

printf("Buy_sig  =  "+Buy_sig+"\n"+"Sell_sig  =  "+Sell_sig+"\n"+"\n");

PlotShapes(IIf(Buy_sig, shapeSmallCircle,shapeNone),5,0,WMA_3,0); 
PlotShapes(IIf(Sell_sig, shapeHollowCircle,shapeNone),4,0,WMA_3,0); 
printf("Buy_sig  =  "+Buy_sig+"\n"+"Sell_sig  =  "+Sell_sig+"\n"+"\n");

Thanks for the good suggestion, good idea so I will do it.
At the same time, it also gives me the opportunity for further calculations.Thank you!

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.