Price problem

 
Good evening, I don't understand why my code doesn't work... I think it's due to the Ask and the AccountBallance() but I've done some modifications and search in the MQL4 library but I can't solve my problem... here is my code :
extern int SL1 = 500;

extern int TP1 = 500;

extern int i = 0;

extern int X = 50;

extern int Y =10;

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

 double Price=PriceAsk;
double accountinit=AccountBalance();


void OnTick()

  {
  
   { 
     
     
     if(OrdersTotal()==0 && iMA(NULL,0,X,0,MODE_EMA,PRICE_OPEN,i)<iMA(NULL,0,Y,0,MODE_EMA,PRICE_OPEN,i) && Ask==Price+100*_Point )
   
       {
        OrderSend (_Symbol,OP_BUY,AccountBalance()/100000,Ask,3,Ask-SL1*_Point,Ask+TP1*_Point,NULL,0,0,Green);
        
       }
     if( AccountBalance()==! accountinit)
      {
        Price=PriceAsk;
        accountinit=AccountBalance();
        
        
       }
       
       
   
    
   }
   }


The purpose of my code is to take a buy position as soon as the price rises 10 pips (the first part of the code). The second part is that if my account after the order is not the same as before the order (winning or losing position) then Price=buy price at time t and accountinit= account balance at time t.

Thank you in advance 

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

 double Price=PriceAsk;
double accountinit=AccountBalance();

Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

  1. They are initialized once on program load.

  2. They don't update unless you assign to them.

  3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

    MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and

    Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
              external static variable - MQL4 programming forum #2 2013.02.10

 
William Roeder:

Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

  1. They are initialized once on program load.

  2. They don't update unless you assign to them.

  3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

    MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and

    Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
              external static variable - MQL4 programming forum #2 2013.02.10

Good evening William Roeder, thank you very much for your answer... But unfortunately I don't understand everything you are telling me... How did you learn the MQL4 language? 


Thank you very much for your answer.