MA EA - problems on server

 

Hello guys,

I am attaching a very good EA which I trade successfully for some time. But there is probably some feature missing in the source code, because when I set it on VPS a few weeks ago, it did not trade at all. It only works if it is the only EA but not work at all, if I set up other EAs at the same time... Is there any mistake in my coding? Could you help me to fix it?

Thank you in advance!

Martin

Files:
fxjma.mq4  7 kb
 
  1. res=OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, 3, Bid+StopLoss*DigitPoint(),
                  Bid-TakeProfit*DigitPoint(), "", MAGICMA, 0, Red);
    
    You're adjusting TP and SL for 5 digit brokers, but you must ALSO adjust slippage
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  2. On ECN brokers you must open and THEN set stops.
  3. Always check return codes so you know WHY
    res=OpenOrder(...);
    if (res<0) Alert("OpenOrder failed: ", GetLastError());

  4.   if(LotStep==1) LotDigit=0;
      if(LotStep==0.1) LotDigit=1;
      if(LotStep==0.01) LotDigit=2;
      //////////////////////////////////////////
      Lot=NormalizeDouble(LotSize,LotDigit);
    
    fails for any other lot step (like 0.05)
    Lot= MathFloor(LotSize/lotStep)*lotStep;

  5. //---- go trading only for first tiks of new bar
       if(Volume[0]>1) return;
    
    Volume is unreliable, you can miss ticks. Bars is unreliable, doesn't change past max bars on chart. Always use time
    int start(){
       //---- go trading only for first tiks of new bar
       static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0];

  6. You MUST count down when closing in the presence of multiple orders (multiple charts)
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
    

 
WHRoeder:
  1. You're adjusting TP and SL for 5 digit brokers, but you must ALSO adjust slippage
  2. On ECN brokers you must open and THEN set stops.
  3. Always check return codes so you know WHY

  4. fails for any other lot step (like 0.05)
  5. Volume is unreliable, you can miss ticks. Bars is unreliable, doesn't change past max bars on chart. Always use time
  6. You MUST count down when closing in the presence of multiple orders (multiple charts)


Hello,

Thank you very much for your help! I made the changes you suggested and hope it will work well on my server. However, I couldn't manage to adjust the slippage for 5 digit brokers. Could you change it for me directly in the code (in the attachement)?

 
billy90:


Hello,

Thank you very much for your help! I made the changes you suggested and hope it will work well on my server. However, I couldn't manage to adjust the slippage for 5 digit brokers. Could you change it for me directly in the code (in the attachement)?

Files:
fxumar3.mq4  8 kb
 
billy90:
However, I couldn't manage to adjust the slippage for 5 digit brokers. Could you change it for me directly in the code (in the attachement)?
Look at #1 your code and the comment at the bottom of mine.
 
WHRoeder:
Look at #1 your code and the comment at the bottom of mine.


I am at a dead end with the slippage adjusting... I did the following changes as suggested:

void CheckForOpen()

{

double ma;

int res;

int pips2points;

double pips2dbl;

int Digits.pips;

//---- go trading only for first tiks of new bar

static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0];

//---- get Moving Average

ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

//---- sell conditions

if(Open[1]>ma && Close[1]<ma)

{

res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3*pips2point,Bid+StopLoss*pips2dbl(),Bid-TakeProfit*pips2dbl(),"",MAGICMA,0,Red);

if (res<0) Alert("OpenOrder failed: ", GetLastError());

return;

}

//---- buy conditions

if(Open[1]<ma && Close[1]>ma)

{

res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3*pips2point,Ask-StopLoss*pips2dbl(),Ask+TakeProfit*pips2dbl(),"",MAGICMA,0,Blue);

if (res<0) Alert("OpenOrder failed: ", GetLastError());

return;

}

}

but I still have problems with placing these lines:

int init(){
if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers.
pips2dbl = Point*10; pips2points = 10; Digits.pips = 1;
} else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; }

Where exactly do I have to place it? i guess I should replace this part:

//DIGITS PART//
double DigitPoint()
{
double MYpoint=Point;
////////////////////////////////////
if(Digits==5||Digits==3)
{
MYpoint=Point*10;
}
return(MYpoint);
}

But it shows many errors when doing so...

 
billy90:
But it shows many errors when doing so...

  1. 3*pips2point,Bid+StopLoss*pips2dbl(),Bid-TakeProfit*pips2dbl(),
    The error message points to this line. pips2dbl is a variable, why do you have ()'s
  2. int init(){
       if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers.
         pips2dbl = Point*10; pips2points = 10; Digits.pips = 1;
       } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; }
    
    // Where exactly do I have to place it? i guess I should replace this part:
    Where's the closing brace for the init.
  3. When in doubt, THINK. /*comment*/ out portions until you isolate the problem.
 
WHRoeder:

  1. The error message points to this line. pips2dbl is a variable, why do you have ()'s
  2. Where's the closing brace for the init.
  3. When in doubt, THINK. /*comment*/ out portions until you isolate the problem.


Hi,

I finally adjusted the slippage. Thank you very much for your help.

I have just one last question.

Always check return codes so you know WHY:

  1. res=OpenOrder(...);
    if (res<0) Alert("OpenOrder failed: ", GetLastError());
  • What does the alert "Open order failed" signals? Why does it show the alert even when no indicator signals to open a trade?
 
billy90:


Hi,

I finally adjusted the slippage. Thank you very much for your help.

I have just one last question.

Always check return codes so you know WHY:

  • What does the alert "Open order failed" signals? Why does it show the alert even when no indicator signals to open a trade?


It is strange, that the robot works on Alpari, XTB and FX Pro without any problems, but it does not work on IBFX - every time it should open a trade, it shows the alert "OpenOrder failed: ". Do you have any idea, where the problem is?
 
I know what's gonna get pasted :PPP
 
billy90:
why does it show the alert even when no indicator signals to open a trade?
  1. You have something still wrong with OrderSend()
  2. You are calling OrderSend() even when "no indicator signal to open a trade."

It is strange, that the robot works on Alpari, XTB and FX Pro without any problems, but it does not work on IBFX
My first reply #2:
On ECN brokers you must open and THEN set stops.