some help needed for my indicator

 

Hi,

I have a couple issues/questions with my indicator, also feel free to add any tips. I'm not a programmer by profession and new to mql4.

- the main issue is that none of these are showing at all, I put these in the function OnCalculate as they have to move dynamically:


    ObjectCreate("top 0.7 ATR", OBJ_HLINE, 0, Time[0],  ATR_levels("xATR","xATRUP"),0 ,0);

    ObjectCreate("bottom 0.7 ATR", OBJ_HLINE, 0, Time[0], 0, ATR_levels("xATR","xATRDOWN"), 0);

    ObjectCreate("top 0.8 ATR", OBJ_HLINE, 0, Time[0], 0, ATR_levels("yATR","yATRUP"),  0);

    ObjectCreate("bottom 0.8 ATR", OBJ_HLINE, 0, Time[0], 0, ATR_levels("yATR","yATRDOWN"), 0);   

what they are meant to do is to draw lines of lowest point of the day + 0.7 ATR, highest point of the day - 0.7 ATR and the same for 0.8 ATR.

 

-the function, ATR_levels I created, I'd say works correctly  but I don't understand why I get this error: not all control paths return a value Morning Glory.mq4 133 4

I removed the property strict which apparently sometimes causes this error. 


I hope this makes sense and I thank you for taking the time to have a look.

Files:
 
  1. I think it's faster to create an object once and then just modify it
  2. "not all control paths return a value Morning Glory.mq4 133 4"
    your function ATR returns a double, but at the very end of this function nothing is returend. Put there a return(-1.) as a signal the function failed?
  3. As there is practically nothing that does not exists for MT4 have you searched (top-right and google)?

 
/*
double PD_LOW = iLow(NULL,1440,1);
double PD_HIGH = iHigh(NULL,1440,1);
double xATR = iATR(NULL,1440,10,0) * 0.7;     // 0.7 ATR value
double yATR = iATR(NULL,1440,10,0) * 0.8;     // 0.8 ATR value
double midrange = (iClose(NULL,1440,1)-iLow(NULL,1440,1))/(iHigh(NULL,1440,1)-iLow(NULL,1440,1));



double TODAY_OPEN = iOpen(NULL,1440,0);
double TODAY_UP = TODAY_OPEN + MarketInfo(Symbol(), MODE_DIGITS);
double TODAY_DOWN = TODAY_OPEN - MarketInfo(Symbol(), MODE_DIGITS);
*/
//+------------------------------------------------------------------+
double ATR_levels(string ATR, string ATR_level) 
   {
   /*
   double xATRUP;    // top of the 0.7 ATR range
   double xATRDOWN;  // bottom of the 0.7 ATR range
   double yATRUP;    // top of the 0.8 ATR range
   double yATRDOWN;  // bottom of the 0.8 ATR range
   double Intraday_range = iHigh(NULL,1440,0)-iLow(NULL,1440,0);
   */
   double Ret_value = 0.0;
   
   if (ATR == "xATR")
      {
      
         double xATR = iATR(NULL,1440,10,0) * 0.7;     // 0.7 ATR value  
         
         if (ATR_level == "xATRUP")
            {
            //xATRUP = iLow(NULL,1440,0)+xATR;
            
            //return xATRUP;
                Ret_value = iLow(NULL,1440,0)+xATR;
            }
         
         else if (ATR_level =="xATRDOWN")
            {
            //xATRDOWN = iHigh(NULL,1440,0)-xATR;
            
            //return xATRDOWN;
            Ret_value = iHigh(NULL,1440,0)-xATR;
            }
        
 
      }
   else if (ATR == "yATR")
      {
     
         double yATR = iATR(NULL,1440,10,0) * 0.8;     // 0.8 ATR value
         
         if (ATR_level == "yATRUP")
            {
            //yATRUP = iLow(NULL,1440,0)+yATR;
            
            //return yATRUP;
            Ret_value = iLow(NULL,1440,0)+yATR;
            }
            
         else if (ATR_level == "yATRDOWN")
            {
            
            //yATRDOWN = iHigh(NULL,1440,0)-yATR;
            
            //return yATRDOWN;
            Ret_value = iHigh(NULL,1440,0)-yATR;
            }
         

      }
      
      return (Ret_value);
   }
//+------------------------------------------------------------------+
I added "double Ret_value", and it return value of this function.
 
int OnInit()
  {
//--- indicator buffers mapping
        
    ObjectCreate("Midrange", OBJ_LABEL, 0, 0, 0);
    ObjectSet("Midrange", OBJPROP_CORNER, 1);
    ObjectSet("Midrange", OBJPROP_XDISTANCE, 10);
    ObjectSet("Midrange", OBJPROP_YDISTANCE, 90);
    //ObjectSetText("Midrange", "Midrange: " + DoubleToString(midrange,2), 10, "Arial", clrYellow);

    ObjectCreate("intraday range", OBJ_LABEL, 0, 0, 0);
    ObjectSet("intraday range", OBJPROP_CORNER, 1);
    ObjectSet("intraday range", OBJPROP_XDISTANCE, 10);
    ObjectSet("intraday range", OBJPROP_YDISTANCE, 115);
         
    ObjectCreate("PD_LOW", OBJ_HLINE, 0, 0, 0, 0, 0);
    ObjectCreate("PD_HIGH", OBJ_HLINE, 0, 0, 0, 0, 0);
    ObjectCreate("top 0.7 ATR", OBJ_HLINE, 0, 0, 0,0 ,0);
    ObjectCreate("bottom 0.7 ATR", OBJ_HLINE, 0, 0, 0, 0, 0);
    ObjectCreate("top 0.8 ATR", OBJ_HLINE, 0, 0, 0, 0,  0);
    ObjectCreate("bottom 0.8 ATR", OBJ_HLINE, 0, 0, 0, 0, 0);   
    
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
                            
                
  {
//---
    double PD_LOW = iLow(NULL,1440,1);
    double PD_HIGH = iHigh(NULL,1440,1);
    double midrange = (iClose(NULL,1440,1)-PD_LOW)/(PD_HIGH-PD_LOW);
        /*
    ObjectCreate("PD_LOW", OBJ_HLINE, 0, Time[0], PD_LOW, 0, 0);
    ObjectCreate("PD_HIGH", OBJ_HLINE, 0, Time[0], PD_HIGH, 0, 0);
    ObjectCreate("intraday range", OBJ_LABEL, 0, 0, 0);
    ObjectSet("intraday range", OBJPROP_CORNER, 1);
    ObjectSet("intraday range", OBJPROP_XDISTANCE, 10);
    ObjectSet("intraday range", OBJPROP_YDISTANCE, 115);
    */
    ObjectMove("PD_LOW", 0, Time[0], PD_LOW);
    ObjectMove("PD_HIGH", 0, Time[0], PD_HIGH);
    ObjectSetText("Midrange", "Midrange: " + DoubleToString(midrange,2), 10, "Arial", clrYellow);
    ObjectSetText("intraday range", "intraday range: " + DoubleToString(ATR_levels("xATR","xATRUP"),4), 10, "Arial", clrYellow);
    /*
    ObjectCreate("top 0.7 ATR", OBJ_HLINE, 0, Time[0],  ATR_levels("xATR","xATRUP"),0 ,0);
    ObjectCreate("bottom 0.7 ATR", OBJ_HLINE, 0, Time[0], 0, ATR_levels("xATR","xATRDOWN"), 0);
    ObjectCreate("top 0.8 ATR", OBJ_HLINE, 0, Time[0], 0, ATR_levels("yATR","yATRUP"),  0);
    ObjectCreate("bottom 0.8 ATR", OBJ_HLINE, 0, Time[0], 0, ATR_levels("yATR","yATRDOWN"), 0);    
    */
    ObjectMove("top 0.7 ATR", 0, Time[0],  ATR_levels("xATR","xATRUP"));
    ObjectMove("bottom 0.7 ATR", 0, Time[0], ATR_levels("xATR","xATRDOWN"));
    ObjectMove("top 0.8 ATR", 0, Time[0], ATR_levels("yATR","yATRUP"));
    ObjectMove("bottom 0.8 ATR", 0, Time[0], ATR_levels("yATR","yATRDOWN"));    
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Create all objects once in the "OnInit()" and in the "OnCalculate" only Move or Set Objects.
 
Jens89: none of these are showing at all,
double PD_HIGH = iHigh(NULL,1440,1);
double xATR = iATR(NULL,1440,10,0) * 0.7;     // 0.7 ATR value
double yATR = iATR(NULL,1440,10,0) * 0.8;     // 0.8 ATR value
double midrange = (iClose(NULL,1440,1)-iLow(NULL,1440,1))/(iHigh(NULL,1440,1)-iLow(NULL,1440,1));
double TODAY_OPEN = iOpen(NULL,1440,0);
double TODAY_UP = TODAY_OPEN + MarketInfo(Symbol(), MODE_DIGITS);
double TODAY_DOWN = TODAY_OPEN - MarketInfo(Symbol(), MODE_DIGITS);

ObjectCreate("PD_LOW", OBJ_HLINE, 0, Time[0], PD_LOW, 0, 0);
ObjectCreate("PD_HIGH", OBJ_HLINE, 0, Time[0], PD_HIGH, 0, 0);
ObjectCreate("intraday range", OBJ_LABEL, 0, 0, 0);
  1. These global variables never change. Assign them in OnCalculate.
  2. Don't hard code numbers, use the proper symbols (PERIOD_D1.)
  3. Unless your chart is that TF, you must handle 4066/4073 errors. See Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
  4. What does price + n mean? 1.01234 + 5 is meaningless.
  5. Once you create an object you can't create it again. They will never move.
  6. That isn't the mid point (H+L)/2 that is the fraction above the low. Use meaningful variable names.
 

guys,

I just want to tell you that I am blown away and am very thankful for all your responses and helpfulness. 

I really appreciate you all taking time to looking into my indicator and giving constructive feedback. 

thank you so much!