#property indicator_separate_window
//--- 设置指标窗口的最大最小值
#property indicator_minimum 0
#property indicator_maximum 100
//--- 在单独指标窗口展示三条水平线
#property indicator_level1 25
#property indicator_level2 50
#property indicator_level3 75
//--- 设置水平线的粗细
#property indicator_levelwidth 1
//--- 设置水平线的样式
#property indicator_levelstyle STYLE_DOT
//+------------------------------------------------------------------+
//| 自定义指标初始化函数 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 设置水平线的描述
IndicatorSetString(INDICATOR_LEVELTEXT,0,"First Level (index 0)");
IndicatorSetString(INDICATOR_LEVELTEXT,1,"Second Level (index 1)");
IndicatorSetString(INDICATOR_LEVELTEXT,2,"Third Level (index 2)");
//--- 设置指标缩略名
IndicatorSetString(INDICATOR_SHORTNAME,"IndicatorSetDouble() Demo");
//--- 设置每个水平的颜色
IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrBlue);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGreen);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrRed);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 自定义指标迭代函数 |
//+------------------------------------------------------------------+
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[])
{
static int tick_counter=0;
static double level1=25,level2=50,level3=75;
static double max=100,min=0, shift=100;
//--- 计算订单号
tick_counter++;
//--- 每10个订单号颠倒一次水平
if(tick_counter%10==0)
{
//--- 水平值的颠倒符号
level1=-level1;
level2=-level2;
level3=-level3;
//--- 最大最小值的颠倒符号
max-=shift;
min-=shift;
//--- 颠倒替换值
shift=-shift;
//--- 设置新的水平值
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,level1);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,level2);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,level3);
//--- 在指标窗口设置新的最大最小值
Print("Set up max = ",max,", min = ",min);
IndicatorSetDouble(INDICATOR_MAXIMUM,max);
IndicatorSetDouble(INDICATOR_MINIMUM,min);
}
//--- 返回prev_calculated值以便下次调用
return(rates_total);
}
|