//+------------------------------------------------------------------+ //| smLazyHedging TrendOsc_vX //+------------------------------------------------------------------+ #property copyright "Copyright 29.10.2020 SwingMan" //#property link "https://www.forexfactory.com/thread/1019505-dave-landrys-swing-trading" #property strict #property indicator_separate_window #property indicator_buffers 5 #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 3 #property indicator_width4 3 #property indicator_width5 3 #property indicator_color1 clrDodgerBlue #property indicator_color2 clrOrange #property indicator_color3 clrSilver #property indicator_color4 clrDodgerBlue #property indicator_color5 clrOrange #property indicator_level1 0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT //-- inputs //+------------------------------------------------------------------+ sinput string ____Averages="---------------------------------------"; input int Average_Highs_Period =10; input int Average_Lows_Period =8; input int Average_Shift =0; input ENUM_MA_METHOD Average_Method =MODE_SMA; //sinput string ____Periods="---------------------------------------"; //input int Period_Average_Fast =10; //input int Period_Average_Middle =20; //input int Period_Average_Slowly =30; //sinput string ____Methods="---------------------------------------"; //input ENUM_MA_METHOD Method_Average_Fast =MODE_SMA; //input ENUM_MA_METHOD Method_Average_Middle =MODE_EMA; //input ENUM_MA_METHOD Method_Average_Slowly =MODE_EMA; //sinput string ____Applied_Price="---------------------------------------"; //input ENUM_APPLIED_PRICE MovingAverage_Price=PRICE_MEDIAN; //input bool Show_Comment =true; //input string ____Drawing_Parameters="---------------------------------------"; //input bool Draw_Areas =true; //input color Color_UP_Trend =clrAliceBlue; //input color Color_DOWN_Trend=clrMistyRose; //+------------------------------------------------------------------+ //---- constants string CR="\n"; //string sObj="arProper_"; //---- buffers double avgHighs[],avgLows[]; double trendUP[],trendDN[]; //double trendNO[]; double circleUP[],circleDN[]; //---- variables int limit; int firstBarUP,lastBarUP; int firstBarDN,lastBarDN; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //IndicatorBuffers(8); //--- SetIndexBuffer(0,trendUP); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"UP-Trend"); SetIndexBuffer(1,trendDN); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(1,"DOWN-Trend"); //SetIndexBuffer(2,trendNO); //SetIndexStyle(2,DRAW_HISTOGRAM); //SetIndexLabel(2,"NULL-Trend"); SetIndexBuffer(3,circleUP); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,159); SetIndexLabel(3,NULL); SetIndexBuffer(4,circleDN); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,159); SetIndexLabel(4,NULL); //--- more buffers IndicatorBuffers(7); SetIndexBuffer(5,avgHighs); SetIndexBuffer(6,avgLows); //--- int firstBar=Average_Highs_Period; SetIndexDrawBegin(0,firstBar); SetIndexDrawBegin(1,firstBar); SetIndexDrawBegin(2,firstBar); SetIndexEmptyValue(0,EMPTY_VALUE); SetIndexEmptyValue(1,EMPTY_VALUE); SetIndexEmptyValue(2,EMPTY_VALUE); //--- string sName=WindowExpertName()+ " ("+ (string)Average_Highs_Period+","+(string)Average_Lows_Period+","+(string)Average_Shift+") "; IndicatorShortName(sName); //--- IndicatorDigits(0); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| 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 counted_bars=IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; if(counted_bars==0) limit-=Average_Highs_Period+1; //if(limit=0; i--) { avgHighs[i]=iMA(Symbol(),Period(),Average_Highs_Period,Average_Shift,Average_Method,PRICE_HIGH,i); avgLows[i] =iMA(Symbol(),Period(),Average_Lows_Period,Average_Shift,Average_Method,PRICE_LOW,i); } Get_TrendChannel(); //--- Histograms ------------------------------------------ for(int i=limit; i>=0; i--) { //--- UP-Trend if(trendUP[i]==1) { circleUP[i]=0; circleDN[i]=EMPTY_VALUE; } else if(trendDN[i]==-1) { circleUP[i]=EMPTY_VALUE; circleDN[i]=0; } else { circleUP[i]=EMPTY_VALUE; circleDN[i]=EMPTY_VALUE; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Get_TrendChannel() { bool bodyAbove=false; bool bodyBelow=false; for(int i=limit; i>=0; i--) { trendUP[i]=EMPTY_VALUE; trendDN[i]=EMPTY_VALUE; bodyAbove=(Open[i]>avgHighs[i] && Close[i]>avgHighs[i]); bodyBelow=(Open[i]