#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Lime

extern double ATRLevel = 0.0014;

double ATRBuffer[];

void 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 = rates_total - prev_calculated;
    if (limit <= 0) {
        return;
    }
    
    for (int i = 0; i < limit; i++) {
        ATRBuffer[i] = iATR(NULL, 0, 14, i);
    }
    
    for (int i = limit; i < rates_total; i++) {
        ATRBuffer[i] = iATR(NULL, 0, 14, i);
    }
}

int init() {
    SetIndexBuffer(0, ATRBuffer, INDICATOR_DATA);
    SetIndexStyle(0, DRAW_LINE);
    return (0);
}

int deinit() {
    return (0);
}

int start() {
    double ATRLevelBuffer[1];
    ATRLevelBuffer[0] = ATRLevel;
    SetLevelStyle(0, DASHED_LINE);
    SetLevelColor(0, Red);
    SetLevelValue(0, ATRLevel);
    SetIndexLabel(0, "ATR Level");
    return (0);
}
