Download MetaTrader 5

My own trailing stop

To add comments, please log in or register
francysouz
39
francysouz  

Hi everyone,

 

I'm trying to make my own trailing stop, because I want to put my own stop rules.

 

As a test I made this stop which I put in OnTick () class, but analyzing this stop I noticed that he has a problem, he never stays in profit zone .. always is an amount as a small prejudice .. even if there is a possibility he stay in PROFIT zone ..

Someone can tell me why ??

Below is a part of the trailing stop ....

I thank everyone for the help ..




 

 

double stop = PositionGetDouble(POSITION_SL);
double take = PositionGetDouble(POSITION_TP);
if(PositionSelect(Symbol())==true && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){
      double sell_value;
      PositionGetDouble(POSITION_PRICE_CURRENT, sell_value);
      if(last_price.bid < sell_value ){
         stop = NormalizeDouble(last_price.bid +40*_Point,_Digits);
         take = NormalizeDouble(last_price.bid - 200*_Point,_Digits);
         Print("Mudando TP e SL posição de venda.");
         mrequest.sl = stop;
         mrequest.tp = take;
         if(OrderSend(mrequest,mresult)){
              if(mresult.retcode!=TRADE_RETCODE_DONE){
               Print("OrderSend failed with error #",GetLastError());
             }
         }else{
             printf("Unable to move Stop Loss of position %s, error #%I64u",_Symbol,mresult.retcode);
         }
      }
  }

   if(PositionSelect(Symbol())==true && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){
      double buy_value;
      PositionGetDouble(POSITION_PRICE_CURRENT, buy_value);
      if(last_price.ask > buy_value ){
         Print("Mudando TP e SL posição de compra.");
         stop = NormalizeDouble(last_price.ask -40*_Point,_Digits);
         take = NormalizeDouble(last_price.ask + 200*_Point,_Digits);
         mrequest.sl = stop;
         mrequest.tp = take;
         if(OrderSend(mrequest,mresult)){
           if(mresult.retcode!=TRADE_RETCODE_DONE){
               Print("OrderSend failed with error #",GetLastError());
           }
         }else{
             printf("Unable to move Stop Loss of position %s, error #%I64u",_Symbol,mresult.retcode);
         }
      }
   }
To add comments, please log in or register