/* Вход на восстановлении тренда после отката на 2 МА. */ #property copyright "MainCook: Integer" #property link "for-good-letters@yandex.ru" #property indicator_chart_window #property indicator_buffers 7 #property indicator_color1 CLR_NONE #property indicator_color2 CLR_NONE #property indicator_color3 DeepSkyBlue #property indicator_color4 Red #property indicator_color5 DeepSkyBlue #property indicator_color6 Red #property indicator_color7 Yellow #property indicator_width3 0 #property indicator_width4 0 #property indicator_width5 1 #property indicator_width6 1 //---- input parameters extern int FastMAPeriod=21; // Период быстрой МА extern int FastMAMethod=1; // Метод быстрой МА: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA extern int FastMAPrice=0; // Цена быстрой МА: 0-Close, 1-Open, 2-High, 3-Low, 4-Median, 5-Typical, 6-Weighted extern int SlowMAPeriod=34; // Период медленной МА extern int SlowMAMethod=1; // Метод медленной МА: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA extern int SlowMAPrice=0; // Цена медленной: МА 0-Close, 1-Open, 2-High, 3-Low, 4-Median, 5-Typical, 6-Weighted extern bool TwoBar=true; // Проверять перегиб МА по двум барам (слева от экстремума, справа всегда по одном бару) //---- buffers double fma[]; double sma[]; double buy[]; double sell[]; double buy1[]; double sell1[]; double close[]; double cnt[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(8); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,fma); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,sma); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,225); SetIndexBuffer(2,buy); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,226); SetIndexBuffer(3,sell); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,233); SetIndexBuffer(4,buy1); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,234); SetIndexBuffer(5,sell1); SetIndexStyle(6,DRAW_ARROW); SetIndexArrow(6,251); SetIndexBuffer(6,close); SetIndexBuffer(7,cnt); SetIndexLabel(0,"Fast MA"); SetIndexLabel(1,"Slow MA"); SetIndexLabel(2,""); SetIndexLabel(3,""); SetIndexLabel(4,""); SetIndexLabel(5,""); SetIndexLabel(6,""); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; int limit = Bars - counted_bars; if(counted_bars==0) limit-=4; for(int i=limit-1;i>=0;i--){ buy[i]=EMPTY_VALUE; sell[i]=EMPTY_VALUE; fma[i]=iMA(NULL,0,FastMAPeriod,0,FastMAMethod,FastMAPrice,i); sma[i]=iMA(NULL,0,SlowMAPeriod,0,SlowMAMethod,SlowMAPrice,i); cnt[i]=cnt[i+1]; buy1[i]=EMPTY_VALUE; sell1[i]=EMPTY_VALUE; close[i]=EMPTY_VALUE; if(fma[i]>sma[i]){ if(fma[i+1]<=sma[i+1]){ close[i]=Low[i]-Point*5; } if(fma[i+3]>fma[i+2] || !TwoBar){ if(fma[i+2]>fma[i+1]){ if(fma[i+1]=sma[i+1]){ close[i]=High[i]+Point*5; } if(fma[i+3]fma[i]){ sell[i]=High[i]+Point*5; if(cnt[i]>0){ cnt[i]=0; } cnt[i]--; if(cnt[i]==-1){ sell1[i]=High[i]+Point*5; } } } } } } return(0); } //+------------------------------------------------------------------+