The problem is in your entry logic,
// buy position
if(cntBuy==0 && bufferRSI[1]>=InpRSILowerLevel && bufferRSI[0]<InpRSILowerLevel)
if(cntSell==0 && bufferRSI[1]<=InpRSIUpperLevel && bufferRSI[0]>InpRSIUpperLevel)
your enter sell position when previous bar is less then 75 and current bar is above 75 and the EA does what you code.
if you want to sell when RSI crosses below 75 the you must code it like this,
//buy position - crossing above from lower level
bufferRSI[1]<=InpRSILowerLevel && bufferRSI[0]>InpRSILowerLevel)
// sell position - crossing below from upper level
bufferRSI[1]>=InpRSIUpperLevel && bufferRSI[0]<InpRSIUpperLevel
you need to change both of your logic to make it more equal rather change only the sell position condition only
The problem is in your entry logic,
// buy position
if(cntBuy==0 && bufferRSI[1]>=InpRSILowerLevel && bufferRSI[0]<InpRSILowerLevel)
if(cntSell==0 && bufferRSI[1]<=InpRSIUpperLevel && bufferRSI[0]>InpRSIUpperLevel)
your enter sell position when previous bar is less then 75 and current bar is above 75 and the EA does what you code.
if you want to sell when RSI crosses below 75 the you must code it like this,
//buy position - crossing above from lower level
bufferRSI[1]<=InpRSILowerLevel && bufferRSI[0]>InpRSILowerLevel)
// sell position - crossing below from upper level
bufferRSI[1]>=InpRSIUpperLevel && bufferRSI[0]<InpRSIUpperLevel
you need to change both of your logic to make it more equal rather change only the sell position condition only
thank you so much!!
I will fix the code as suggested.
Again, thanks a lot!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello!
I need some help. I have an MT5 EA working right now based on the RSI Strategy. It works very well, but I wanted to make a change and I can't get it to work.
There is only one position open at a time. Even though I have coded stoploss and take profit, I have them both with value 0.
My buy position opens when the 30 line is crossed and it closes when the 75 line is crossed above, but also, at the same time, my sell position opens as soon as the line is crossed and the buy position is closed.
What I want to do, is that once the buy position closes, it waits until the 75 line is crossed below to open a sell position. I have come to see that I am spending a lot of money on Swaps while waiting for it to cross below the line. Same goes for the buying position.
I have tried to adjust it, but I can't get it to work and I honestly can't see a way to get it to work. Can you help me, please? Thank you!!
Here is my code for the opening positions
And this is my closing position function