78 lines
3 KiB
MQL5
78 lines
3 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ColorCandlesDaily.mq5 |
|
|
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com"
|
|
|
|
#property indicator_separate_window
|
|
#property indicator_buffers 5
|
|
#property indicator_plots 1
|
|
//--- plot ColorCandles
|
|
#property indicator_type1 DRAW_COLOR_CANDLES
|
|
#property indicator_label1 "Open;High;Low;Close"
|
|
//--- indicator buffers
|
|
double ExtOpenBuffer[];
|
|
double ExtHighBuffer[];
|
|
double ExtLowBuffer[];
|
|
double ExtCloseBuffer[];
|
|
double ExtColorsBuffer[];
|
|
//---
|
|
color ExtColorOfDay[6]= {clrNONE,clrMediumSlateBlue,clrDarkGoldenrod,clrForestGreen,clrBlueViolet,clrRed};
|
|
//+------------------------------------------------------------------+
|
|
//| Custom indicator initialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnInit()
|
|
{
|
|
//--- indicator buffers mapping
|
|
SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
|
|
SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
|
|
SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
|
|
SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
|
|
SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
|
|
//--- set number of colors in color buffer
|
|
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,6);
|
|
//--- set colors for color buffer
|
|
for(int i=1; i<6; i++)
|
|
PlotIndexSetInteger(0,PLOT_LINE_COLOR,i,ExtColorOfDay[i]);
|
|
//--- set accuracy
|
|
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
|
PrintFormat("We have %i colors of days",PlotIndexGetInteger(0,PLOT_COLOR_INDEXES));
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Custom indicator iteration function |
|
|
//+------------------------------------------------------------------+
|
|
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 pos;
|
|
MqlDateTime tstruct;
|
|
//---
|
|
if(prev_calculated<1)
|
|
pos=0;
|
|
else
|
|
pos=prev_calculated-1;
|
|
//--- main cycle
|
|
for(int i=pos; i<rates_total && !IsStopped(); i++)
|
|
{
|
|
ExtOpenBuffer[i]=open[i];
|
|
ExtHighBuffer[i]=high[i];
|
|
ExtLowBuffer[i]=low[i];
|
|
ExtCloseBuffer[i]=close[i];
|
|
//--- set color for every candle
|
|
TimeToStruct(time[i],tstruct);
|
|
ExtColorsBuffer[i]=tstruct.day_of_week;
|
|
}
|
|
//--- return value of prev_calculated for next call
|
|
return(rates_total);
|
|
}
|
|
//+------------------------------------------------------------------+
|