Expert advisor running profit but also taking loss

 

I have written a code that I use to take profit in XAUUSD for 1 minute time frame. the problem with this EA is that it can make a profit when it follow the trend line, but when reversal came I keep taking losses, thus diminishing my profit. is there any way to fix my code ?

As you can read from the code, when the candle break above or below the moving average line, I will initiate a buy stop or sell stop action. the portion code down below is to continuously adjust SL and TP. after a long build up downwards / upwards, the graph tends to just move up hit the entry point, hit the sl and hit entry point again before it truly reverse it's cycle.

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Every mql5-program allows to specify additional specific parameters named #property that help client terminal in proper servicing for programs...
Files:
test.mq5  7 kb
 
izzuddin muhd:

I have written a code that I use to take profit in XAUUSD for 1 minute time frame. the problem with this EA is that it can make a profit when it follow the trend line, but when reversal came I keep taking losses, thus diminishing my profit. is there any way to fix my code ?

As you can read from the code, when the candle break above or below the moving average line, I will initiate a buy stop or sell stop action. the portion code down below is to continuously adjust SL and TP. after a long build up downwards / upwards, the graph tends to just move up hit the entry point, hit the sl and hit entry point again before it truly reverse it's cycle.

So adjust your strategy 
Reason: