这是指示器,它返回新栏的剩余时间:
#property indicator_chart_window
#property strict
#property indicator_buffers 1
//---- input parameters
input color Clock_Color = clrWhite;
input ENUM_BASE_CORNER Corner = CORNER_LEFT_LOWER;
string objname="Spread&Bar";
double s1[];
double remainingtime[];
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0,remainingtime,INDICATOR_CALCULATIONS);
ObjectCreate(0, objname, OBJ_LABEL,0, 0, 0);
ObjectSetInteger(0, objname, OBJPROP_CORNER, Corner);
ObjectSetInteger(0, objname, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, objname, OBJPROP_YDISTANCE, 2);
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
switch (Corner)
{
case CORNER_LEFT_UPPER: Anchor=ANCHOR_LEFT_UPPER; break;
case CORNER_RIGHT_UPPER: Anchor=ANCHOR_RIGHT_UPPER; break;
case CORNER_LEFT_LOWER: Anchor=ANCHOR_LEFT_LOWER; break;
case CORNER_RIGHT_LOWER: Anchor=ANCHOR_RIGHT_LOWER; break;
}
ObjectSetInteger(0, objname, OBJPROP_ANCHOR, Anchor);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason) { ObjectDelete(0, objname); }
//+------------------------------------------------------------------+
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& spreads[])
{
ArraySetAsSeries(time, true);
int m=int(time[0]+PeriodSeconds()-TimeCurrent());
int s=m%60;
m=(m-s)/60;
long spread=SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp="",_m="",_s="";
if (spread<10) _sp="..";
else if (spread<100) _sp=".";
if (m<10) _m="0";
if (s<10) _s="0";
ObjectSetString(0, objname, OBJPROP_TEXT, "Spread: " +IntegerToString(spread)+_sp+" Next Bar in "+_m+IntegerToString(m)+":"+_s+IntegerToString(s));
remainingtime[0] = s;
Print(remainingtime[0]);
ObjectSetInteger(0, objname, OBJPROP_FONTSIZE, 10);
ObjectSetInteger(0, objname, OBJPROP_COLOR, Clock_Color);
ObjectSetString(0, objname, OBJPROP_FONT, "Courier");
return(rates_total);
}
我在打印时获得了正确的价值。但是,当我通过专家调用它时,我只得到了零。
这是专家:
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int candletime;
double remaining_time[];
int OnInit()
{
//---
candletime = iCustom(_Symbol,_Period,"candle_time_end_and_spread.ex5");
ArraySetAsSeries(remaining_time,true);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
IndicatorRelease(candletime);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
////---
CopyBuffer(candletime,0,0,1,remaining_time);
ArrayPrint(remaining_time);
}
请让我知道我做错了什么。
答案 0 :(得分:1)
首先,不知道为什么你需要这个简单任务的指标。
jQuery(element).after(ul_element);
第二,不清楚你 const int seconds =PeriodSeconds();
int secondsRemaining = seconds - TimeCurrent()%seconds;
正在做什么。我建议检查ArrayPrint()
,也不需要将该数组设置为时间序列。当然,您应该检查您的句柄是否不是remaining_time[0]
并且您设法复制了至少1个元素。简单的调试会告诉你问题。我认为指标的名称可以没有ex5后缀