lock profit without trail

Posted By: Grat

lock profit without trail - 07/14/19 15:53

Hi,

I dont like trail function. With this TMF function you can lock profit without laugh

Code
//--------------------- TMF --------------------------------------------------------
#define VAR_LOCK TradeVar[0]
#define VAR_ACTI TradeVar[1]
#define VAR_CLOSE TradeVar[2]

int myTMF(){
  if (TradeIsEntry){
    // only one each trade?
    VAR_LOCK=-1;  // No lock
    VAR_ACTI=1*TradeLots;          // 1 USD/per LOTS ... MT4 1=0.01
    VAR_CLOSE=VAR_ACTI*0.8;        // after profit is target, profit under 80% close trade
  }
  
  if(TradeIsOpen){
    if (TradeProfit > VAR_ACTI)
      VAR_LOCK=1.0; // activate trigger

    if (VAR_LOCK > 0 )
    if (TradeProfit < VAR_CLOSE){
      exitTrade(ThisTrade);
      return 16;
    }

    if (TradeProfit > VAR_ACTI*1.05){
      // Profit > ACTI+5%
      VAR_ACTI=TradeProfit;
      VAR_CLOSE=VAR_ACTI*0.8;
    }
  }    
  
  return 0;
}
Posted By: danatrader

Re: lock profit without trail - 09/15/20 06:05

Nice, I will make use of it (potentially) laugh
Posted By: Grat

Re: lock profit without trail - 09/16/20 08:05

Yes,

in the original is a bug:

int myTMF(){
if (VAR_LOCK == 0){
Posted By: danatrader

Re: lock profit without trail - 09/17/20 21:05

This is not Grat, this is Great laugh
Posted By: danatrader

Re: lock profit without trail - 09/18/20 13:27

Is it needed in case of MaxLong = MaxShort > 1 to have a for(current_trades) loop in a TMF or does TMF automatically go through all open trades?
Posted By: Grat

Re: lock profit without trail - 09/18/20 14:30

TRADE* EnterTrade(int side)
{
if (side == _LONG)
return enterLong(myTMF);
else
return enterShort(myTMF);
}
Posted By: kalmar

Re: lock profit without trail - 09/24/20 09:59

Thank you, Grat laugh And what is the problem with trails? Thx
Posted By: danatrader

Re: lock profit without trail - 09/25/20 06:46

Trails in many times reduce profit.
© 2024 lite-C Forums