Альтерой
переименовал
//+------------------------------------------------------------------+
//| DivOsMA.mq4 |
//+------------------------------------------------------------------+
#property copyright "2005-2014, MetaQuotes Software Corp."
#property link "http://www.mql4.com"
#property description "Moving Averages of Oscillator"
#property strict
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Silver
#property indicator_width1 2
//--- indicator parameters
input int InpFastEMA=12; // Fast EMA Period
input int InpSlowEMA=26; // Slow EMA Period
input int InpSignalSMA=9; // Signal SMA Period
input int MAPeriod=12; // Simple MA Period
//--- indicator buffers
double ExtOsmaBuffer[];
double ExtMacdBuffer[];
double ExtSignalBuffer[];
//--- right input parameters flag
bool ExtParameters=false;
datetime tim=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- 2 additional buffers are used for counting.
IndicatorBuffers(3);
//--- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexDrawBegin(0,InpSignalSMA);
IndicatorDigits(Digits+2);
//--- 3 indicator buffers mapping
SetIndexBuffer(0,ExtOsmaBuffer);
SetIndexBuffer(1,ExtMacdBuffer);
SetIndexBuffer(2,ExtSignalBuffer);
//--- name for DataWindow and indicator subwindow label
IndicatorShortName("OsMA("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");
//--- check for input parameters
if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)
{
Print("Wrong input parameters");
ExtParameters=false;
return(INIT_FAILED);
}
else
ExtParameters=true;
//--- initialization done
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutPointer(double price,datetime time,int code,color clr)
{
const string name="Point"+TimeToStr(TimeCurrent());
//--- создаем стрелку "SELL"
ObjectCreate(name,OBJ_ARROW,0,time,price,0,0);
ObjectSet(name,OBJPROP_BACK,true);
ObjectSet(name,OBJPROP_COLOR,clr);
ObjectSet(name,OBJPROP_ARROWCODE,code);
ObjectSet(name,OBJPROP_WIDTH,1);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutVLine(datetime t)
{
const string name="VLine"+TimeToStr(TimeCurrent());
ObjectCreate(0,name,OBJ_VLINE,0,t,0);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,Blue);
//--- установим стиль отображения линии
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+------------------------------------------------------------------+
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 i,limit;
double ma1=iMA(NULL,0,MAPeriod,0,0,0,1);
double ma2=iMA(NULL,0,MAPeriod,0,0,0,2);
double ma3=iMA(NULL,0,MAPeriod,0,0,0,3);
//---
if(rates_total<=InpSignalSMA || !ExtParameters)
return(0);
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit++;
//--- macd counted in the 1-st buffer
for(i=0; i<limit; i++)
ExtMacdBuffer[i]=iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//--- signal line counted in the 2-nd buffer
SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- main loop
for(i=0; i<limit; i++)
ExtOsmaBuffer[i]=ExtMacdBuffer[i]-ExtSignalBuffer[i];
if(tim!=Time[0])
{
if(ExtOsmaBuffer[1]>ExtOsmaBuffer[2] && ExtOsmaBuffer[2]>ExtOsmaBuffer[3] && ExtOsmaBuffer[3]<ExtOsmaBuffer[4] && ExtOsmaBuffer[1]<0 &&
ma1<ma2 && ma2<ma3)
{
Alert("Разворот снизу вверх!!!");
PutVLine(Time[0]);
PutPointer(Low[0],Time[0],233,Red);
}
if(ExtOsmaBuffer[1]<ExtOsmaBuffer[2] && ExtOsmaBuffer[2]<ExtOsmaBuffer[3] && ExtOsmaBuffer[3]>ExtOsmaBuffer[4] && ExtOsmaBuffer[1]>0 &&
ma1>ma2 && ma2>ma3)
{
Alert("Разворот сверху вниз!!!");
PutVLine(Time[0]);
PutPointer(High[0],Time[0],234,Aqua);
}
tim=Time[0];
}
//--- done
return(0);
}
//+------------------------------------------------------------------+
Когда 2 столбик гистограммы убывает в отрицательном поле и цена соответственно индикатору должна расти но она наоборот падает то тогда и сигнал: расхождение началось. Если 2 столбик в гистограмме в отрицательном поле т.е.ниже 0 увеличивается а цена соответственно должна падать но она растет вопреки индикатору то тогда тоже сигнал: расхождение началось. В поле индикатора выше 0 т. е. в положительной гистограмме все сигналы наоборот. Я уже не прошу про сигнал: расхождение окончилось.
вход на первой стрелочке… если эта позитыя убыточна то следующий вход на противоположном сигнале
AM2