problems definig a variable in the right way

 
//+------------------------------------------------------------------+
//|                                                GBPUSD trader.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"



extern double buffer=0;           
extern double stoploss=20;            
extern double takeprofit=350;                
extern double filter=50;               
extern double ma_value=218;  
double max_account_balance=0;
double max_spread=4;   
extern double Z=1;



double M=1;  // risk 
bool price_above=false;
bool trade_ok=true;
int ticket1=-1;


//------------------------------------------------------------------------------------------------~~~~~~!!!!!!!!!!!!!!!!



//------------------------------------------------------------------------------------------------~~~~~~!!!!!!!!!!!!!!!!

     
double entryprice=0;
int K = 1 ;  // point * K   (in demo account use 10, in real account use 1)

int init()
  {
  
double SMA_10day=iMA(Symbol(),15,ma_value,0,MODE_SMA,PRICE_TYPICAL,0);

if (Bid>SMA_10day)
price_above=true;
else
price_above=false;



   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
double SMA_10day=iMA(Symbol(),15,ma_value,0,MODE_SMA,PRICE_TYPICAL,0);  //  simple ma_value day moving average value 
double ATR=iATR(Symbol(),60,200,0);
//double adx=iADX(Symbol(),30,14,PRICE_TYPICAL,MODE_SMA,0);

//----- risk
//Alert("lot size:",MarketInfo(Symbol(), MODE_LOTSIZE));
//Alert("minlot:",MarketInfo(Symbol(), MODE_MINLOT));
//Alert("lot step:",MarketInfo(Symbol(), MODE_LOTSTEP));
//Alert("max lot:",MarketInfo(Symbol(), MODE_MAXLOT));


//M = MathRound ( MathLog (AccountBalance()/(367.88/M+1) ) / MathLog (2.72)  );


M= (AccountBalance()*0.002*Z)/(stoploss) ;  // x% risk per trade

if (M<1) M=1;

//M=1;



if (AccountBalance()>max_account_balance)
max_account_balance=AccountBalance();

//-----end of risk



//---------------- open new trades

//--- * short trade





if  (trade_ok==true)

{






if ( ( Bid- SMA_10day  < buffer*Point*K ) && ( price_above==true) && (ATR<0.0040) )     
  
  {  

     ticket1=-1;
     

      
    
     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<max_spread*Point*K)  // spread < 4
     {
     Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID));
     RefreshRates();
     ticket1 = OrderSend(Symbol() , OP_SELL , 0.01*M , Bid , 3 , Ask+stoploss*Point*K , Ask-takeprofit*Point*K); 
     Sleep(200);
     if (ticket1>0)
     { 
     entryprice=Bid; 
     break;
     }
     }

trade_ok=false; 

  }
  
    //--- * end of short trade
    
    
    
    
    
    
    
    
     
     else 
     
     
     
     
     
     
     
    
       
//--- * long trade

if ( ( SMA_10day -  Ask < buffer*Point*K ) && (price_above==false) && (ATR<0.0040))     
  
  {   
     
     ticket1=-1;
     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<max_spread*Point*K) //spread < 4
     {
     Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID));
     RefreshRates();     
     ticket1 = OrderSend(Symbol() , OP_BUY , 0.01*M , Ask , 3 , Bid-stoploss*Point*K , Bid+takeprofit*Point*K);
     Sleep(200);
     if (ticket1>0)
     {
     entryprice=Ask;
     break;
     } 
     }
     

     trade_ok=false;    
  }

//--- * end of long trade
  
}
  

//---- end of open new trades




//-----x pip noise filter
          
       if (trade_ok==false)
      {
         if  (price_above==true)  //-- price currently above 
           
           {
                if (Bid < entryprice - filter*Point*K)       //-- price moved below and is not random noise
                
                  {
                       price_above=false;
                       trade_ok=true;
                  }
                  
                  
              else
              
               
                if (Ask > entryprice + filter*Point*K)     //-- price stayed above and is not random noise
                   trade_ok=true;
               
           }

      else


         if (price_above==false)  //-- price currently below
  
           {

                if (Ask > entryprice + filter*Point*K)  //-- price moved above and is not random noise
  
                  {
                      price_above=true;
                      trade_ok=true; 
                  }   
   
             else
               
               if (Bid < entryprice - filter*Point*K)  //-- price stayed below and is not random noise
               trade_ok=true;
          
           }
        }   
  
  //----- end of filter
  
  
   return(0);
  }
  
  

hello,

How can I make the "trade_above" variable
work properly and be correct for every tick?

as for now, If the program is reloaded
this variable may not be correct !

I tried to change it to -> price_above=(ask>SMA_10day) and move it to start()
but it worked only for short trades
how can I make it work for short & long trades ??

thanks

 
Appears like you're just moving codes around hoping it'll work. I'll recommend learning to code by the book.
Reason: