MQL4-One trade per Bar not working - Please advise

 

//--------------------------------------------------------------------
//+GLOBAL Variable declaration
//+-------------------------------------------------------------------
double ExecutedBarOpenPrice=0;

//+------------------------------------------------------------------+
//| EA initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   Alert("EA Initiated");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| EA tick function                                             |
//+------------------------------------------------------------------+
int LotSize = 1;
extern double myvol=1;
double mystoploss=0;
double mytakeprofit=Ask + 300 * Point;

int start()
  {
     double Bar_zero_Open_Price = iOpen("XAUUSD",0,0);
  
     if(ExecutedBarOpenPrice!=Bar_zero_Open_Price)
      {
         OrderSend("XAUUSD",OP_BUY,myvol,Ask,2,mystoploss,mytakeprofit);
         ExecutedBarOpenPrice=Bar_zero_Open_Price;
      }

 

Hi, I tried to place order at each bar (xauusd daily chart), but only one buy executed in 22 bars. Could you please correct me where i'm wrong?

Please have look at  the link for the visual result https://www.mql5.com/en/charts/6344538/xauusd-d1-forex-capital-markets 


      
 
  1. Don't type inside your SRC blocks. MQL4 Forum editor problem - MQL4 forum 
  2. double mytakeprofit=Ask + 300 * Point;
    Your take profit never changes, you need to assign a value inside start.
  3. How do you know "only one buy executed?" Answer, you don't because you didn't check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  4. Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 forum.) Always use time. New candle - MQL4 forum
 
whroeder1:
  1. Don't type inside your SRC blocks. MQL4 Forum editor problem - MQL4 forum 
  2. double mytakeprofit=Ask + 300 * Point;
    Your take profit never changes, you need to assign a value inside start.
  3. How do you know "only one buy executed?" Answer, you don't because you didn't check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  4. Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 forum.) Always use time. New candle - MQL4 forum
Thank you so much Mr.whroeder1. I will go through the link and learn it.