EA Opens similar position when Stops are hit

[Deleted]  
I hope this finds everyone in good health. I am working on an expert adviser, but it is giving me a headache. The expert adviser open similar positions when stops or takeprofits are hit. That is, is a sell trade goes bad and hits a stop loss, the EA opens another trade immediately. Can anyone please lend me a code to prevent this. I have searched in the forum but I could only find an MT4 code. I only work with MetaTrader5. Save a soul. Thank you in advance
andrew4789  
Nelson Wanyama:
I hope this finds everyone in good health. I am working on an expert adviser, but it is giving me a headache. The expert adviser open similar positions when stops or takeprofits are hit. That is, is a sell trade goes bad and hits a stop loss, the EA opens another trade immediately. Can anyone please lend me a code to prevent this. I have searched in the forum but I could only find an nt4 code. I only work with MetaTrader5. Save a soul. Thank you in advance
This is might be to do with your code logic, not mt4/5 
After a sl or tp is hit, are the conditions for opening a trade still valid? Then of course a new trade will be made, unless your code does something to prevent it....for example, after a loss no trade for x bars or price not within x pts of stoploss...

[Deleted]  
andrew4789:
This is might be to do with your code logic, not mt4/5 
After a sl or tp is hit, are the conditions for opening a trade still valid? Then of course a new trade will be made, unless your code does something to prevent it....for example, after a loss no trade for x bars or price not within x pts of stoploss...

Let me see if I can restrict trading if CurrentPrice is above HistoryDealClosePrice. 
Please help me find a code to do  this. 
I just need the "if" statement 
Reason: