ChartIndicatorDelete

指定された名称の指標を指定されたチャートウィンドウから削除します。

bool  ChartIndicatorDelete(
  long          chart_id,              // チャート識別子
  int            sub_window             // サブウィンドウ番号
  const string  indicator_shortname   // 指標短縮名
  );

パラメータ

chart_id

[in]  チャート識別子。( 0 は現在のチャート)

sub_window

[in]  チャートサブウィンドウの番号。( 0 はメインチャートウィンドウ)

const indicator_shortname

[in] IndicatorSetString() 関数で INDICATOR_SHORTNAMEプロパティに設定した指標の短縮名指標の短縮名を取得するには ChartIndicatorName() 関数が呼ばれます。

戻り値

指標の削除が成功した場合は true、その他の場合は false。エラーの詳細を取得するにはGetLastError() 関数を使用します。

注意事項

同一の短縮名を持つ指標がチャートサブウィンドウに 2 つ存在する場合、行の最初のものは削除されます。

このチャート上の他の指標が削除される指標の値に基づいている場合は、そのような指標も削除されます。

iCustom() 及び IndicatorCreate() 関数を使用して指標を作成する際、指標の短縮名とファイル名を混同しないでください。指標の短縮名が明示的に設定されていない場合、指標のソースコードを含むファイルの名称は、コンパイル時に指定されます。

指標のチャートからの削除は、その演算部が端末のメモリから削除されることを意味するものではありません。指標ハンドルを解除するには IndicatorRelease() 関数が使用されます。

指標の短縮名は正しく形成されなければなりません。短縮名は IndicatorSetString() 関数を使用してINDICATOR_SHORTNAMEプロパティに書かれます。ChartIndicatorDelete() 関数によってチャートから削除される指標は短縮名によって識別されるので、短縮名に指標の全ての入力パラメータの値を含むようお勧めします。

初期化の失敗後に指標を削除する例:

//+------------------------------------------------------------------+
//|                                    Demo_ChartIndicatorDelete.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                             https://www.MQL5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link     "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- ヒストグラムをプロットする
#property indicator_label1 "Histogram"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1  1
//--- 入力パラメータ
input int     first_param=1;
input int     second_param=2;
input int     third_param=3;
input bool     wrong_init=true;
//--- 指標バッファ
double         HistogramBuffer[];
string         shortname;
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数                                            |
//+------------------------------------------------------------------+
int OnInit()
 {
  int res=INIT_SUCCEEDED;
//--- HistogramBuffer 配列を指標バッファに関係づける
  SetIndexBuffer(0,HistogramBuffer,INDICATOR_DATA);
//--- 入力パラメータに基づいて、指標短縮名を構築する
  shortname=StringFormat("Demo_ChartIndicatorDelete(%d,%d,%d)",
                        first_param,second_param,third_param);
  IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- 指標の強制終了が設定されている場合、ゼロ以外の値を返す
  if(wrong_init) res=INIT_FAILED;
  return(res);
 }
//+------------------------------------------------------------------+
//| カスタム指標の反復関数                                                |
//+------------------------------------------------------------------+
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[])
 {
//--- ループを操作するための開始位置
  int start=prev_calculated-1;
  if(start<0) start=0;
//--- 指標バッファに値を記入する
  for(int i=start;i<rates_total;i++)
    {
     HistogramBuffer[i]=close[i];
    }
//--- 次の呼び出しのために prev_calculated の値を返す
  return(rates_total);
 }
//+------------------------------------------------------------------+
//| Deinit イベントハンドラ                                                |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
 {
  PrintFormat("%s: Deinitialization reason code=%d",__FUNCTION__,reason);
  if(reason==REASON_INITFAILED)
    {
    PrintFormat("An indicator with a short name %s (file %s) deletes itself from the chart",shortname,__FILE__);
    int window=ChartWindowFind();
    bool res=ChartIndicatorDelete(0,window,shortname);
    //--- ChartIndicatorDelete() 呼び出しの結果を分析する
    if(!res)
       {
        PrintFormat("Failed to delete indicator %s from window #%d. Error code %d",
                    shortname,window,GetLastError());
       }
    }
 }

参照

ChartIndicatorAdd(), ChartIndicatorName(), ChartIndicatorsTotal(), iCustom(), IndicatorCreate(), IndicatorSetString()