跳至内容

ChartNavigate

ChartNavigate

执行指定图表相对于图表中指定位置的条形图移动指定数量条。该命令被添加到图表消息队列中,并且只有在所有先前的命令处理完成后才会执行。

bool  ChartNavigate(
   long  chart_id,     // Chart ID
   int   position,     // Position
   int   shift=0       // Shift value
   );

参数

chart_id

[in] 图表ID。0表示当前图表。

position

[in] 要执行的图表位置。可以是ENUM_CHART_POSITION中的值之一。

shift=0

[in] 移动图表的条形图数量。正值表示向右移动(到图表的末尾),负值表示向左移动(到图表的开始)。零位移可用于导航到图表的开始或末尾。

返回值

如果成功则返回true,否则返回false。

示例:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- get handle of the current chart
   long handle=ChartID();
   string comm="";
   if(handle>0) // if successful, additionally set up the chart
     {
      //--- disable auto scroll
      ChartSetInteger(handle,CHART_AUTOSCROLL,false);
      //--- set a shift from the right chart border
      ChartSetInteger(handle,CHART_SHIFT,true);
      //--- draw candlesticks
      ChartSetInteger(handle,CHART_MODE,CHART_CANDLES);
      //--- set the display mode for tick volumes
      ChartSetInteger(handle,CHART_SHOW_VOLUMES,CHART_VOLUME_TICK);

      //--- prepare a text to output in Comment()
      comm="Scroll 10 bars to the right of the history start";
      //--- show comment
      Comment(comm);
      //--- scroll 10 bars to the right of the history start
      ChartNavigate(handle,CHART_BEGIN,10);
      //--- get the number of the first bar visible on the chart (numeration like in timeseries)
      long first_bar=ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
      //--- add line feed character
      comm=comm+"\r\n";
      //--- add to comment
      comm=comm+"The first bar on the chart is number "+IntegerToString(first_bar)+"\r\n";
      //--- show comment
      Comment(comm);
      //--- wait 5 seconds to see how the chart moves
      Sleep(5000);

      //--- add to the comment text
      comm=comm+"\r\n"+"Scroll 10 bars to the left of the right chart border";
      Comment(comm);
      //--- scroll 10 bars to the left of the right chart border
      ChartNavigate(handle,CHART_END,-10);
      //--- get the number of the first bar visible on the chart (numeration like in timeseries)
      first_bar=ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
      comm=comm+"\r\n";
      comm=comm+"The first bar on the chart is number "+IntegerToString(first_bar)+"\r\n";
      Comment(comm);
      //--- wait 5 seconds to see how the chart moves
      Sleep(5000);

      //--- new block of chart scrolling
      comm=comm+"\r\n"+"Scroll 300 bars to the right of the history start";
      Comment(comm);
      //--- scroll 300 bars to the right of the history start
      ChartNavigate(handle,CHART_BEGIN,300);
      first_bar=ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
      comm=comm+"\r\n";
      comm=comm+"The first bar on the chart is number "+IntegerToString(first_bar)+"\r\n";
      Comment(comm);
      //--- wait 5 seconds to see how the chart moves
      Sleep(5000);

      //--- new block of chart scrolling
      comm=comm+"\r\n"+"Scroll 300 bars to the left of the right chart border";
      Comment(comm);
      //--- scroll 300 bars to the left of the right chart border
      ChartNavigate(handle,CHART_END,-300);
      first_bar=ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
      comm=comm+"\r\n";
      comm=comm+"The first bar on the chart is number "+IntegerToString(first_bar)+"\r\n";
      Comment(comm);
     }
  }
最后更新于