我有一个奇怪的发生,我无法弄清楚。我开发了一个自定义指标,用于计算指数,然后我将做出交易决策。该指标使用三个时间段来检查趋势是否稳定。第一个是一分钟,第二个是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总是如此..
答案 0 :(得分:0)
我最终想出了几天没有找到的答案!在最近的栏中,其中一个或5分钟或30分钟图表的条件发生了变化。一分钟的条形记录了每分钟5分钟和30分钟的条件。如果我点击刷新,过去的柱子现在很坚固,因此可以最终计算出来。
如果希望这些条件发生变化,则需要代码更新过去的条形码。
感谢您考虑帮助我。