【发布时间】:2018-01-31 15:25:27
【问题描述】:
我有一个奇怪的现象,我无法弄清楚。我开发了一个自定义指标来计算一个指数,然后我将做出交易决策。该指标使用三个时间段来检查趋势是否稳定。第一个是一分钟,第二个是 5 分钟,最后是 30 分钟。我计算了合适的柱,从中检查较大的时间段,以便它们与一分钟柱相对应。
我的测试表明这些数字计算正确。
此指标附加到一分钟图表。很多时候,我会右键单击并选择刷新,指标会在最后 5 - 10 分钟内发生变化!我找不到它会这样做的原因。我尝试在每分钟栏后单击刷新,有时它会改变,而其他时候则不会。但是,即使我在图表上每分钟点击一次,有时更改也会在 5 到 10 分钟后返回。
你能帮帮我吗?
为了您的帮助,我附上我的代码:
int start() // Special function start()
{
int i, // Bar index
iLook = 0,
iCurrMinute = 0,
iMinFloor = 0,
iMinsAdd = 0,
Counted_bars, // Number of counted bars
iCalcVal,
iTrendConsistency;
double EMA_1min_10_current, EMA_1min_10_prev,
EMA_5min_10_current, EMA_5min_10_prev,
EMA_30min_10_current, EMA_30min_10_prev,
EMA_1min_20_current, EMA_1min_20_prev,
EMA_5min_20_current, EMA_5min_20_prev,
EMA_30min_20_current, EMA_30min_20_prev,
dblMinRemain = 0;
datetime dtBarTime;
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
iCalcVal = 0;
iTrendConsistency = 0;
dtBarTime = iTime(NULL,PERIOD_M1,i);
// Calculate trend consistency
if (boolIncl1Min)
{
iLook = i;
EMA_1min_10_current = iMA(NULL,PERIOD_M1,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook);
EMA_1min_10_prev = iMA(NULL,PERIOD_M1,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook+1);
EMA_1min_20_current = iMA(NULL,PERIOD_M1,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook);
EMA_1min_20_prev = iMA(NULL,PERIOD_M1,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook+1);
if (EMA_1min_10_current > EMA_1min_20_current) iTrendConsistency++;
if (EMA_1min_10_current < EMA_1min_20_current) iTrendConsistency--;
if (EMA_1min_10_current > EMA_1min_10_prev) iTrendConsistency++;
if (EMA_1min_10_current < EMA_1min_10_prev) iTrendConsistency--;
if (EMA_1min_20_current > EMA_1min_20_prev) iTrendConsistency++;
if (EMA_1min_20_current < EMA_1min_20_prev) iTrendConsistency--;
if (iClose(NULL,PERIOD_M1,iLook) > EMA_1min_10_current) iTrendConsistency++;
if (iClose(NULL,PERIOD_M1,iLook) < EMA_1min_10_current) iTrendConsistency--;
}
if (boolIncl5Min)
{
iLook = i;
if (boolIncl1Min) iLook = iBarShift(NULL,PERIOD_M5,dtBarTime,true);
EMA_5min_10_current = iMA(NULL,PERIOD_M5,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook);
EMA_5min_10_prev = iMA(NULL,PERIOD_M5,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook+1);
EMA_5min_20_current = iMA(NULL,PERIOD_M5,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook);
EMA_5min_20_prev = iMA(NULL,PERIOD_M5,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook+1);
if (EMA_5min_10_current > EMA_5min_20_current) iTrendConsistency++;
if (EMA_5min_10_current < EMA_5min_20_current) iTrendConsistency--;
if (EMA_5min_10_current > EMA_5min_10_prev) iTrendConsistency++;
if (EMA_5min_10_current < EMA_5min_10_prev) iTrendConsistency--;
if (EMA_5min_20_current > EMA_5min_20_prev) iTrendConsistency++;
if (EMA_5min_20_current < EMA_5min_20_prev) iTrendConsistency--;
if (iClose(NULL,PERIOD_M5,iLook) > EMA_5min_10_current) iTrendConsistency++;
if (iClose(NULL,PERIOD_M5,iLook) < EMA_5min_10_current) iTrendConsistency--;
}
if(boolIncl30Min)
{
iLook = i;
if (boolIncl1Min) iLook = iBarShift(NULL,PERIOD_M30,dtBarTime,true);
EMA_30min_10_current = iMA(NULL,PERIOD_M30,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook);
EMA_30min_10_prev = iMA(NULL,PERIOD_M30,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook+1);
EMA_30min_20_current = iMA(NULL,PERIOD_M30,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook);
EMA_30min_20_prev = iMA(NULL,PERIOD_M30,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook+1);
if (EMA_30min_10_current > EMA_30min_20_current) iTrendConsistency++;
if (EMA_30min_10_current < EMA_30min_20_current) iTrendConsistency--;
if (EMA_30min_10_current > EMA_30min_10_prev) iTrendConsistency++;
if (EMA_30min_10_current < EMA_30min_10_prev) iTrendConsistency--;
if (EMA_30min_20_current > EMA_30min_20_prev) iTrendConsistency++;
if (EMA_30min_20_current < EMA_30min_20_prev) iTrendConsistency--;
if (iClose(NULL,PERIOD_M30,iLook) > EMA_30min_10_current) iTrendConsistency++;
if (iClose(NULL,PERIOD_M30,iLook) < EMA_30min_10_current) iTrendConsistency--;
}
Trend_Consistency[i]= iTrendConsistency;
i--; // Calculating index of the next bar
}
ps:boolIncl1Min 始终为 true..
【问题讨论】: