HELP ! EA is not taking any Trades

 

Hello.

This EA is getting 0 Errors, but its not taking any trades, when i test it.


Buy Rules :

HMA Trend Indicator = Greenline

ROC = crossing 0 from below or >0


Sell Rules :

HMA Trend Indicator = Redline

ROC = crossing 0 from above or <0


Where is my mistake ?


#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
int RPeriod=20;
bool UsePercent=false;

//Custom function
int Cross(){
    double
    ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2),
    ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1);

   if(ROC_2<=0 && ROC_1>0){return(1);}
   if(ROC_2>=0 && ROC_1<0){return(-1);}
   return(0);
}
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{


    //Buy: when current line is up and blue and previous line is down and red
    
    double buy_hmacurrent = iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 0, 0);

    double buy_hmaprevious = iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 0, 1);



    //Sell: when current line is down and red and previous line is up and blue
    
    double sell_hmacurrent = iCustom(NULL, 0, "hma-trend-indicator", 30, 3, 0, 1, 0);

    double sell_hmaprevious = iCustom(NULL, 0, "hma-trend-indicator", 30, 3, 0, 1, 1);
    
  
   
    // Here, we fetch the current 3-period ATR value
    double atr = iATR(NULL, 0, 14, 0);
     
     
     
    // Since the stop loss will be a multiple of this ATR value,
    // we define this multiple. 2.5 times the ATR value
    // is often a good start:
    double atrMultiple = 3;
     
     
     
    // Now, we set our stop loss.
    // We multiply the ATR value by the ATR multiple
    // and divide by the Point constant
    // in order to get a value in points:
    int stopLoss = (int)(atr * atrMultiple / Point);
     
     
     
    // And, since we have a dynamic stop loss value,
    // it makes sense to use the same pips amount as our take profit
    int takeProfit = stopLoss;
    
    
    
    // Dynamic lot sizes based on our stop loss
    double lots = calculateLotSize(stopLoss);
    
    
    
    // Buy Rules
        if (Cross()>0)
        if (sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE)
        
          {
        if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "1", 12345, 0, Green)) {
            Print("Buy order succeeded!");
        }
    }
    
    

   // Sell Rules
        if(Cross()<0)
        if(buy_hmaprevious!=EMPTY_VALUE && buy_hmacurrent==EMPTY_VALUE && sell_hmacurrent!=EMPTY_VALUE)
        
         {
        if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "2", 12345, 0, Red)) {
            Print("Sell order succeeded!");
        }
    }
   
}
//+------------------------------------------------------------------+

/**
 * Calculate the amount of lots needed based on stop loss
 *
 * @return  double
 */
double calculateLotSize(int StopLossPoints)
{
    // 1% risk per trade
    int risk = 2;
    
    double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
    double minLot  = MarketInfo(Symbol(), MODE_MINLOT); 
    double maxLot  = MarketInfo(Symbol(), MODE_MAXLOT);
    double tickVal = MarketInfo(Symbol(), MODE_TICKVALUE);

    double lotSize = AccountBalance() * risk / 100 / (StopLossPoints * tickVal);

    return MathMin(
        maxLot,
        MathMax(
            minLot,
            NormalizeDouble(lotSize / lotStep, 0) * lotStep // This rounds the lotSize to the nearest lotstep interval
        )
    ); 
}
Files:
 
Some condition it is never met
 
you have to check your logical business
 
maybe is never empty value in that if condition
 
I am not a good programmer but that looks like mql4 to me and i cant see the order send function at all, what i can detect that ur code will do calculations in the background and no condition will be meet hence wont do anything it wont even print a thing
 
Marius Ovidiu Sunzuiana:
maybe is never empty value in that if condition
It is. The problem is the cross over. As soon as that’s in, it’s not taking trades anymore. 
 
Jefferson Metha:
I am not a good programmer but that looks like mql4 to me and i cant see the order send function at all, what i can detect that ur code will do calculations in the background and no condition will be meet hence wont do anything it wont even print a thing
  // Buy Rules
        if (Cross()>0)
        if (sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE)
        
          {
        if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "1", 12345, 0, Green)) {
            Print("Buy order succeeded!");
        }
    }
    
    

   // Sell Rules
        if(Cross()<0)
        if(buy_hmaprevious!=EMPTY_VALUE && buy_hmacurrent==EMPTY_VALUE && sell_hmacurrent!=EMPTY_VALUE)
        
         {
        if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "2", 12345, 0, Red)) {
            Print("Sell order succeeded!");
        }
    }
 
fiehejulien:
There is some OrderSend
 
fiehejulien:
There is some OrderSend
And it’s sending orders, when I remove the crossover
 
Found Your Error lol please recheckyour cross Function.
int Cross(){
    double
    ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2),
    ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1);

   if(ROC_2<=0 && ROC_1>0){return(1);}
   if(ROC_2>=0 && ROC_1<0){return(-1);}
   return(0);

Try and remove the last line that will always return Zero

Fix to this

int Cross()
   {
//+=======================================
//|Assisted by jeffiq
//+=======================================
     double
     ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2),
     ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1);

       
bool bull,bear; 
if(ROC_2<=0 && ROC_1>0)bull;
if(ROC_2>=0 && ROC_1<0)bear;

    // Buy Rules
        if (Bull)
        if (sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE)
        
          {
        if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "1", 12345, 0, Green)) {
            Print("Buy order succeeded!");
        }
    }
    
    

   // Sell Rules
        if(Bear)
        if(buy_hmaprevious!=EMPTY_VALUE && buy_hmacurrent==EMPTY_VALUE && sell_hmacurrent!=EMPTY_VALUE)
        
         {
        if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "2", 12345, 0, Red)) {
            Print("Sell order succeeded!");
    }   

But thats wrong i think



Better yet remove Cross functionand put everything in to OnTick and make conditions boolian 


 
Jefferson Metha:
Found Your Error lol please recheckyour cross Function.

Try and remove the last line that will always return Zero

Fix to this

But thats wrong i think

Thank you ! its just giving me one error now. If i delet the return(0); itll give me that error.


'}' - not all control paths return a value    Automate V0.mq4    20    5