//+------------------------------------------------------------------+ //| ClassyFractalSnR.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, by. ganztrade" #property link "http://www.metaquotes.net" #property description "ClassyFractalSnR" #property version "1.03" #property indicator_chart_window //---- input parameters input int CountedBars=382; input color UpperColor = clrDodgerBlue; input color MidColor = clrYellow; input color LowerColor = clrOrange; input int InpDepth=12; // Depth input int InpDeviation=5; // Deviation input int InpBackstep=3; // Backstep double FractalUp; double FractalDown; double ZigzagUp; double ZigzagDown; int RefreshEveryXMins = 0; string ccy; datetime prev_time; //----buffers //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //--- if (RefreshEveryXMins > 240) RefreshEveryXMins = 240; if (RefreshEveryXMins > 60 && RefreshEveryXMins < 240) RefreshEveryXMins = 60; if (RefreshEveryXMins > 30 && RefreshEveryXMins < 60) RefreshEveryXMins = 30; if (RefreshEveryXMins > 15 && RefreshEveryXMins < 30) RefreshEveryXMins = 15; if (RefreshEveryXMins > 5 && RefreshEveryXMins < 15) RefreshEveryXMins = 5; if (RefreshEveryXMins > 1 && RefreshEveryXMins < 5) RefreshEveryXMins = 1; RefreshRates(); EventSetMillisecondTimer(250); //--- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectsDeleteAll(0,OBJ_RECTANGLE); ObjectsDeleteAll(0,OBJ_TREND); ChartRedraw(); EventKillTimer(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- if (RefreshEveryXMins == 0) { ObjectsDeleteAll(0,OBJ_RECTANGLE); ObjectsDeleteAll(0,OBJ_TREND); ScreenDrawing(); } else { if(prev_time != iTime(ccy,RefreshEveryXMins,0)) { ObjectsDeleteAll(0,OBJ_RECTANGLE); ObjectsDeleteAll(0,OBJ_TREND); ScreenDrawing(); prev_time = iTime(ccy,RefreshEveryXMins,0); } } return(0); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_CHART_CHANGE) ScreenDrawing(); } int ScreenDrawing() { bool BullFractal=false; bool BearFractal=false; bool BullBox=false; bool BearBox=false; int shift=0; int shift1=0; int shift2=0; int shift3=0; int shiftline=0; int limit; int n; limit=CountedBars; for(shift=limit;shift>=0;shift--) { shift1=shift+1; shift2=shift+2; shift3=shift+3; FractalUp = iFractals(NULL, 0, MODE_UPPER,shift); FractalDown = iFractals(NULL, 0, MODE_LOWER,shift); ZigzagUp = iCustom(NULL,0,"ZigZag",InpDepth,InpDeviation,InpBackstep,1,shift); ZigzagDown = iCustom(NULL,0,"ZigZag",InpDepth,InpDeviation,InpBackstep,2,shift); //---Bullish Fractal if(FractalDown > 0 && Close[shift] < Open[shift]) BullFractal=true; else BullFractal=false; //---Bearish Fractal if(FractalUp > 0 && Close[shift] > Open[shift]) BearFractal=true; else BearFractal=false; //============================== if(BullFractal && ZigzagDown) { BullBox=true; } else { BullBox=false; } if(BearFractal && ZigzagUp) { BearBox=true; } else { BearBox=false; } //---------TEXT START if(BullFractal) { if(BullBox) { n++; CreateBox(n,Time[shift],High[shift],Time[shiftline],Low[shift],UpperColor); CreateLine(n,Time[shift],((High[shift]+Low[shift])/2),Time[shiftline],((High[shift]+Low[shift])/2),MidColor); } } if(BearFractal) { if(BearBox) { n++; CreateBox(n,Time[shift],High[shift],Time[shiftline],Low[shift],LowerColor); CreateLine(n,Time[shift],((High[shift]+Low[shift])/2),Time[shiftline],((High[shift]+Low[shift])/2),MidColor); } } } WindowRedraw(); //---- return(0); } //+------------------------------------------------------------------+ void CreateBox(int name,datetime dts, double price1,datetime dte,double price2, color clr) { ObjectCreate(name+"Box",OBJ_RECTANGLE,0,dts,price1,dte,price2,clr); ObjectSet(name+"Box", OBJPROP_STYLE, STYLE_SOLID); ObjectSet(name+"Box",OBJPROP_RAY_RIGHT,true); ObjectSet(name+"Box", OBJPROP_COLOR, clr); ObjectSet(name+"Box", OBJPROP_BACK, false); } //+------------------------------------------------------------------+ void CreateLine(int name,datetime dts, double price1,datetime dte,double price2, color clr) { ObjectCreate(name+"upln",OBJ_TREND,0,dts,price1,dte,price2,clr); ObjectSet(name+"upln",OBJPROP_STYLE,STYLE_DASHDOT); ObjectSet(name+"upln",OBJPROP_RAY,false); ObjectSet(name+"upln",OBJPROP_COLOR,clr); ObjectSet(name+"upln",OBJPROP_BACK,true); }