Help figuring out why my EA trailing stop loss works but modifies more than it is supposed to

To add comments, please log in or register
senbonzuka
50
senbonzuka  

So, I did a 17.5 stop loss trail with 3 pip increase to stop loss and it is doing way more than 3 pip increases. 

extern bool Use_Stop_Loss=true;
extern double When_to_Move_Stop_Loss=17.5;
extern double Trail_Amount=3.0;

//+------------------------------------------------------------------+
//| Trailing Stop Function
//+------------------------------------------------------------------+
void Trailing_Stop(int ticket,int ordertype,double Price,double  stoploss,double takeprofit,double openprice,int MagicNum)
  {
   bool Ans;
   for(int OrderIndex=OrdersTotal()-1; OrderIndex>=0; OrderIndex--)
     {
      if(OrderSelect(OrderIndex,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderMagicNumber()==Magic_Number)
           {
            if(OrderSymbol()==Symb)
              {
               if(OrderType()==OP_BUY)
                 {
                  if(Bid-OrderStopLoss()>When_to_Move_Stop_Loss*vPoint)
                    {
                     Comment("Bid -  OrderStopLoss(): ",Bid-OrderStopLoss(),
                             "greater than When to move Stop Loss: ",When_to_Move_Stop_Loss*vPoint);
                     Print("Bid -  OrderStopLoss(): ",Bid-OrderStopLoss(),
                           "greater than When to move Stop Loss: ",When_to_Move_Stop_Loss*vPoint);
                     if(OrderStopLoss()<Bid -(vPoint*Trail_Amount))
                       {
                        Comment("StopLoss Modified!");
                        Print("StopLoss Modified!");
                        Ans=OrderModify(OrderTicket(),OrderOpenPrice(),Bid -(vPoint*Trail_Amount),OrderTakeProfit(),0,clrNONE);
                       }
                    }
                 }
              }
           }
        }
     }
  }

Here is the logs - 


1    2018.11.26 05:01    buy    1    0.01    128.288    0.000    0.000    0.00    10000.00
2    2018.11.26 05:01    modify    1    0.01    128.288    128.030    128.780    0.00    10000.00
3    2018.11.26 05:01    modify    1    0.01    128.288    128.248    128.780    0.00    10000.00
4    2018.11.26 06:58    modify    1    0.01    128.288    128.394    128.780    0.00    10000.00
5    2018.11.26 09:04    modify    1    0.01    128.288    128.543    128.780    0.00    10000.00
6    2018.11.26 10:02    modify    1    0.01    128.288    128.703    128.780    0.00    10000.00
7    2018.11.26 10:02    t/p    1    0.01    128.780    128.703    128.780    4.30    10004.30

nicholi shen
2253
nicholi shen  
senbonzuka:

So, I did a 17.5 stop loss trail with 3 pip increase to stop loss and it is doing way more than 3 pip increases. 

Here is the logs - 


1    2018.11.26 05:01    buy    1    0.01    128.288    0.000    0.000    0.00    10000.00
2    2018.11.26 05:01    modify    1    0.01    128.288    128.030    128.780    0.00    10000.00
3    2018.11.26 05:01    modify    1    0.01    128.288    128.248    128.780    0.00    10000.00
4    2018.11.26 06:58    modify    1    0.01    128.288    128.394    128.780    0.00    10000.00
5    2018.11.26 09:04    modify    1    0.01    128.288    128.543    128.780    0.00    10000.00
6    2018.11.26 10:02    modify    1    0.01    128.288    128.703    128.780    0.00    10000.00
7    2018.11.26 10:02    t/p    1    0.01    128.780    128.703    128.780    4.30    10004.30

Was this slapped together from many different functions? 

senbonzuka
50
senbonzuka  
nicholi shen:

Was this slapped together from many different functions? 

Not at all, the parameters are the order select values, if that is what you are referring to. I just have not used them yet . Maybe will not be needed because it runs outside of my order accounting loop which is in my start function.
Alain Verleyen
37188
Alain Verleyen  
senbonzuka:

So, I did a 17.5 stop loss trail with 3 pip increase to stop loss and it is doing way more than 3 pip increases. 

Your code trails by 3 pips, nowhere it's coded "3 pip increases".

Here is the logs - 


1    2018.11.26 05:01    buy    1    0.01    128.288    0.000    0.000    0.00    10000.00
2    2018.11.26 05:01    modify    1    0.01    128.288    128.030    128.780    0.00    10000.00
3    2018.11.26 05:01    modify    1    0.01    128.288    128.248    128.780    0.00    10000.00
4    2018.11.26 06:58    modify    1    0.01    128.288    128.394    128.780    0.00    10000.00
5    2018.11.26 09:04    modify    1    0.01    128.288    128.543    128.780    0.00    10000.00
6    2018.11.26 10:02    modify    1    0.01    128.288    128.703    128.780    0.00    10000.00
7    2018.11.26 10:02    t/p    1    0.01    128.780    128.703    128.780    4.30    10004.30

Your log doesn't correspond to the code you posted. Posted the relevant log.

What is the problem with this log you posted ?

senbonzuka
50
senbonzuka  
Alain Verleyen:
Your code trails by 3 pips, nowhere it's coded "3 pip increases".

Your log doesn't correspond to the code you posted. Posted the relevant log.

What is the problem with this log you posted ?

Ok, I did the trail stop loss function exactly as instructed from multiple sources so i assumed the Trail Amount is the increment part which is 3.0 but when multiplied by vPoint -  it is multiplied by to the pip value. From what I understand, when there is a 17.5 pip difference, it will increase the stop loss by 3 pips.

So, what is my code doing?


//+------------------------------------------------------------------+
//| Initialization function for 3 and 5 digit brokers                                           |
//+------------------------------------------------------------------+
int init()
  {

   if(Digits==3 || Digits==5)
     { vPoint=Point*10; vSlippage=Slippage*10; }
   else{ vPoint=Point; vSlippage=Slippage; }

   return(0);
  }
Alain Verleyen
37188
Alain Verleyen  
senbonzuka:

Ok, I did the trail stop loss function exactly as instructed from multiple sources so i assumed the Trail Amount is the increment part which is 3.0 but when multiplied by vPoint -  it is multiplied by to the pip value. From what I understand, when there is a 17.5 pip difference, it will increase the stop loss by 3 pips.

So, what is my code doing?


It's not what it is doing. What it is doing is when profit is greater than 17.5 "vPoint" if moves the stoploss to current close price - 3 vPoint. vPoint being supposed to be the same as 1 pip.

So at 17.5 pips it will put the stoploss at 14.5 pips...if it reached 50 pips, it will place the stoploss at 47 pips, etc...

senbonzuka
50
senbonzuka  
Alain Verleyen:

It's not what it is doing. What it is doing is when profit is greater than 17.5 "vPoint" if moves the stoploss to current close price - 3 vPoint. vPoint being supposed to be the same as 1 pip.

So at 17.5 pips it will put the stoploss at 14.5 pips...if it reached 50 pips, it will place the stoploss at 47 pips, etc...

Thank you, that explains why it is moving too high. Thank you so much.

To add comments, please log in or register