EA no longer open trade according to condition

 

double task = MarketInfo(Symbol(),MODE_ASK);

double ilastBuy = FindLastBuyPrice();

if(FindLastBuyPrice() != 0 && pipsDistFromPriceBuy(FindLastBuyPrice()) <= -10 && CountTradesBuy() >= 1 && FindLastBuyPrice() - task >= 10*Point() ){

                                OpenBuy();

Print("Down buy"," add ",add," lbuy ",ilastBuy," p_l_buy ",pipsDistFromPriceBuy(FindLastBuyPrice())," task ",task," countbuy ",CountTradesBuy());

}

I am using the above condition to enter martingale trade after the first trade. This condition is working fine when there is no high-impact news which will cause high volatility. But when there is high-impact news this same code start malfunctioning by opening many trades at the same time even when this condition is no longer met. The condition is that another trade should open when there market moves away from the last buy price by 10 pips. pipsDistFromPriceBuy(double price) is the function  am using to know when market has moved away from the last buy trade by 10 pips. The function is below. I tried to print, I saw that marketinfo() is not actually capturing the latest Ask price. Before I started using marketinfo() I was using just Ask the problem still happened.

int pipsDistFromPriceBuy(double price){

   //Calculate pips from open price of first position

            int vdigits = (int)MarketInfo(Symbol(),MODE_DIGITS);

            double task=MarketInfo(Symbol(),MODE_ASK);

            if(vdigits==5){

               pipsFromOpenPriceBuy = int((task-price)*10000);

            }else if(vdigits==3){

               pipsFromOpenPriceBuy = int((task-price)*100);

            }

  return  pipsFromOpenPriceBuy;

} 

See what is printed below, I think the problem is getting the latest Ask price. From the printed statement it is not possible for the robot to open buy at 1.19096 when the Ask price is 1.18971. So the problem is getting the latest Ask price.

Please I need solution to this problem. How do I get the latest price (whether Ask or Bid) in a high volatile market?

 

2              21:34:50.752       SARAPH1013103 EURUSD,H1: open #575111690 buy 0.12 EURUSD at 1.19097 ok

2              21:34:51.358       SARAPH1013103 EURUSD,H1: modify #575111690 buy 0.12 EURUSD at 1.19097 sl: 0.00000 tp: 1.19197 ok

0              21:34:51.358       SARAPH1013103 EURUSD,H1: Order #575111690 modified

0              21:34:51.358       SARAPH1013103 EURUSD,H1: Down buy add 0.001010000000000066 lbuy 1.19096 p_l_buy -12 task 1.18971 countbuy 2

 
Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.


 
            if(vdigits==5){
               pipsFromOpenPriceBuy = int((task-price)*10000); 
  1. Multiplying by 10k is the same as dividing by _Point. No test required.
  2. The result is points not PIPs.

    PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum 2014.08.03

    Unless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points), and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 programming forum 2017.02.09
              Slippage defined in index points - Expert Advisors and Automated Trading - MQL5 programming forum 2018.01.15