Hi all

I struggle to set the stop loss to break even once a trade is a certain amount in profit.

I want to achieve the following behaviour of the bot:

  • open new position with initial stop loss at entry signal
  • when profit > defined amount => set stoploss to break even (do not change stoploss afterwards)
  • if exit ondition is met, exit trade



I tried this with the code below using TMF (only long position shown).
With the stopflag I want to make sure the stop is just moved once and not touched after.
During testing I noticed that the stop loss is not always set to BE, even if profit was big enough, sometimes it seems the stop was moved up too high, and not just to BE.

I might not use the TMF functions correctly?
Thanks a lot for your advice!

BR, Luke


Code
#define stopflag TradeVar[0]

//TMF
int moveStopLong() {
	for(current_trades) {
		if(stopflag == 0) {
			if(TradeIsOpen and TradeIsLong and TradeProfit > 1) {
					stopflag = 1;
					Stop = 0.0007;
			}
		}
		// return 0 to let Zorro check the stop/profit limits
		return 0;
	}
}

//main loop
function run()
...some conditions
     enterLong(moveStopLong, Stop=20*PIP);

..some other conditions
    exitLong();