what should I add to this code before I run it on a live account ?

 

I tried running this EA on a live account

and got some delay in the execution of the trade ( the blue line is where it should sell )

any idea why ?

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=MathRound((AccountBalance()*0.005*Z)/(0.1*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 noice 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 noice
                
                  {
                       price_above=false;
                       trade_ok=true;
                  }
                  
                  
              else
              
               
                if (Ask > entryprice + filter*Point*K)     //-- price stayed above and is not random noice
                   trade_ok=true;
               
           }

      else


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

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

I tried running this EA on a live account

and got some delay in the execution of the trade ( the blue line is where it should sell )

any idea why ?

Hi Sergeyrar,

Without knowing the MA period for the MA line shown on the chart, your variable name is different than your MA period.

You have SMA_10day but your MA Period is 15...?

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

Maybe this is why you are getting a different result?

Hope this helps,

Robert

 
cosmicbeing:

Hi Sergeyrar,

Without knowing the MA period for the MA line shown on the chart, your variable name is different than your MA period.

You have SMA_10day but your MA Period is 15...?

Maybe this is why you are getting a different result?

Hope this helps,

Robert


the MA on the chart is 218 on a 15 minute chart its all good

really need to change the name though

 
Maybe ATR was greater than 0.0040?
 
zzuegg:
Maybe ATR was greater than 0.0040?


thanks

It might be it