首页 > 解决方案 > 如何将标签移到当前蜡烛上?

问题描述

#property       strict
#property       indicator_chart_window
int OnInit(){

   if( ObjectFind("MyLabel") == -1)
      ObjectCreate(0, "MyLabel", OBJ_LABEL, 0, 0, 0);

   return(INIT_SUCCEEDED);

}

void OnDeinit(const int reason){

   if( ObjectFind("MyLabel") >=0 )
      ObjectDelete(0, "MyLabel");

}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {

   ObjectSetText( "MyLabel", "$"+DoubleToString(((Close[0]-Close[4])*10000),1), 12, "Times New Roman", clrBlue);
   ObjectMove( "MyLabel", OBJ_TEXT, Time[0], Close[0]);

   return(rates_total);
  }

图表标签

我想将 72.9 美元移动到我放置红色箭头的当前蜡烛,不仅我希望标签立即移动到当前蜡烛,新蜡烛出现?

提前谢谢你

标签: mql4

解决方案


您已经创建了一个 Label 对象,它的属性是 x 和 y。您应该创建文本对象(使用 OBJ_TEXT),以便您可以在时间/价格轴上移动它


推荐阅读