|
|
//+------------------------------------------------------------------+
//| XAUUSD_Monitor_Dots.mq4 |
//| Range / High Volatility / Drop Monitor |
//+------------------------------------------------------------------+
#property copyright "XAUUSD Monitor"
#property version "1.10"
#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 clrRed
#property indicator_color2 clrLime
#property indicator_color3 clrYellow
//--- inputs
input int ATR_Period = 14;
input double RangeMultiplier = 0.55; // Red - Range / consolidation
input double HighVolMultiplier = 1.60; // Green - High volatility
input double DropMultiplier = 1.10; // Yellow- Strong directional move
input int ArrowCode = 159; // Wingdings solid circle
input int ArrowSize = 2;
input bool OnlyClosedBars = true; // true = safer for EA
//--- buffers
double RangeBuffer[]; // Buffer 0 - Red
double HighVolBuffer[]; // Buffer 1 - Green
double DropBuffer[]; // Buffer 2 - Yellow
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, RangeBuffer);
SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, ArrowSize);
SetIndexArrow(0, ArrowCode);
SetIndexLabel(0, "Range");
SetIndexBuffer(1, HighVolBuffer);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, ArrowSize);
SetIndexArrow(1, ArrowCode);
SetIndexLabel(1, "High Volatility");
SetIndexBuffer(2, DropBuffer);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, ArrowSize);
SetIndexArrow(2, ArrowCode);
SetIndexLabel(2, "Drop / Spike");
IndicatorShortName("XAUUSD Monitor");
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[])
{
if(rates_total < ATR_Period + 5) return(0);
int limit = (prev_calculated == 0) ? rates_total - ATR_Period - 2
: rates_total - prev_calculated + 1;
for(int i = limit; i >= 0; i--)
{
// Skip current forming bar if requested
if(OnlyClosedBars && i == 0)
{
RangeBuffer = EMPTY_VALUE;
HighVolBuffer = EMPTY_VALUE;
DropBuffer = EMPTY_VALUE;
continue;
}
double atr = iATR(NULL, 0, ATR_Period, i);
if(atr <= 0) continue;
double barRange = high - low;
double barBody = MathAbs(open - close);
// Clear previous values
RangeBuffer = EMPTY_VALUE;
HighVolBuffer = EMPTY_VALUE;
DropBuffer = EMPTY_VALUE;
// Priority: Drop > HighVol > Range
if(barBody > DropMultiplier * atr)
{
DropBuffer = (close >= open) ? low - atr*0.25 : high + atr*0.25;
}
else if(barRange > HighVolMultiplier * atr)
{
HighVolBuffer = (close >= open) ? low - atr*0.15 : high + atr*0.15;
}
else if(barRange < RangeMultiplier * atr)
{
RangeBuffer = (high + low) / 2.0;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
复制代码 |
|