CustomPlotFunction (Get yöntemi)

Kullanıcı tanımlı eğri çizimi için kullanılan fonksiyonun işaretçisini alır.

PlotFucntion  CustomPlotFunction()

Dönüş Değeri

Kullanıcı tanımlı eğri çizimi için kullanılan fonksiyonun işaretçisi.

CustomPlotFunction (Set yöntemi)

Kullanıcı tanımlı eğri çizimi için kullanılan fonksiyonun işaretçisini ayarlar.

void  CustomPlotFunction(
   PlotFucntion  func      // fonksiyonun işaretçisi
   )

Parametreler

func

[in]  Kullanıcı tanımlı eğri çizimi için kullanılan fonksiyonun işaretçisi

Örnek:

Kullanıcı tanımlı eğri çizimi modu

Çubuklardan olşan bu eğri aşağıdaki kod ile çizilmiştir:

//+------------------------------------------------------------------+
//|                                                CandleGraphic.mq5 |
//|                         Copyright 2000-2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Graphics\Graphic.mqh>
//+------------------------------------------------------------------+
//| CCandle Sınıfı                                                   |
//| Kullanım: Mum çizimi için bir sınıf                              |
//+------------------------------------------------------------------+
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(voidconst { return(m_clr_inc);  }
   uint              CandleColorDecrement(voidconst { return(m_clr_dec);  }
   int               CandleWidth(void)          const { return(m_width);    }
  };
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
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)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CCandle::~CCandle(void)
  {
  }
//+------------------------------------------------------------------+
//| Mum çizimi için kullanıcı tanımlı yöntem                         |
//+------------------------------------------------------------------+
void PlotCandles(double &x[],double &y[],int size,CGraphic *graphic,CCanvas *canvas,void *cbdata)
  {
//--- nesneyi kontrol et
   CArrayObj *candles=dynamic_cast<CArrayObj*>(cbdata);
   if(candles==NULL || candles.Total()!=size)
      return;
//--- mumları çiz  
   for(int i=0; i<size; i++)
     {
      CCandle *candle=dynamic_cast<CCandle*>(candles.At(i));
      if(candle==NULL)
         return;
      //--- ön hesaplama
      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();
      //--- mumu çiz
      canvas.LineVertical(xc,high,low,0x000000);
      //--- mum gövdesini çiz
      canvas.FillRectangle(xc+width_2,open,xc-width_2,close,clr);
      canvas.Rectangle(xc+width_2,open,xc-width_2,close,0x000000);
     }
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
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;
//--- değerleri oluştur 
   for(int i=0; i<count; i++)
     {
      x[i] = i;
      y[i] = i;
      //--- değerleri hesapla
      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);
      //--- max ve min değerlerini bul
      if(i==0 || max<high)
         max=high;
      if(i==0 || min>low)
         min=low;
      //--- mumu oluştur
      CCandle *candle=new CCandle(open,close,high,low,width);
      candles.Add(candle);
     }
//--- grafiği oluştur
   CGraphic graphic;
   if(!graphic.Create(0,"CandleGraphic",0,30,30,780,380))
     {
      graphic.Attach(0,"CandleGraphic");
     }
//--- eğri oluştur
   CCurve *curve=graphic.CurveAdd(x,y,CURVE_CUSTOM,"Candles");
//--- eğri özelliklerini ayarlar
   curve.CustomPlotFunction(PlotCandles);
   curve.CustomPlotCBData(GetPointer(candles));
//--- grafik özelliklerini ayarlar
   graphic.YAxis().Max((int)max);
   graphic.YAxis().Min((int)min);
//--- çiz 
   graphic.CurvePlotAll();
   graphic.Update();
  }