don't call it onTick(), you only want it to do something when you change timeframes so deinit() is the right place for you.
you would use something like this:
edit: removed the check for REASON_CHARTCHANGE
/**
* MyIndicator
*/#property indicator_chart_window#define ERR_NO_ERROR 0/**
* Initialization
*
* @return int - error status
*/int init() {
return(0);
}
/**
* Deinitialization
*
* @return int - error status
*/int deinit() {
string label;
int type, flags, current=PeriodToFlag(), objects=ObjectsTotal();
GetLastError(); // reset last errorfor (int i=objects-1; i>=0; i--) {
label = ObjectName(i);
if (GetLastError() != ERR_NO_ERROR) // skip index on threading issuescontinue;
// skip already processed objects
flags = ObjectGet(label, OBJPROP_TIMEFRAMES) +0.1; // (int)(double) intif (flags == 0) {
// all objects: visible in creation timeframe
ObjectSet(label, OBJPROP_TIMEFRAMES, current);
type = ObjectType(label);
if (type==OBJ_TREND || type==OBJ_HLINE || type==OBJ_VLINE) {
// lines: visible in lower timeframes too
ObjectSet(label, OBJPROP_TIMEFRAMES, current|(current-1));
}
}
}
return(0);
}
/**
* Main function
*
* @return int - error status
*/int start() {
return(0);
}
/**
* Convert a chart period identifier into an object visibility flag.
*
* @param int period - period id (default: current chart period id)
*
* @return int - visibility flag
*/int PeriodToFlag(int period=NULL) {
if (period == NULL)
period = Period();
switch (period) {
casePERIOD_M1: return(OBJ_PERIOD_M1 );
casePERIOD_M5: return(OBJ_PERIOD_M5 );
casePERIOD_M15: return(OBJ_PERIOD_M15);
casePERIOD_M30: return(OBJ_PERIOD_M30);
casePERIOD_H1: return(OBJ_PERIOD_H1 );
casePERIOD_H4: return(OBJ_PERIOD_H4 );
casePERIOD_D1: return(OBJ_PERIOD_D1 );
casePERIOD_W1: return(OBJ_PERIOD_W1 );
casePERIOD_MN1: return(OBJ_PERIOD_MN1);
}
return(0);
}
Great indicator, it's really useful. I'm not a programmer and have been trying to modify it so it only works on HLines. Unfortunately at the moment if a rectangle is drawn then it only shows on the current TF. I'd be greatful if someone who knows what theyre doing could modifly the above to apply only to HLines so that Tlines and Rectangles etc are unaffected and show on all time frames. Many thanks.
Great indicator, it's really useful. I'm not a programmer and have been trying to modify it so it only works on HLines. Unfortunately at the moment if a rectangle is drawn then it only shows on the current TF. I'd be greatful if someone who knows what theyre doing could modifly the above to apply only to HLines so that Tlines and Rectangles etc are unaffected and show on all time frames. Many thanks.
Hi again, I've actually come up with a work around myself. The above script draws a HLine with the required parameters and time-frames. I've modified it for 3 different line types and applied hot key to each. Hope someone finds it useful.
don't call it onTick(), you only want it to do something when you change timeframes so deinit() is the right place for you.
you would use something like this:
edit: removed the check for REASON_CHARTCHANGE
Great indicator, it's really useful. I'm not a programmer and have been trying to modify it so it only works on HLines. Unfortunately at the moment if a rectangle is drawn then it only shows on the current TF. I'd be greatful if someone who knows what theyre doing could modifly the above to apply only to HLines so that Tlines and Rectangles etc are unaffected and show on all time frames. Many thanks.
Great indicator, it's really useful. I'm not a programmer and have been trying to modify it so it only works on HLines. Unfortunately at the moment if a rectangle is drawn then it only shows on the current TF. I'd be greatful if someone who knows what theyre doing could modifly the above to apply only to HLines so that Tlines and Rectangles etc are unaffected and show on all time frames. Many thanks.