EA does not follow specified instructions.

 
Hi everyone. I have created EA which enters a long trade when RSI is above 70 and a short trade when RSI below 30. However, sometimes it enters either a short trade when RSI is above 30, and a long trade when RSI is below 70 which contradicts my if statement. In program, I have   specified if(RSI[0]<30) enters a short, and when if(RSI[0]>70) enters a long. I have attached screenshot to see. Thanks
Files:
EA.png  42 kb
 
Launger:
Hi everyone. I have created EA which enters a long trade when RSI is above 70 and a short trade when RSI below 30. However, sometimes it enters either a short trade when RSI is above 30, and a long trade when RSI is below 70 which contradicts my if statement. In program, I have   specified if(RSI[0]<30) enters a short, and when if(RSI[0]>70) enters a long. I have attached screenshot to see. Thanks
Place a "if (TimeCurrent()>= D'20210902 03:57') DebugBreak(); in OnTick right before the relevant variables are set and check it - it is made for this.
 

Hi, Thanks for suggestion. But I have figured out that current RSI value [0] can actually cross 70 for a second so the open trade is triggered, but right after that RSI value falls below 70 and never crosses it back. So the problem is that current value does not close above 70 it just crosses it for a second.

Carl Schreiber #:
Place a "if (TimeCurrent()>= D'20210902 03:57') DebugBreak(); in OnTick right before the relevant variables are set and check it - it is made for this.
 
Launger # :

Hi, Thanks for suggestion. But I have figured out that current RSI value [0] can actually cross 70 for a second so the open trade is triggered, but right after that RSI value falls below 70 and never crosses it back. So the problem is that current value does not close above 70 it just crosses it for a second.

And you, in this case, start checking the signal on bar # 1.

 

it looks like repainting, the RSI value was once met the requirement when the bar has not closed, but then end without meeting your requirement when the bar closed

you can set iRSI on the last bar closed instead of the current bar to solve this