CustomPlotFunction(取得メソッド)

カスタム曲線プロットモードを実装する関数へのポインタを取得します。

PlotFucntion  CustomPlotFunction()

戻り値

カスタム曲線プロットモードを実装する関数へのポインタ

CustomPlotFunction(設定メソッド)

カスタム曲線プロットモードを実装する関数へのポインタを設定します。

void  CustomPlotFunction(
  PlotFucntion  func      // 関数へのポインタ
  )

パラメータ

func

[in]  カスタム曲線プロットモードを実装する関数へのポインタ

例:

カスタム曲線プロットモード

バーで構成されるこの曲線は、次のコードを使用して作成されます。

//+------------------------------------------------------------------+
//|                                                CandleGraphic.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Graphics\Graphic.mqh>
//+------------------------------------------------------------------+
//| Class CCandle                                                    |
//| 使用法:ローソク足を表すクラス                                            |
//+------------------------------------------------------------------+
class CCandle: public CObject
 {
private:
  double            m_open;
  double            m_close;
  double            m_high;
  double            m_low;
  uint              m_clr_inc;
  uint              m_clr_dec;
  int               m_width;
 
public:
                    CCandle(const double open,const double close,const double high,const double low,
                                                      const int width,const uint clr_inc=0x000000,const uint clr_dec=0xF5F5F5);
                   ~CCandle(void);
  double            OpenValue(void)           const { return(m_open);     }
  double            CloseValue(void)           const { return(m_close);    }
  double            HigthValue(void)           const { return(m_high);     }
  double            LowValue(void)             const { return(m_low);      }
  uint              CandleColorIncrement(void) const { return(m_clr_inc);  }
  uint              CandleColorDecrement(void) const { return(m_clr_dec);  }
  int               CandleWidth(void)         const { return(m_width);    }
 };
//+------------------------------------------------------------------+
//| コンストラクタ                                                         |
//+------------------------------------------------------------------+
CCandle::CCandle(const double open,const double close,const double high,const double low,
                                const int width,const uint clr_inc=0x000000,const uint clr_dec=0xF5F5F5):
                                m_open(open),m_close(close),m_high(high),m_low(low),
                                m_clr_inc(clr_inc),m_clr_dec(clr_dec),m_width(width)
 {
 }
//+------------------------------------------------------------------+
//| デストラクタ                                                          |
//+------------------------------------------------------------------+
CCandle::~CCandle(void)
 {
 }
//+------------------------------------------------------------------+
//| Custom method for plot candles                                   |
//+------------------------------------------------------------------+
void PlotCandles(double &x[],double &y[],int size,CGraphic *graphic,CCanvas *canvas,void *cbdata)
 {
//--- check obj
  CArrayObj *candles=dynamic_cast<CArrayObj*>(cbdata);
  if(candles==NULL || candles.Total()!=size)
    return;
//--- plot candles  
  for(int i=0; i<size; i++)
    {
     CCandle *candle=dynamic_cast<CCandle*>(candles.At(i));
    if(candle==NULL)
        return;
    //--- primary calculate
    int xc=graphic.ScaleX(x[i]);
    int width_2=candle.CandleWidth()/2;
    int open=graphic.ScaleY(candle.OpenValue());
    int close=graphic.ScaleY(candle.CloseValue());
    int high=graphic.ScaleY(candle.HigthValue());
    int low=graphic.ScaleY(candle.LowValue());
    uint clr=(open<=close) ?candle.CandleColorIncrement() :  candle.CandleColorDecrement();
    //--- ローソク足をプロットする
     canvas.LineVertical(xc,high,low,0x000000);
    //--- ローソクの実体をプロットする
     canvas.FillRectangle(xc+width_2,open,xc-width_2,close,clr);
     canvas.Rectangle(xc+width_2,open,xc-width_2,close,0x000000);
    }
 }
//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数                                              |
//+------------------------------------------------------------------+
void OnStart()
 {
  int count=10;
  int width=10;
  double x[];
  double y[];
  ArrayResize(x,count);
  ArrayResize(y,count);
  CArrayObj candles();
  double max=0;
  double min=0;
//--- 値を作成する
  for(int i=0; i<count; i++)
    {
     x[i] = i;
     y[i] = i;
    //--- 値を計算する
    double open=MathRound(50.0+(MathRand()/32767.0)*50.0);
    double close=MathRound(50.0+(MathRand()/32767.0)*50.0);
    double high=MathRound(MathMax(open,close)+(MathRand()/32767.0)*10.0);
    double low=MathRound(MathMin(open,close) -(MathRand()/32767.0)*10.0);
    //--- 最高値と最低値を見つける
    if(i==0 || max<high)
        max=high;
    if(i==0 || min>low)
        min=low;
    //--- ローソク足を作成する
     CCandle *candle=new CCandle(open,close,high,low,width);
     candles.Add(candle);
    }
//--- グラフィックを作成する
  CGraphic graphic;
  if(!graphic.Create(0,"CandleGraphic",0,30,30,780,380))
    {
     graphic.Attach(0,"CandleGraphic");
    }
//--- 曲線を作成する
  CCurve *curve=graphic.CurveAdd(x,y,CURVE_CUSTOM,"Candles");
//--- 曲線のプロパティを設定する
  curve.CustomPlotFunction(PlotCandles);
  curve.CustomPlotCBData(GetPointer(candles));
//--- グラフィックのプロパティを設定する
  graphic.YAxis().Max((int)max);
  graphic.YAxis().Min((int)min);
//--- プロット
  graphic.CurvePlotAll();
  graphic.Update();
 }