Ordersend() and Orderclose() not working properly on 2 different brokers (both are 5 digits, non-ECN)

 

Hi everyone,

I am running my EA on MT4 provided by 2 different broker (FXCC and AxiTrader). Both are non-ECN, 5-digits broker. I also set my slippage to very large values, ranging from 10 to 1000. On backtesting, the EA runs properly on both brokers, with trade opened and closed at the same time. When I ran my trading on live, sometimes the EA on AxiTrader does not execute or close order whereas the one on FXCC does. There is no error printed in the journal.

I have attached parts of my codes. I could provided the full EA, but it is very long. Could anyone look into the problem please? Thank you very much.

datetime 
   bartime=0;
extern double RewardRatio, RiskPerTrade, MinZone;
int 
   TPTrade=0, OpenTrade=0, //opening position?
   i,Index=0,
   Slip=1000,
   OrderID, 
   EntryCandle,CandleTop, CandleBottom, CandlePosition, CandleAfter, CandlePrevious;
double     
   OrderSize,
   TrendStart=0,
   BullishEntrySignal=1000,BearishEntrySignal=-1, Entry=1,Stop=1,
   Zone[20],
   Variation=0;   
   
string  
   OpenPosition, TrendDirection;

int init()
{
   string ZoneName[20];
   int TrendDirectionTrack, OpenPositionTrack;
   for (i=0;i<=20;i++) 
   {
      ZoneName[i]="Zone" +CharToStr(i);
      Zone[i]=GlobalVariableGet(ZoneName[i]);
   }
   Index=GlobalVariableGet("GlobalIndex");
   OrderSize=GlobalVariableGet("GlobalOrderSize");
   OrderID=GlobalVariableGet("GlobalOrderID");  
   OpenTrade=GlobalVariableGet("GlobalOpenTrade");
   TPTrade=GlobalVariableGet("GlobalTPTrade");
   Entry=GlobalVariableGet("GlobalEntry");
   Stop=GlobalVariableGet("GlobalStop");
   RewardRatio=GlobalVariableGet("GlobalRewardRatio");
   BullishEntrySignal=GlobalVariableGet("GlobalBullishEntrySignal");
   BearishEntrySignal=GlobalVariableGet("GlobalBearishEntrySignal");
   TrendDirectionTrack=GlobalVariableGet("GlobalTrendDirectionTrack");
   EntryCandle=GlobalVariableGet("GlobalEntryCandle");
   if (TrendDirectionTrack==1) TrendDirection="Up";
   if (TrendDirectionTrack==0) TrendDirection="No";
   if (TrendDirectionTrack==-1) TrendDirection="Down";
   OpenPositionTrack=GlobalVariableGet("GlobalOpenPositionTrack");
   if (OpenPositionTrack==1) OpenPosition="Buy";
   if (OpenPositionTrack==-1) OpenPosition="Sell";
}

int start()
{  
   if (bartime != Time[0])
   {
      DetermineTrend(); //Determine Trend direction and candleposition after trend start
      if (TrendDirection=="Up") BullishStrategy();
      if (TrendDirection=="Down") BearishStrategy();
      bartime=Time[0];
   }
}

void Enter(string Direction)
{
   OrderSize=AccountBalance()*RiskPerTrade/100/MathAbs(Entry-Stop)/100000;
   if (iClose(NULL,0,0)>10) OrderSize=OrderSize*100;
   if (OrderSize<0.01) OrderSize=0.01;
   OpenTrade=1;     
   if (Direction=="Buy") 
   {
      OrderSend(Symbol(), OP_BUY,OrderSize, Ask, Slip, 0, 0, "Buy", 0, 0, Green);
      Print("Order sent"); //command run even when trade was not opened when running live on AxiTrader
   }
   if (Direction=="Sell") 
   {
      OrderSend(Symbol(), OP_SELL,OrderSize, Bid, Slip, 0, 0, "Sell", 0, 0, Green);
      Print("Order sent"); //command run even when trade was not opened when running live on AxiTrader
   }
   OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
   OrderID=OrderTicket();
   OrderSize=OrderLots();      
}

void Exit()
{
   if (OpenPosition=="Buy") 
   {
      OrderClose(OrderID, OrderSize, Bid,Slip,Red);
      Print("Order closed");  //command run even when trade was not closed when running live on AxiTrader
   }
   if (OpenPosition=="Sell") 
   {
      OrderClose(OrderID, OrderSize, Ask,Slip,Red);
      Print("Order closed");  //command run even when trade was not closed when running live on AxiTrader
   }
   OpenTrade=0;
   Index=0;
}

int deinit() //To save variables when EA restarts
{
   string ZoneName[20];
   int TrendDirectionTrack, OpenPositionTrack;
   for (i=0;i<=20;i++) 
   {
      ZoneName[i]="Zone" +CharToStr(i);
      GlobalVariableSet(ZoneName[i],Zone[i]);
   }
   GlobalVariableSet("GlobalIndex", Index);
   GlobalVariableSet("GlobalOrderSize",OrderSize);
   GlobalVariableSet("GlobalOrderID",OrderID);  
   GlobalVariableSet("GlobalOpenTrade",OpenTrade);
   GlobalVariableSet("GlobalTPTrade",TPTrade);
   GlobalVariableSet("GlobalEntry",Entry);
   GlobalVariableSet("GlobalStop",Stop);
   GlobalVariableSet("GlobalRewardRatio",RewardRatio);
   GlobalVariableSet("GlobalBullishEntrySignal",BullishEntrySignal);
   GlobalVariableSet("GlobalBearishEntrySignal",BearishEntrySignal);
   GlobalVariableSet("GlobalEntryCandle",EntryCandle);
   if (TrendDirection=="Up") TrendDirectionTrack=1;
   if (TrendDirection=="No") TrendDirectionTrack=0;
   if (TrendDirection=="Down") TrendDirectionTrack=-1;
   GlobalVariableSet("GlobalTrendDirectionTrack",TrendDirectionTrack);
   if (OpenPosition=="Buy") OpenPositionTrack=1;
   if (OpenPosition=="Sell") OpenPositionTrack=-1;
   GlobalVariableSet("GlobalOpenPositionTrack",OpenPositionTrack);
}
 
  1. What are Function return values ? How do I use them ? - MQL4 forum
  2. OrderSelect(0, SELECT_BY_POS
    EA is incompatible with every other EA (including itself on other charts) and manual trading.
  3. GlobalVariableSet("GlobalEntry"
    EA is incompatible with itself on other charts and with other EAs that use the same GV names.