96 lines
3.5 KiB
MQL5
96 lines
3.5 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ColorBar.mq5 |
|
|
//| Copyright 2026, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
|
|
//--- input parameters
|
|
//input color corALTA = clrLime;
|
|
//input color corBAIXA = clrRed;
|
|
|
|
#include "acm_common.mqh"
|
|
|
|
#property copyright "Copyright 2026, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
#property indicator_chart_window
|
|
#property indicator_buffers 5
|
|
#property indicator_plots 1
|
|
//--- plot Candles
|
|
#property indicator_label1 "Candles"
|
|
#property indicator_type1 DRAW_COLOR_CANDLES
|
|
#property indicator_color1 clrRed,clrLime,clrBlack
|
|
#property indicator_style1 STYLE_SOLID
|
|
#property indicator_width1 1
|
|
|
|
#define VERMELHO 0
|
|
#define VERDE 1
|
|
#define PRETO 2
|
|
//--- indicator buffers
|
|
double CandlesBuffer1[];
|
|
double CandlesBuffer2[];
|
|
double CandlesBuffer3[];
|
|
double CandlesBuffer4[];
|
|
double CandlesColors[];
|
|
//+------------------------------------------------------------------+
|
|
//| Custom indicator initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
SetChartProperties();
|
|
//--- indicator buffers mapping
|
|
SetIndexBuffer(0, CandlesBuffer1, INDICATOR_DATA);
|
|
SetIndexBuffer(1, CandlesBuffer2, INDICATOR_DATA);
|
|
SetIndexBuffer(2, CandlesBuffer3, INDICATOR_DATA);
|
|
SetIndexBuffer(3, CandlesBuffer4, INDICATOR_DATA);
|
|
SetIndexBuffer(4, CandlesColors, INDICATOR_COLOR_INDEX);
|
|
ArraySetAsSeries(CandlesBuffer1, true);
|
|
ArraySetAsSeries(CandlesBuffer2, true);
|
|
ArraySetAsSeries(CandlesBuffer3, true);
|
|
ArraySetAsSeries(CandlesBuffer4, true);
|
|
ArraySetAsSeries(CandlesColors, true);
|
|
//---
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Custom indicator iteration function |
|
|
//+------------------------------------------------------------------+
|
|
int OnCalculate(const int32_t rates_total,
|
|
const int32_t 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 int32_t &spread[])
|
|
|
|
{
|
|
//---
|
|
ArraySetAsSeries(open, true);
|
|
ArraySetAsSeries(high, true);
|
|
ArraySetAsSeries(low, true);
|
|
ArraySetAsSeries(close, true);
|
|
int copiar = MathMin(rates_total, rates_total - prev_calculated + 1);
|
|
//if (CopyBuffer(media_handle,0,0,copiar,MediaBuffer) <= 0 ) return 0;
|
|
for(int i = copiar - 1; i >= 0; i--)
|
|
{
|
|
CandlesBuffer1[i] = open[i];
|
|
CandlesBuffer2[i] = high[i];
|
|
CandlesBuffer3[i] = low[i];
|
|
CandlesBuffer4[i] = close[i];
|
|
CandlesColors[i] = PRETO;
|
|
if(i >= rates_total - 1)
|
|
continue;
|
|
if(open[i] > close[i])
|
|
CandlesColors[i] = VERDE;
|
|
if(open[i] < close[i])
|
|
CandlesColors[i] = VERMELHO;
|
|
//if(rsibuffer[i] <= 30 && mediabuffer[i] > mediabuffer[i+1]) CandlesColors[i] = VERDE;
|
|
//if(rsibuffer[i] >= 70 && mediabuffer[i] < mediabuffer[i+1]) CandlesColors[i] = VERMELHO;
|
|
}
|
|
//--- return value of prev_calculated for next call
|
|
return(rates_total);
|
|
}
|
|
//+------------------------------------------------------------------+
|