Visibility of Objects
对象的可见性
对象可见性标志的组合决定了对象的可见时间范围。要设置或获取 OBJPROP_TIMEFRAMES 属性的值,可以使用 ObjectSet() 或 ObjectGet() 以及 ObjectSetInteger() 或 ObjectGetInteger() 函数。
| ID | 值 | 描述 |
|---|---|---|
| OBJ_NO_PERIODS, EMPTY | -1 | 该对象不在所有时间范围内显示 |
| OBJ_PERIOD_M1 | 0x0001 | 该对象在1分钟图表中显示 |
| OBJ_PERIOD_M5 | 0x0002 | 该对象在5分钟图表中显示 |
| OBJ_PERIOD_M15 | 0x0004 | 该对象在15分钟图表中显示 |
| OBJ_PERIOD_M30 | 0x0008 | 该对象在30分钟图表中显示 |
| OBJ_PERIOD_H1 | 0x0010 | 该对象在1小时图表中显示 |
| OBJ_PERIOD_H4 | 0x0020 | 该对象在4小时图表中显示 |
| OBJ_PERIOD_D1 | 0x0040 | 该对象在日图表中显示 |
| OBJ_PERIOD_W1 | 0x0080 | 该对象在周图表中显示 |
| OBJ_PERIOD_MN1 | 0x0100 | 该对象在月图表中显示 |
| OBJ_ALL_PERIODS | 0x01ff | 该对象在所有时间范围内显示 |
可见性标志可以使用符号“|”进行组合,例如,OBJ_PERIOD_M15|OBJ_PERIOD_H1 的组合表示该对象将在15分钟和每小时的时间范围内显示。
示例:
void OnStart()
{
//---
string highlevel="PreviousDayHigh";
string lowlevel="PreviousDayLow";
double prevHigh; // The previous day High
double prevLow; // The previous day Low
double highs[],lows[]; // Arrays for High and Low
//--- Reset the last error
ResetLastError();
//--- Get the last 2 High values on the daily timeframe
int highsgot=CopyHigh(Symbol(),PERIOD_D1,0,2,highs);
if(highsgot>0) // If copying was successful
{
Print("High prices for the last 2 days were obtained successfully");
prevHigh=highs[0]; // The previous day High
Print("prevHigh = ",prevHigh);
if(ObjectFind(0,highlevel)<0) // Object with the name highlevel not found
{
ObjectCreate(0,highlevel,OBJ_HLINE,0,0,0); // Create the Horizontal Line object
}
//--- Set value for the price level for the line highlevel
ObjectSetDouble(0,highlevel,OBJPROP_PRICE,0,prevHigh);
//--- Set the visibility only PERIOD_M15 and PERIOD_H1
ObjectSetInteger(0,highlevel,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M15|OBJ_PERIOD_H1);
}
else
{
Print("Could not get High prices over the past 2 days, Error = ",GetLastError());
}
//--- Reset the last error
ResetLastError();
//--- Get the 2 days values Low on the daily timeframe
int lowsgot=CopyLow(Symbol(),PERIOD_D1,0,2,lows);
if(lowsgot>0) // If copying was successful
{
Print("Low prices for the last 2 days were obtained successfully");
prevLow=lows[0]; // The previous day Low
Print("prevLow = ",prevLow);
if(ObjectFind(0,lowlevel)<0) // Object with the name lowlevel not found
{
ObjectCreate(0,lowlevel,OBJ_HLINE,0,0,0); // Create the Horizontal Line object
}
//--- Set value for the price level for the line lowlevel
ObjectSetDouble(0,lowlevel,OBJPROP_PRICE,0,prevLow);
//--- Set the visibility only PERIOD_M15 and PERIOD_H1
ObjectSetInteger(0,lowlevel,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M15|OBJ_PERIOD_H1);
}
else Print("Could not get Low prices for the last 2 days, Error = ",GetLastError());
ChartRedraw(0); // redraw the chart forcibly
}另请参阅
最后更新于