Trying to write a Trailing Hedge EA, but I'm stuck - Please help

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
74
Trader3000 2016.01.25 09:25 #
 

Hello Everyone.  I am now on version 52.  I have the trailing stop working on pairs such as the EURUSD where 1 pip = $1.  I found out that with pairs such as the JPY, 1 pip = $0.93.  I have tried evrything to correct for this, but I am unable to figure it out.  I think I need to either multiply something with 1.11111 or 0.93 divide something with 1.11111 or 0.93.  I simply want the EA to be accurate, i.e. that when I set the trailing stop to kick in at 10 pips, I want it to kick in at 10 pips and not at 9.3 pips.  Can someone please shed some light on this please.

 

#property copyright "Kruger"
// #property link      "http://www.*****.com"

// Kicks in when position reaches at least TrailingStop pips of profit.

extern string LabelPips = "Value in Pips";
extern double TrailingStart = 10; 
extern double TrailingStop = 5;
 
double res;

int init()
{
   return(0);
}
 
int deinit()
{
   return(0);
}
 
int start()
{

  for (int i = 0; i < OrdersTotal(); i++) 
  {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
      if (OrderSymbol()==Symbol() )
      double pip = (MarketInfo(OrderSymbol(), MODE_POINT))*10;
      
     if (OrderType() == OP_BUY) 
      {
        if (Bid - OrderOpenPrice() > NormalizeDouble(TrailingStart *pip,4)) 
         {
           if (OrderStopLoss() < Bid - NormalizeDouble(TrailingStop * pip,4)) 
            {
              if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid - NormalizeDouble(TrailingStop * pip,4), OrderTakeProfit(), Blue))
              if(!res) 
              Print("Error setting Buy trailing stop: ",GetLastError()); 
            else 
               Print("Order modified successfully."); 
              }
            }
          }
     else if (OrderType() == OP_SELL)
      {
        if (OrderOpenPrice() - Ask > NormalizeDouble(TrailingStart * pip,4)) 
         {
          if ((OrderStopLoss() > Ask + NormalizeDouble(TrailingStop * pip,4)) || (OrderStopLoss() == 0))
           {
              if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask + NormalizeDouble(TrailingStop * pip,4), OrderTakeProfit(), Red))
              if(!res) 
              Print("Error setting Sell trailing stop: ",GetLastError()); 
            else 
               Print("Order modified successfully."); 
              }
                 }
          }
         }
    return(0);
}
Back to topics list   | 1 2  

To add comments, please log in or register