Forum on trading, automated trading systems and testing trading strategies
Question about OBJPROP_TIMEFRAMES
Alain Verleyen, 2015.01.24 13:53
Just for fun.
By the way I found 2 bugs in the process, see comments (first one already found by Gumrai)
input string objname="test"; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { long objTimeframes=0; ENUM_TIMEFRAMES period=(ENUM_TIMEFRAMES)Period(); //--- Get visibility property of the object if(ObjectGetInteger(0,"test",OBJPROP_TIMEFRAMES,0,objTimeframes)) { long mask=-1; //--- set mask from period switch(period) { case PERIOD_M1 : mask=0x0001; break; // The object is drawn in 1-minute chart case PERIOD_M5 : mask=0x0002; break; // The object is drawn in 5-minute chart case PERIOD_M15: mask=0x0004; break; // The object is drawn in 15-minute chart case PERIOD_M30: mask=0x0008; break; // The object is drawn in 30-minute chart case PERIOD_H1 : mask=0x0010; break; // The object is drawn in 1-hour chart case PERIOD_H4 : mask=0x0020; break; // The object is drawn in 4-hour chart case PERIOD_D1 : mask=0x0040; break; // The object is drawn in day charts case PERIOD_W1 : mask=0x0080; break; // The object is drawn in week charts case PERIOD_MN1: mask=0x0100; break; // The object is drawn in month charts default: break; } //--- check mask. Special cases : //--- 1° BUG 1: if "Show on all timeframes" is enabled, objTimeframes=0 is returned and not '0x01ff' as stated in documentation. //--- 2° BUG 2: it's not possible with MT4 to disable "Show on all timeframes" without enabled at least 1 period ; //--- but it's possible to set it to -1 with mql4. In this case, MT4 object properties window will display erroneously "Show on all timeframes" enabled. if(objTimeframes==0 || (objTimeframes!=-1 && (objTimeframes&mask)==mask)) { printf("Object %s is visible on this chart %s",objname,EnumToString(period)); } else { printf("Object %s exists but is not visible on this chart %s",objname,EnumToString(period)); } } //--- ObjectGetInteger error processing else { int err=GetLastError(); if(err==ERR_OBJECT_DOES_NOT_EXIST) { printf("Object %s doesn't exist!",objname); } else { printf("Error(%i) whily getting properties of %s",err,objname); } } } //+------------------------------------------------------------------+
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I have objects that i display with different timeframe visibility on the chart as such so that i don't clutter the objects onto higher timeframes.
ObjectSetInteger(0,sObjName,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M1|OBJ_PERIOD_M5|OBJ_PERIOD_M15);
Now i want to retrieve the objects and find out what objects are visible in the current timeframe. How do you do that?
long tf = ObjectGetInteger(0,sObjName,OBJPROP_TIMEFRAMES);
How do I compare the variable tf with Period, that tf is visible in current Period?
Thanks!