MT4 EA returning wrong bid and ask price different from those visible on chart

 

Good day... 

I am making an EA that opens orders depending on time, (e.g at exactly 1pm). The EA opens orders on the chart it is loaded on, so if it is on GBPUSD, USDJPY and EURUSD, it will place orders at exactly 1pm on both pairs. The EA compiles without errors but the problem is as follow:

The EA keeps mixing prices of one chart with another. For example if the EA on GBPUSD chart places a pending/market buy order at 1.30121, the EA on USDJPY attempts to place an order at 1.30121 although each chart has its own EA which gets the bid price before sending the order. As a result, I get an error because I can't use 1.30121 on USDJPY. 

I tried putting a delay between the opening of orders when it is time to open the orders, e.g if it is 1pm, buy GBPUSD, wait for 2 seconds and buy USDJPY and after 4 seconds, buy EURUSD. I did this to give time to each EA to get the current bid and ask prices but I find that the bid price being used lets say on USDJPY is that from GBPUSD. 

I then tried putting a refresh rates before getting bid and ask prices but yet to no avail. I tried displaying the current bid and ask price of any pair on which I place the EA during initialization and I realised that the prices are only correct on some charts and wrong on others. 

The problem seem to be that the EA is not discarding the values in variables and I don't get how variables of same EA on one chart gets mixed up with variables on another chart (Same EA on MT4 terminal but loaded on different charts) . The bid and ask prices are requested per tick using  ' MarketInfo(OrderSymbol(), MODE_ASK) ' or MODE_BID for example. 

Is there anyway to discard values and get new values for the respective chart on which the EA is placed. 

See picture attached. 

Any help and correction is welcome, 

Thanks in advance

 
ITM7:

Good day... 

I am making an EA that opens orders depending on time, (e.g at exactly 1pm). The EA opens orders on the chart it is loaded on, so if it is on GBPUSD, USDJPY and EURUSD, it will place orders at exactly 1pm on both pairs. The EA compiles without errors but the problem is as follow:

The EA keeps mixing prices of one chart with another. For example if the EA on GBPUSD chart places a pending/market buy order at 1.30121, the EA on USDJPY attempts to place an order at 1.30121 although each chart has its own EA which gets the bid price before sending the order. As a result, I get an error because I can't use 1.30121 on USDJPY. 

I tried putting a delay between the opening of orders when it is time to open the orders, e.g if it is 1pm, buy GBPUSD, wait for 2 seconds and buy USDJPY and after 4 seconds, buy EURUSD. I did this to give time to each EA to get the current bid and ask prices but I find that the bid price being used lets say on USDJPY is that from GBPUSD. 

I then tried putting a refresh rates before getting bid and ask prices but yet to no avail. I tried displaying the current bid and ask price of any pair on which I place the EA during initialization and I realised that the prices are only correct on some charts and wrong on others. 

The problem seem to be that the EA is not discarding the values in variables and I don't get how variables of same EA on one chart gets mixed up with variables on another chart (Same EA on MT4 terminal but loaded on different charts) . The bid and ask prices are requested per tick using  ' MarketInfo(OrderSymbol(), MODE_ASK) ' or MODE_BID for example. 

Is there anyway to discard values and get new values for the respective chart on which the EA is placed. 

See picture attached. 

Any help and correction is welcome, 

Thanks in advance

Show your code.
 
nicholi shen:
Show your code.
 double pAsk, pp;
   pp = MarketInfo(OrderSymbol(), MODE_POINT);
   pAsk = MarketInfo(OrderSymbol(), MODE_ASK);

   int err,ticket;
   double myStopLoss=0, myTakeProfit=0;
   double LongTradeRate=NormalizeDouble(pAsk + (pendingOrderDist*PipsToPointFactor()*pp),Digits);
   
   myStopLoss = NormalizeDouble(LongTradeRate - (PipsToPointFactor()*StopLoss*pp),Digits);
   
   myTakeProfit = NormalizeDouble(LongTradeRate + (PipsToPointFactor()*TakeProfit*pp),Digits);
   
   ticket=OrderSend(Symbol(),OP_BUYSTOP,lotMM,LongTradeRate,(Slippage*PipsToPointFactor()*pp),myStopLoss,myTakeProfit,NULL,MagicNumber,0,Blue);
   if (ticket>0) 
   {   buyPendingOrderCompleted = true;  
      // MessageBox("1 Buy Pending order should be opened by now");
      // PlaySound("alert.wav");
   }
   if(ticket<=0)
     {
      err=GetLastError();
      Print("Error opening BUY STOP order [" + setup + "]: (" + err + ") " + ErrorDescription(err));
     }
    
  

Nicholi Shen, 

Thank you for taking time to consider, see above code

 
It's because you are using the wrong function. OrderSymbol returns the symbol of the last selected order in the order pool. Symbol returns the chart symbol. 
 
nicholi shen:
It's because you are using the wrong function. OrderSymbol returns the symbol of the last selected order in the order pool. Symbol returns the chart symbol. 

Oooh.... Thanks a lot Shen

Reason: