Problem with my first EA :(

 

Guys my first EA doesn't open any sell order.. only buy.. can you help me ? 

double Lots=1;
double SL=0;
double TP=0;
int ticket=0;



extern int MagicNumber=10056;
extern int StopL=20;
extern int TakeP=80;
extern bool Compounding=true;
extern double Rischio=2.0;
extern int BegTrade=8;
extern int EndTrade=19;


void OnTick(){

   if(NewBar()){
   
      CalcolaSize(Rischio);  
      if(OrdersTotal() == 0) Ordine();
      
   }   
}



void Ordine(){
     
      if((iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_KIJUNSEN,1)>iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_TENKANSEN,1)) && Bid<iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANA,1) && Bid<iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANB,1) && 
         (iRSI(Symbol(),PERIOD_CURRENT,14,PRICE_CLOSE,0)<=50) &&
         (iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,0)<(iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,1)<(iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,2))>=20)) &&
         (iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0)<(iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1)<(iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2))))){
         
         if(Hour()>BegTrade && Hour()<EndTrade){
         ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid+StopL*10*Point,Bid-TakeP*10*Point,"Ordine Sell",MagicNumber,0,clrAqua);
         Print(GetLastError());
         }
   }

      if((iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_KIJUNSEN,1)<iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_TENKANSEN,1)) && Bid>iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANA,1) && Bid>iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANB,1) &&
         (iRSI(Symbol(),PERIOD_CURRENT,14,PRICE_CLOSE,0)>=50) &&
         (iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,0)>(iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,1)>(iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,2))<=80)) &&
         (iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0)>(iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1)>(iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2))))){      
               
         if(Hour()>BegTrade && Hour()<EndTrade){ 
         ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopL*10*Point,Ask+TakeP*10*Point,"Ordine Buy",MagicNumber,0,clrMagenta);
         Print(GetLastError());
         }     
   }
}



double CalcolaSize(double RischioIns){
  
 if (Compounding){
  double diff=StopL*10*Point;
  diff=NormalizeDouble(diff,5);
  Print(MarketInfo(Symbol(),MODE_TICKVALUE));
  Lots=(AccountBalance()*RischioIns/100)/(MarketInfo(Symbol(),MODE_TICKVALUE)*diff*MathPow(10,MarketInfo(Symbol(),MODE_DIGITS)));
  return Lots;
 }
 else return Lots=1;

}


bool NewBar(){

  static datetime lastbar;
  datetime curbar = Time[0];
  
   if(lastbar!=curbar){
      lastbar=curbar;
      return (true);
   }
   else{
     return(false);
   }
}
 

I can not help because I am not a coder sorry.
But I think some coder may help I hope..

 
  1.       if(OrdersTotal() == 0) Ordine();
    Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  2.       if((iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_KIJUNSEN,1)>iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_TENKANSEN,1)) && Bid<iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANA,1) && Bid<iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANB,1) && 
             (iRSI(Symbol(),PERIOD_CURRENT,14,PRICE_CLOSE,0)<=50) &&
             (iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,0)<(iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,1)<(iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,2))>=20)) &&
             (iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0)<(iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1)<(iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2))))){
    
    Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it. Don't copy and past code, write self documenting code.
    double kijunsen   = iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_KIJUNSEN,1);
    double tenkansen  = iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_TENKANSEN,1);
    double spanA      = iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANA,1);
    double spanB      = iIchimoku(Symbol(),PERIOD_CURRENT,7,22,44,MODE_SENKOUSPANB,1);
    double rsi        = iRSI(Symbol(),PERIOD_CURRENT,14,PRICE_CLOSE,0);
    double main0      = iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,0)
    double main1      = iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,1);
    double main2      = iStochastic(Symbol(),PERIOD_CURRENT,5,3,3,MODE_SMA,0,MODE_MAIN,2);
    double macdSig0   = iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
    double macdSig1   = iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
    double macdSig2   = iMACD(Symbol(),PERIOD_CURRENT,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2);
    if((kijunsen>tenkansen) && Bid<spanA && Bid<spanB && (rsi<=50) &&
    (main0<(main1<(main2)>=20)) &&
    (macdSig0<(macdSig1<(macdSig2)))){
    And then should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. True = 1 and false = 0 so you get
    if( 3 < 2 < 1 )
    if( false < 1 )
    if(     0 < 1 )
    if(     true  )
    if( 3 > 2 > 1 )
    iftrue > 1 )
    if(     1 > 1 )
    if(     false )
    

  4. ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask-StopL*10*Point,Ask+TakeP*10*Point,"Ordine Buy",MagicNumber,0,clrMagenta);
    
    You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

  5. Using Points means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum

  6.   Lots=(AccountBalance()*RischioIns/100)/(MarketInfo(Symbol(),MODE_TICKVALUE)*diff*MathPow(10,MarketInfo(Symbol(),MODE_DIGITS)));
    1/10Digits == _Point always. It is diff*TickValue/TickSize not TickValue/Point and definitely not TickValue*10000. Write self-documenting code.
    Risk depends on your initial stop loss, lot size, and the value of the pair.
    1. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    2. Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency (EUR, in this case).
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers.
    4. You must normalize lots properly and check against min and max.
    5. You must also check FreeMargin to avoid stop out
    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5=0.1 Lots maximum.
 
Sergey Golubev:

I can not help because I am not a coder sorry.
But I think some coder may help I hope..