Here is a start...
Xard777
Code: Select all
//+------------------------------------------------------------------+
//| ATR Grid Indicator from Daily |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Orange
#property indicator_color3 Yellow
#property indicator_color4 Yellow
#property indicator_color5 Orange
#property indicator_color6 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
//--- Input parameters
input int daily_atr_len = 15;
double lvl1 = 0.5;
double lvl2 = 0.7;
//--- Buffers for storing ATR values
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
int OnInit()
{
SetIndexBuffer(0, Buffer1, INDICATOR_DATA);
SetIndexBuffer(1, Buffer2, INDICATOR_DATA);
SetIndexBuffer(2, Buffer3, INDICATOR_DATA);
SetIndexBuffer(3, Buffer4, INDICATOR_DATA);
SetIndexBuffer(4, Buffer5, INDICATOR_DATA);
SetIndexBuffer(5, Buffer6, INDICATOR_DATA);
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexStyle(3, DRAW_LINE);
SetIndexStyle(4, DRAW_LINE);
SetIndexStyle(5, DRAW_LINE);
IndicatorShortName("ATR Grid from Daily");
return(INIT_SUCCEEDED);
}
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 limit;
if(prev_calculated == 0)
limit = rates_total - daily_atr_len;
else
limit = rates_total - prev_calculated;
// Daily ATR calculation
for(int i = limit; i >= 0; i--)
{
double dailyATR = iATR(NULL, PERIOD_D1, daily_atr_len, i);
double dailyClose = iClose(NULL, PERIOD_D1, i);
Buffer1[i] = dailyClose + dailyATR;
Buffer2[i] = dailyClose + dailyATR * lvl2;
Buffer3[i] = dailyClose + dailyATR * lvl1;
Buffer4[i] = dailyClose - dailyATR * lvl1;
Buffer5[i] = dailyClose - dailyATR * lvl2;
Buffer6[i] = dailyClose - dailyATR;
}
return(rates_total);
}
// Note: Fill color between lines in MT4 is not directly supported like in TradingView.
// You might need to use a custom indicator or modify the chart appearance externally to achieve the fill effect.