//+------------------------------------------------------------------+ //| sm3BarFractalBreak vX //+------------------------------------------------------------------+ #property copyright "Copyright 15.03.2020, SwingMan" #property strict #property description "Thread autor: dazjw2311" #property description "https://www.forexfactory.com/showthread.php?t=985306" /*-------------------------------------------------------------------- Source: smSmashBar Indicator_v2.0 14.03.2020 - v1.0 - first version --------------------------------------------------------------------*/ #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 clrDodgerBlue #property indicator_color2 clrRed #property indicator_color3 clrDodgerBlue #property indicator_color4 clrRed #property indicator_width1 0 #property indicator_width2 0 #property indicator_width3 1 #property indicator_width4 1 //------- external parameters ---------------------------------------+ input bool Draw_Fractal_Arrows=false; input int Line_Length =2; input int Line_Width =3; input bool Show_Comment =true; //+------------------------------------------------------------------+ //---- constants string CR="\n"; string sObj="3Bar_"; //---- buffers double arrowUP[],arrowDN[]; double arrowFractalUP[],arrowFractalDN[]; //---- variables datetime thisTime,oldTime; bool newBar; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorDigits(Digits); int iArrowSignal=164; int iArrowFractal=159; int iBuff=-1; //--- indicator buffers mapping iBuff++; //0 SetIndexBuffer(iBuff,arrowUP); SetIndexStyle(iBuff,DRAW_ARROW); SetIndexArrow(iBuff,iArrowSignal); SetIndexLabel(iBuff,"high UP"); iBuff++; //1 SetIndexBuffer(iBuff,arrowDN); SetIndexStyle(iBuff,DRAW_ARROW); SetIndexArrow(iBuff,iArrowSignal); SetIndexLabel(iBuff,"low DOWN"); iBuff++; //2 SetIndexBuffer(iBuff,arrowFractalUP); SetIndexStyle(iBuff,DRAW_ARROW); SetIndexArrow(iBuff,iArrowFractal); SetIndexLabel(iBuff,"fractal UP"); iBuff++; //3 SetIndexBuffer(iBuff,arrowFractalDN); SetIndexStyle(iBuff,DRAW_ARROW); SetIndexArrow(iBuff,iArrowFractal); SetIndexLabel(iBuff,"fractal DOWN"); //--- ChartSetInteger(0,CHART_SHOW_OBJECT_DESCR,false); ChartSetInteger(0,CHART_SHOW_GRID,false); ObjectsDeleteAll(0,sObj); //--- if(Show_Comment==true) Comment(WindowExpertName(),CR, "=================="); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { if(Show_Comment==true) Comment(""); ObjectsDeleteAll(0,sObj); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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 limit=rates_total-prev_calculated; //--- if(rates_total<=10) return(0); if(prev_calculated==0) limit=limit-20; if(prev_calculated>0) limit++; if(limit<5) limit=5; //========================================================= int period=Period(); double low1,low2,low3,low4; double high1,high2,high3,high4; bool buyCondition,sellCondition; for(int i=limit; i>=0; i--) { //---- new bar ----------------------------------------- thisTime=Time[i]; if(thisTime!=oldTime) { oldTime=thisTime; newBar=true; } else newBar=false; //--- prices ---------------------------------------- low1=NormalizeDouble(iLow(Symbol(),period,i+1),Digits); low2=NormalizeDouble(iLow(Symbol(),period,i+2),Digits); low3=NormalizeDouble(iLow(Symbol(),period,i+3),Digits); low4=NormalizeDouble(iLow(Symbol(),period,i+4),Digits); high1=NormalizeDouble(iHigh(Symbol(),period,i+1),Digits); high2=NormalizeDouble(iHigh(Symbol(),period,i+2),Digits); high3=NormalizeDouble(iHigh(Symbol(),period,i+3),Digits); high4=NormalizeDouble(iHigh(Symbol(),period,i+4),Digits); //=================================================== //--- fractals 1-1 ---------------------------------- if(Draw_Fractal_Arrows==true) { if(high3low2 && low1>low2) arrowFractalDN[i+2]=Low[i+2]; } //=================================================== //--- signal bars ----------------------------------- //-- condition 1 - stronger buyCondition =(low4>low3 && low3low2 && high1>high2); sellCondition=(high4high2 && high1low3 && low3high2); //sellCondition=(high4high2 && low1