179 lines
5.0 KiB
Plaintext
179 lines
5.0 KiB
Plaintext
//+------------------------------------------------------------------+
|
|
//| Learn 3.mq5 |
|
|
//| Copyright 2016, Hudson Analytics |
|
|
//| NurudeenAmedu |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2016, Hudson Analytics"
|
|
#property link "NurudeenAmedu"
|
|
#property version "1.00"
|
|
#property indicator_separate_window
|
|
#property indicator_buffers 3
|
|
#property indicator_plots 2
|
|
#property indicator_type1 DRAW_LINE
|
|
#property indicator_color1 clrBlue
|
|
#property indicator_type2 DRAW_LINE
|
|
#property indicator_color2 clrRed
|
|
|
|
double ExtBuffer1[];
|
|
double ExtBuffer2[];
|
|
//+------------------------------------------------------------------+
|
|
//| Custom indicator initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
//--- indicator buffers mapping
|
|
SetIndexBuffer(0, ExtBuffer1);
|
|
SetIndexBuffer(1, ExtBuffer2);
|
|
//---
|
|
return (INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Custom indicator iteration function |
|
|
//+------------------------------------------------------------------+
|
|
int OnCalculate(const int rates_total, // 1001
|
|
const int prev_calculated, // 1000
|
|
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 x, y, limit;
|
|
int min_rates_total = 100;
|
|
|
|
ArraySetAsSeries(close, true);
|
|
ArraySetAsSeries(ExtBuffer1, true);
|
|
ArraySetAsSeries(ExtBuffer2, true);
|
|
|
|
//---- calculations of the necessary amount of data to be copied
|
|
//---- and the 'limit' starting index for the bars recalculation loop
|
|
if (prev_calculated > rates_total || prev_calculated <= 0) // checking for the first start of the indicator calculation
|
|
{
|
|
limit = rates_total - min_rates_total - 1; // calculated number of all bars
|
|
}
|
|
else
|
|
{
|
|
limit = rates_total - prev_calculated; // starting index for calculation of new bars
|
|
}
|
|
|
|
for (int i = limit; i >= 0; i--)
|
|
{
|
|
x = 0;
|
|
y = 0;
|
|
|
|
if (close[i] > close[i + 1])
|
|
x++;
|
|
if (close[i] < close[i + 1])
|
|
y++;
|
|
|
|
if (close[i] > close[i + 2])
|
|
x++;
|
|
if (close[i] < close[i + 2])
|
|
y++;
|
|
|
|
if (close[i] > close[i + 3])
|
|
x++;
|
|
if (close[i] < close[i + 3])
|
|
y++;
|
|
|
|
if (close[i] > close[i + 4])
|
|
x++;
|
|
if (close[i] < close[i + 4])
|
|
y++;
|
|
|
|
if (close[i] > close[i + 5])
|
|
x++;
|
|
if (close[i] < close[i + 5])
|
|
y++;
|
|
|
|
if (close[i] > close[i + 6])
|
|
x++;
|
|
if (close[i] < close[i + 6])
|
|
y++;
|
|
|
|
//////////////////////////
|
|
if (close[i + 1] > close[i + 2])
|
|
x++;
|
|
if (close[i + 1] < close[i + 2])
|
|
y++;
|
|
|
|
if (close[i + 1] > close[i + 3])
|
|
x++;
|
|
if (close[i + 1] < close[i + 3])
|
|
y++;
|
|
|
|
if (close[i + 1] > close[i + 4])
|
|
x++;
|
|
if (close[i + 1] < close[i + 4])
|
|
y++;
|
|
|
|
if (close[i + 1] > close[i + 5])
|
|
x++;
|
|
if (close[i + 1] < close[i + 5])
|
|
y++;
|
|
|
|
if (close[i + 1] > close[i + 6])
|
|
x++;
|
|
if (close[i + 1] < close[i + 6])
|
|
y++;
|
|
|
|
//////////////////////////////
|
|
if (close[i + 2] > close[i + 3])
|
|
x++;
|
|
if (close[i + 2] < close[i + 3])
|
|
y++;
|
|
|
|
if (close[i + 2] > close[i + 4])
|
|
x++;
|
|
if (close[i + 2] < close[i + 4])
|
|
y++;
|
|
|
|
if (close[i + 2] > close[i + 5])
|
|
x++;
|
|
if (close[i + 2] < close[i + 5])
|
|
y++;
|
|
|
|
if (close[i + 2] > close[i + 6])
|
|
x++;
|
|
if (close[i + 2] < close[i + 6])
|
|
y++;
|
|
|
|
////////////////////////////
|
|
if (close[i + 3] > close[i + 4])
|
|
x++;
|
|
if (close[i + 3] < close[i + 4])
|
|
y++;
|
|
|
|
if (close[i + 3] > close[i + 5])
|
|
x++;
|
|
if (close[i + 3] < close[i + 5])
|
|
y++;
|
|
|
|
if (close[i + 3] > close[i + 6])
|
|
x++;
|
|
if (close[i + 3] < close[i + 6])
|
|
y++;
|
|
|
|
////////////////////////////
|
|
if (close[i + 4] > close[i + 5])
|
|
x++;
|
|
if (close[i + 4] < close[i + 5])
|
|
y++;
|
|
|
|
if (close[i + 4] > close[i + 6])
|
|
x++;
|
|
if (close[i + 4] < close[i + 6])
|
|
y++;
|
|
|
|
ExtBuffer1[i] = MathAbs(x);
|
|
ExtBuffer2[i] = MathAbs(y);
|
|
}
|
|
//--- return value of prev_calculated for next call
|
|
return (rates_total);
|
|
}
|
|
//+------------------------------------------------------------------+
|