//+------------------------------------------------------------------+ //| BrainTrend2-all-in-one.mq4 | //| www.forex-tsd.com | //| Nick Bilak | //| Modified by Serge skhorouji@gmail.com| //+------------------------------------------------------------------+ /* Serge: This indicator includes 3 original BrainTrend2 indicators as I am 2 lazy to apply them all one by one on a chart: BrainTrend2Stop, BrainTrend2StopLine, BrainTrend2Sig Note: BrainTrend2 indicator is not included as we use BrainTrend1 indicator for trend direction It has customisable external variables that can be played with during optimisation Also I renamed variables, simplified & logically re-arranged the codes of the original indicators to make them more understandable (I mean for myself :-) */ #property copyright "Copyright © 2005, MetaQuotes Software Corp." #property link "www.forex-tsd.com" #property indicator_chart_window #property indicator_buffers 6 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Red #property indicator_color4 Blue #property indicator_color5 Red #property indicator_color6 Blue //---- input parameters extern int NumBars=0; //If 0, all indicator will be drawn on the whole chart (from 1st bar) extern bool spread_eq_0=false; //if true, we will use spread=0 in all our calculations, if false we will use spread from the broker //---- buffers double sell_stop_dot_buf[]; //Sell stop dots, aka BrainTrend2Stop double buy_stop_dot_buf[]; //Buy stop dots double sell_stop_line_buf[]; //Sell stop line, aka BrainTrend2StopLine double buy_stop_line_buf[]; //Buy stop line double sell_signal_buf[]; //Sell signal dots, aka BrainTrend2Sig double buy_signal_buf[]; //Buy signal dots double spread; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,115); SetIndexBuffer(0,sell_stop_dot_buf); SetIndexLabel(0,"sell_stop_dot"); SetIndexEmptyValue(0, EMPTY_VALUE); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,115); SetIndexBuffer(1,buy_stop_dot_buf); SetIndexLabel(1,"buy_stop_dot"); SetIndexEmptyValue(1, EMPTY_VALUE); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,sell_stop_line_buf); SetIndexLabel(2,"sell_stop_line"); SetIndexEmptyValue(2, EMPTY_VALUE); SetIndexStyle(3,DRAW_LINE); SetIndexBuffer(3,buy_stop_line_buf); SetIndexLabel(3,"buy_stop_line"); SetIndexEmptyValue(3, EMPTY_VALUE); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,234); SetIndexBuffer(4,sell_signal_buf); SetIndexLabel(4,"sell_signal"); SetIndexEmptyValue(4, EMPTY_VALUE); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,233); SetIndexBuffer(5,buy_signal_buf); SetIndexLabel(5,"buy_signal"); SetIndexEmptyValue(5, EMPTY_VALUE); if (spread_eq_0 == false) spread=MarketInfo(Symbol(),MODE_SPREAD)*Point; else spread=0; } int start() { double true_range; int artp=7; bool river=True; double Emaxtra=0; double Values[100]; double ATR=0; int glava=0; double Weight=0; int Curr=0; double widcha=0; double cecf=0.7; double Range1=0; double r=0; double r1=0; int p=0; double s=2; if (NumBars == 0) NumBars = Bars; else NumBars = MathMin(Bars,NumBars); if (Close[NumBars - 2] > Close[NumBars - 1]) river = True; else river = False; Emaxtra = Close[NumBars - 2]; true_range = MathMax(spread + High[NumBars-3] - Low[NumBars-3], MathMax(MathAbs(spread+High[NumBars-3]-Close[NumBars-2]), MathAbs(spread+High[NumBars-3]-Close[NumBars-3]))); for (int i = 0; i <= artp-1; i++) Values[i] = true_range; for (int shift=NumBars-3; shift>=0; shift--) { true_range = MathMax(spread + High[shift] - Low[shift], MathMax(MathAbs(spread+High[shift]-Close[shift+1]),MathAbs(spread+High[shift]-Close[shift+1]))); Values[glava] = true_range; ATR = 0; Weight = artp; // 7 Curr = glava; // 0 for (i = 0; i<=artp-1; i++) { ATR += Values[Curr] * Weight; Weight -= 1; Curr -= 1; if (Curr == -1) Curr = artp - 1; } ATR = 2.0 * ATR / (artp * (artp + 1.0)); glava += 1; if (glava == artp) glava = 0; widcha = cecf * ATR; //cecf = 0.7 if (river && Low[shift] < Emaxtra - widcha) { river = False; Emaxtra = spread + High[shift]; } if (river && Low[shift] > Emaxtra) { Emaxtra = Low[shift]; } if (!river && spread + High[shift] > Emaxtra + widcha) { river = True; Emaxtra = Low[shift]; } if (!river && spread + High[shift] < Emaxtra) { Emaxtra = spread + High[shift]; } Range1 = iATR(NULL,0,10,shift)+spread/10.0; if (river) { if (Low[shift] - Range1 * s < r && r != 0) r1 = r; else r1 = Low[shift] - Range1 * s / 3.0; if (p == 2) { r1 = Low[shift] - Range1 * s / 3.0; buy_signal_buf[shift]=r1; } buy_stop_dot_buf[shift]=r1; buy_stop_line_buf[shift]=r1; r = r1; p = 1; } else { if (spread + High[shift] + Range1 * s > r && r != 0) r1 = r; else r1 = spread + High[shift] + Range1 * s / 3.0; if (p == 1) { r1 = spread + High[shift] + Range1 * s / 3.0; sell_signal_buf[shift]=r1; } sell_stop_dot_buf[shift]=r1; sell_stop_line_buf[shift]=r1; r = r1; p = 2; } } }
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Indicator Curves created:
Implements a curve of type DRAW_ARROW
Implements a curve of type DRAW_LINE
Indicators Used:
Indicator of the average true range
Custom Indicators Used:
Order Management characteristics:
Other Features: