Indicator only drawing when time frames changed

To add comments, please log in or register
peterpies
28
peterpies  
Can anyone help with this code, it compiles and 'works', but only draws the lines when time frames are changed,
#property copyright "Coded by Manic Miner"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots   0

input ENUM_TIMEFRAMES TimeFrame=PERIOD_M1;
input ENUM_LINE_STYLE LineStyle=STYLE_DOT;
input color LineColour=White;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

datetime time1=TimeCurrent();
datetime time2=time1+60; 
datetime time3=time2+240;
datetime time4=time2+480;
double   openprice  = iOpen(NULL,TimeFrame,0);
double   highprice = iHigh(NULL,TimeFrame,0); 
double   lowprice = iLow(NULL,TimeFrame,0); 

int OnInit()
  {
//---

//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)

{

if(reason==1)

{

ObjectDelete(0,"High");
ObjectDelete(0,"Low");
ObjectDelete(0,"Open");

}
  
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {
//---

   
  }
//+------------------------------------------------------------------+

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[]) 
{ 
  
ObjectCreate(0,"High",OBJ_TREND,0,time3,highprice,time4,highprice);
ObjectSetInteger(0,"High",OBJPROP_COLOR,LineColour);
ObjectSetInteger(0,"High",OBJPROP_STYLE,2);
ObjectSetInteger(0,"High",OBJPROP_BACK,true);
ObjectCreate(0,"Low",OBJ_TREND,0,time3,lowprice,time4,lowprice);
ObjectSetInteger(0,"Low",OBJPROP_COLOR,LineColour);
ObjectSetInteger(0,"Low",OBJPROP_STYLE,2);
ObjectSetInteger(0,"Low",OBJPROP_BACK,true); 
ObjectCreate(0,"Open",OBJ_TREND,0,time2,openprice,time3,openprice);
ObjectSetInteger(0,"Open",OBJPROP_COLOR,LineColour);
ObjectSetInteger(0,"Open",OBJPROP_STYLE,0);
ObjectSetInteger(0,"Open",OBJPROP_BACK,true);  

return(rates_total); 

} 


Also in mql4, Time[0] can be used,


ObjectSet("High",OBJPROP_TIME2,Time[0]+(Time[0]-Time[2]));


But when I try this in mql5, it compiles, the lines are drawn, all the settings seem fine in Object List / Properties, but it is not visible,


ObjectCreate(0,"High",OBJ_TREND,0,time3,highprice,time[0]+(time[0]-time[2]),highprice);
To add comments, please log in or register