can't make trade

 
#property copyright "sergey antipin"
#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 trade_ok=true;
int ticket1=-1;


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






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

     
double entryprice=0;
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

int     init(){
    if (Digits == 5 || Digits == 3)
    {    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } 
    else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl

}



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);
bool price_above= ( Ask > SMA_10day );



//-----risk management

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

if (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* pips2dbl ) && ( price_above==true) && (ATR<40*pips2dbl) )     
  
  {  

     ticket1=-1;
     
   Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID),"short trade"," atr=", ATR);
      
    
     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<max_spread* pips2dbl)  // spread < 4
     {
  
     RefreshRates();
     ticket1 = OrderSend(Symbol() , OP_SELL , 0.01*M , Bid , 2 , 0 ,0); 
  
     Sleep(2000);
     if (ticket1>0)
     { 
     OrderModify(ticket1,Bid,Ask+stoploss* pips2dbl , Ask-takeprofit* pips2dbl,0,White);
     entryprice=Bid; 
     break;
     }
     }

trade_ok=false; 

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

if ( ( SMA_10day -  Ask < buffer* pips2dbl ) && (price_above==false) && (ATR<40*pips2dbl))     
  
  {   
          Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID),"long trade"," atr=", ATR,price_above);
     ticket1=-1;
     

     

     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<max_spread* pips2dbl) //spread < 4
     {

     RefreshRates();     
     ticket1 = OrderSend(Symbol() , OP_BUY , 0.01*M , Ask , 2 , 0 , 0);
     
     Sleep(2000);
     if (ticket1>0)
     {
     OrderModify(ticket1,Ask,Bid-stoploss* pips2dbl , Bid+takeprofit* pips2dbl,0,White);
     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* pips2dbl)       //-- price moved below and is not random noice
                
                  {
                      // price_above=false;
                       trade_ok=true;
                  }
                  
                  
              else
              
               
                if (Ask > entryprice + filter* pips2dbl)     //-- price stayed above and is not random noice
                   trade_ok=true;
               
           }

      else


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

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

any idea why no trades are made ?

THANKS

 
sergeyrar:
any idea why no trades are made ?
  1. No mind readers here. Why don't you PRINT out the error code to find out WHY
        int ticket = OrderSend(...
        if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket()...)
           Alert("OrderModify failed: ", GetLastError());
    

  2. EA's must adjust for 4/5 digit brokers tp, sl, AND SLIPPAGE
    ticket1 = OrderSend(Symbol() , OP_BUY , 0.01*M , Ask , 2*pips2points , 0 , 0);

  3. bool price_above= ( Ask > SMA_10day );
    :
    if ( ( Bid- SMA_10day  < buffer* pips2dbl ) && ( price_above==true) 
    You wouldn't ever say if ( (2==2) == true) would you? You would only say if (2==2). So don't say if ( BOOL == true) just say if (BOOL)
  4.  while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<max_spread* pips2dbl) //spread < 4
    Why use function calls when the simplier variables are the same
     while (Ask-Bid<max_spread* pips2dbl) //spread < 4

 

Im a noob sorry :P

thanks alot !!

 

it works !! thank u !!

however the program makes only short trades.

-----------------

bool price_above= ( Ask > SMA_10day );

if I switch "Ask" to "Bid" it makes only long trades...

----------------

is there a way to work this out ?

Reason: