//+------------------------------------------------------------------+
//| HedgeOnDiffMAHist |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 DarkOrange
#property indicator_color3 Lime
#property indicator_color4 Green
#property indicator_color5 Snow
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
extern string ExtSymbol_1 = "FDAXZ0";//"BRNX0";
extern string ExtSymbol_2 = "MCZ0";//"6CZ0";
extern string Параметры_МА = "-------------------";
extern int ExtPeriodMAFast = 6;
extern int ExtPeriodMASlow = 18;
extern int ExtModeMA = MODE_SMMA;
extern int ExtPriceMA = PRICE_WEIGHTED;
//---- buffers
double BufferAboveUp[];
double BufferAboveDn[];
double BufferBelowDn[];
double BufferBelowUp[];
double BufferLine[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string sWindowName;
//IndicatorBuffers( 6 );
SetIndexStyle( 0, DRAW_HISTOGRAM );
SetIndexStyle( 1, DRAW_HISTOGRAM );
SetIndexStyle( 2, DRAW_HISTOGRAM );
SetIndexStyle( 3, DRAW_HISTOGRAM );
SetIndexStyle( 4, DRAW_LINE );
SetIndexBuffer( 0, BufferAboveUp );
SetIndexBuffer( 1, BufferAboveDn );
SetIndexBuffer( 2, BufferBelowDn );
SetIndexBuffer( 3, BufferBelowUp );
SetIndexBuffer( 4, BufferLine );
/*SetIndexLabel( 0, ExtSymbol_1 );
SetIndexLabel( 1, ExtSymbol_1 );
SetIndexLabel( 2, ExtSymbol_2 );
SetIndexLabel( 3, ExtSymbol_2 );*/
sWindowName = StringConcatenate( "HedgeOnDiffMAHist(", ExtSymbol_1, "-", ExtSymbol_2, ")" );
IndicatorShortName( sWindowName );
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit;
int iShiftBar;
double dDiffMA_1;
double dDiffMA_2;
limit = Bars - IndicatorCounted();
if ( limit > 1 ) {
limit = Bars - MathMax( ExtPeriodMASlow, ExtPeriodMAFast ) - 1;
}
//---- основной цикл
for( int k = limit; k >= 0; k-- ) {
iShiftBar = iBarShift( ExtSymbol_1, 0, Time[k], False );
dDiffMA_1 = iMA( ExtSymbol_1, Period(), ExtPeriodMAFast, 0, ExtModeMA, ExtPriceMA, iShiftBar ) /
iMA( ExtSymbol_1, Period(), ExtPeriodMASlow, 0, ExtModeMA, ExtPriceMA, iShiftBar );
iShiftBar = iBarShift( ExtSymbol_2, 0, Time[k], False );
dDiffMA_2 = iMA( ExtSymbol_2, Period(), ExtPeriodMAFast, 0, ExtModeMA, ExtPriceMA, iShiftBar ) /
iMA( ExtSymbol_2, Period(), ExtPeriodMASlow, 0, ExtModeMA, ExtPriceMA, iShiftBar );
BufferLine[k] = dDiffMA_1 - dDiffMA_2;
BufferAboveUp[k] = EMPTY_VALUE;
BufferAboveDn[k] = EMPTY_VALUE;
BufferBelowDn[k] = EMPTY_VALUE;
BufferBelowUp[k] = EMPTY_VALUE;
if ( BufferLine[k] > 0 ) {
if ( BufferLine[k] > BufferLine[k+1] ) {
BufferAboveUp[k] = BufferLine[k];
}
else {
BufferAboveDn[k] = BufferLine[k];
}
}
else {
if ( BufferLine[k] < BufferLine[k+1] ) {
BufferBelowDn[k] = BufferLine[k];
}
else {
BufferBelowUp[k] = BufferLine[k];
}
}
} // for
return(0);
}