Download MetaTrader 5

help for ea take profit

To add comments, please log in or register
No time to learn MQL5? Order your application from a developer!
tito78 2016.11.08 00:29 

hello friends  this is ea take profit but  not work in 4 digit broker

I would like it to work with my 4 digit brokers, can you help me?

where is the error?  thank you


//| expert start function                                            |
int start()
   int StopMultd=10;
   double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
   double SL=NormalizeDouble(StopLoss*StopMultd,Digits);
// orders
  for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
          if((MonitorTakeProfit==true)&&(TakeProfit>0)&&(OrderMagicNumber()==0)){ // monitor tp
                // Calculate take profit
                double tpb=NormalizeDouble(OrderOpenPrice()+TP*Point,Digits);
                double tps=NormalizeDouble(OrderOpenPrice()-TP*Point,Digits);
                Comment("Modifying take profit");
                if((OrderType()==OP_BUY)&&(OrderTakeProfit()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,OrderStopLoss(),tpb,0,CLR_NONE); }
                if((OrderType()==OP_SELL)&&(OrderTakeProfit()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,OrderStopLoss(),tps,0,CLR_NONE); }

          } // monitor tp
          if((MonitorStopLoss==true)&&(StopLoss>0)&&(OrderMagicNumber()==0)){ // monitor sl
                   // Calculate stop loss
                   double slb=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits);
                   double sls=NormalizeDouble(OrderOpenPrice()+SL*Point,Digits);

                   Comment("Modifying stop loss");
                   if((OrderType()==OP_BUY)&&(OrderStopLoss()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,slb,OrderTakeProfit(),0,CLR_NONE); }
                   if((OrderType()==OP_SELL)&&(OrderStopLoss()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,sls,OrderTakeProfit(),0,CLR_NONE); }

          }// monitor sl
int Error=GetLastError();
  if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
  if(Error==133){Alert("Trading prohibited.");}
  if(Error==2){Alert("Common error.");}
  if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}


Marco vd Heijden
Marco vd Heijden 2016.11.08 09:14  
double pip;

//--- 1.1. Define pip -----------------------------------------------------
   if(Digits==4 || Digits<=2) pip=Point;
   if(Digits==5 || Digits==3) pip=Point*10;

Maybe you can try this.

Code base has a lot of examples for you to examine.

MQL5 Code Base
MQL5 Code Base
MQL5 Source Code Library for MetaTrader 5
whroeder1 2016.11.08 14:39  
tito78: not work in 4 digit broker
  1. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
  2. You must adjust for 4/5 digit brokers
    There is Tick, PIP, and Point. They are all different in general. A tick is the smallest change of price. A Point is the least significant digit quoted. In currencies a pip is defined as 0.0001 (or for JPY 0.01)

    On a 4 digit broker a point (0.0001) = pip (0.0001). [JPY 0.01 == 0.01] On a 5 digit broker a point (0.00001) = 1/10 pip (0.00010/10). Just because you quote an extra digit doesn't change the value of a pip. (0.0001 == 0.00010) EA's must adjust pips to points (for mq4.) In currencies a tick is a point. Price can change by least significant digit (1.23456 -> 1.23457)

    In metals a Tick is still the smallest change but is larger than a point. If price can change from 123.25 to 123.50, you have a TickSize of 0.25 and a point of 0.01. Pip has no meaning.

    This is why you don't use TickValue by itself. Only as a ratio with TickSize. See DeltaValuePerLot()

tito78 2016.11.26 23:13  
  1. You must adjust for 4/5 digit brokers
thank you
To add comments, please log in or register