//+------------------------------------------------------------------+
//| DateAxisGraphic.mq5 |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Graphics\Graphic.mqh>
//--- 저장소 값의 배열
double arrX[];
double arrY[];
//+------------------------------------------------------------------+
//| X-축에 값을 만드는 사용자 지정 함수 |
//+------------------------------------------------------------------+
string TimeFormat(double x,void *cbdata)
{
return(TimeToString((datetime)arrX[ArraySize(arrX)-(int)x-1]));
}
//+------------------------------------------------------------------+
void OnStart()
{
MqlRates rates[];
CopyRates(Symbol(),Period(),0,100,rates);
ArraySetAsSeries(rates,true);
int size=ArraySize(rates);
ArrayResize(arrX,size);
ArrayResize(arrY,size);
for(int i=0; i<size;++i)
{
arrX[i]=(double)rates[i].time;
arrY[i]=rates[i].close;
}
//--- 그래픽 생성
CGraphic graphic;
if(!graphic.Create(0,"DateAxisGraphic",0,30,30,780,380))
{
graphic.Attach(0,"DateAxisGraphic");
}
//--- 곡선 생성
CCurve *curve=graphic.CurveAdd(arrY,CURVE_LINES);
//--- X-축 가져오기
CAxis *xAxis=graphic.XAxis();
//--- X-축 속성 설정하기
xAxis.AutoScale(false);
xAxis.Type(AXIS_TYPE_CUSTOM);
xAxis.ValuesFunctionFormat(TimeFormat);
xAxis.DefaultStep(20.0);
//--- 플롯
graphic.CurvePlotAll();
graphic.Update();
}
|