66 lines
2.1 KiB
MQL5
66 lines
2.1 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| HistogramChartSample.mq5 |
|
|
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com"
|
|
#property description "Example of using histogram"
|
|
//---
|
|
#include <Canvas\Charts\HistogramChart.mqh>
|
|
//+------------------------------------------------------------------+
|
|
//| inputs |
|
|
//+------------------------------------------------------------------+
|
|
input bool Accumulative=true;
|
|
//+------------------------------------------------------------------+
|
|
//| Script program start function |
|
|
//+------------------------------------------------------------------+
|
|
int OnStart(void)
|
|
{
|
|
int k=100;
|
|
double arr[10];
|
|
//--- create chart
|
|
CHistogramChart chart;
|
|
if(!chart.CreateBitmapLabel("SampleHistogramChart",10,10,600,450))
|
|
{
|
|
Print("Error creating histogram chart: ",GetLastError());
|
|
return(-1);
|
|
}
|
|
if(Accumulative)
|
|
{
|
|
chart.Accumulative();
|
|
chart.VScaleParams(20*k*10,-10*k*10,20);
|
|
}
|
|
else
|
|
chart.VScaleParams(20*k,-10*k,20);
|
|
chart.ShowValue(true);
|
|
chart.ShowScaleTop(false);
|
|
chart.ShowScaleBottom(false);
|
|
chart.ShowScaleRight(false);
|
|
chart.ShowLegend();
|
|
for(int j=0;j<5;j++)
|
|
{
|
|
for(int i=0;i<10;i++)
|
|
{
|
|
k=-k;
|
|
if(k>0)
|
|
arr[i]=k*(i+10-j);
|
|
else
|
|
arr[i]=k*(i+10-j)/2;
|
|
}
|
|
chart.SeriesAdd(arr,"Item"+IntegerToString(j));
|
|
}
|
|
//--- play with values
|
|
while(!IsStopped())
|
|
{
|
|
int i=rand()%5;
|
|
int j=rand()%10;
|
|
k=rand()%3000-1000;
|
|
chart.ValueUpdate(i,j,k);
|
|
Sleep(200);
|
|
}
|
|
//--- finish
|
|
chart.Destroy();
|
|
return(0);
|
|
}
|
|
//+------------------------------------------------------------------+
|