#------------------------------------------------------------------------------------------------------- # Smooth_Sailing vs Jitter_Zone Indicator # V 8.0 # Last update 09/02/2022 - Traderzen #------------------------------------------------------------------------------------------------------ declare lower; Input UseMTF = {"No", Default "Yes"}; Input MTF = AggregationPeriod.FIFTEEN_MIN; Input VolumeSmoothing = { Default "Yes", "No"}; Input Slope = {Default "Incremental" , "Aggregate"}; Input Bar_Segment = { Default "HL", "OC" }; Input fast = 2; #Average Slope. Input SuperSlow = 2; #Projection Curve Setting - Used for the divergence sensitivity. Input ShowJitterZone = { Default "Yes", "No"}; Input ShowLabel = { default "Yes", "No"}; Input ShowVerticalLine = {Default "yes", "No"}; Input ShowPPS = { Default "Yes", "No"}; Input Min_Theta_for_Mfactor = 25; # Buy/Short signal min avg angle. Input CommonRate = .97125; #Sensitivity for geometric progression def p_selected = if UseMTF == UseMTF."Yes" then MTF else getAggregationPeriod() ; def p = if Slope == Slope."Incremental" then GetAggregationPeriod() else if p_selected < getAggregationPeriod() then getAggregationPeriod() else p_selected; def mFactor = if UseMTF == UseMTF."Yes" and Slope == Slope."Incremental" then p_selected / getAggregationPeriod() else 1; def SlopeF = if UseMTF == UseMTF."Yes" and Slope == Slope."Incremental" then (mFactor+fast) else 1; def SlopeS = if UseMTF == UseMTF."Yes" and Slope == Slope."Incremental" then (mFactor+SuperSlow) else 1 ; Def averageType = AverageType.wilders; Def averageType2 = AverageType.Hull; def hiDiff = IF Bar_Segment == Bar_segment."HL" then high(period=p) - high(period=p)[1] else close(period=p) - close(period=p)[1]; def loDiff = If Bar_Segment == Bar_segment."HL" then low(period=p)[1] - low(period=p) else open(period=p)[1] - open(period=p); def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0; def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0; def ATR = MovingAverage(AverageType, TrueRange(high(period=p), close(period=p), low(period=p)), SlopeF); Plot DIplus = 100 * MovingAverage(averageType, plusDM, SlopeF) / if bar_segment == bar_segment."HL" then ATR else ATR*.5; Plot DIminus = 100 * MovingAverage(averageType, minusDM, SlopeF) / if bar_segment == bar_segment."HL" then ATR else ATR*.5; plot DX = DIplus - DIminus; Plot hz=0; #-- Real deal Buy signal angle calculation for MTF using geomatric progression. #-- For example: Do not trigger buy signal if then slope is less than 75 degrees for 1 min chart and 30 degrees for 30 min chart. def Theta = MIn_Theta_for_Mfactor*power(commonRate,Mfactor-1); ##-- Real deal scientific slope calculation using ArcTan formula. def ATanP = (ATan(DX/SlopeF) * (180 / Double.Pi)); # MTF support def v_1 = volume(period=p); def v_2 = volume; def w_1 = if ATanp > 0 and !(ATanP[1]> 0)then v_1 else if ATanP < 0 and !(Atanp[1] < 0 ) then v_1 else w_1[1] + v_1; def w_2 = if ATanp > 0 and !(ATanP[1]> 0) then v_2 else if ATanP < 0 and !(Atanp[1] < 0 ) then v_2 else w_2[1] + v_2; plot TDX; Switch (VolumeSmoothing){ Case "No" : TDX = w_1 * if atanp>0 then 1 else -1; Case "Yes" : TDX = w_2 * if atanp>0 then 1 else -1; } TDX.AssignValueColor( if ATanP >= ATanP[1] && ATanP > 0 and TDX >= TDX[1] then color.cyan else if ATanP <= ATanP[1]&& ATanP > 0 and TDX >= TDX[1] then color.light_green else if ATanP <= ATanP[1]&& ATanP < 0 and TDX <= TDX[1] then color.magenta else if ATanP >= ATanP[1]&& ATanP < 0 and TDX <= TDX[1] then color.Pink else Color.yellow ); TDX.setLineWeight(1); TDX.SetPaintingStrategy(PaintingStrategy.histogram); def ATANPMA = MovingAverage(averageType2, ATanP,mFactor); plot ATDX; Switch (VolumeSmoothing){ Case "No" : ATDX = w_1 * if atanpma>0 then 1 else -1; Case "Yes" : ATDX = w_2 * if atanpma>0 then 1 else -1; } Def JitterZone = if (ATanP>0 and ATanp[1]<0) or (ATanp<0 and ATanp[1]>0) then 1 else if (ATanPMA>0 and ATanpMA[1]<0) or (ATanpMA<0 and ATanpMA[1]>0) then 1 else 0; ATDX.AssignValueColor( if JitterZone then color.yellow else if (tdx==atdx and tdX > 0) then color.uptick else if (tdx==atdx and tdx<0) then color.downtick else color.yellow ); ATdx.setLineWeight(1); ATdx.SetPaintingStrategy(PaintingStrategy.LiNE); plot jz = if Jitterzone or (tdx!=atdx) then atdx else double.nan; jz.setpaintingstrategy(paintingStrategy.LINE_VS_Triangles); jz.setlineweight(3); jz.assignValueColor(color.yellow); atdx.setHiding(ShowJitterZone); jz.setHiding(ShowJitterZone); addlabel(if showLabel == ShowLabel."yes" then yes else no, if JitterZone then "Jitter Zone" else "Smooth Sail", if JitterZone then color.yellow else if tdx==atdx and tdx>0 then color.uptick else if tdx == atdx and tdx<0 then color.downtick else color.White ); def zone = if (tdx==atdx and tdX > 0) then -5 else if (tdx==atdx and tdx < 0) then 5 else if (TDX != atdx) then 0 else double.nan; plot ZoneLine = zone; Zoneline.assignValuecolor(if JitterZone then Color.Yellow else if zoneline == -5 then color.uptick else if zoneline == 5 then color.downTICK else color.White); zoneline.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES); HZ.AssignValueColor(color.gray); def up = if (ShowPPS == ShowPPS."Yes") then PPS().BuySignal else double.nan; def down = if (ShowPPS == ShowPPS."Yes") then PPS().SellSignal else double.nan; def upArrow = if up then 0 else double.NaN; def dnArrow = if down then 0 else double.NaN; plot PPSup = upArrow; Plot PPSdown = dnArrow; PPSup.SetPaintingStrategy(PaintingStrategy.ARROW_UP); PPSdown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); PPSup.SetLineWeight(3); PPSDown.SetLineWeight(3); PPSUp.AssignValueColor(Color.UpTick); PPSDown.AssignValueColor(Color.DownTick); DIminus.hide(); DIplus.hide(); DX.hide(); # -- Buy / Sell Indicator -- # def ATanP2 = (ATan(DX/Fast) * 180 / Double.Pi); def ATANPMA_JZ = MovingAverage(averageType2, ATanP2,SuperSlow); Def decision = if JitterZone == 0 and ATANP > 0 and ATANP[1] > 0 and ATANP > ATANP[1] and !(ATanp <= Theta and atanp >= -Theta) then 1 #BUY else if JitterZone == 0 and ATANPMA > 0 and ATANPMA[1] > 0 and ATANPMA > ATANPMA[1] and !(ATanp <= Theta and atanp >= -Theta) then 1 #BUY else if decision[1] == 1 and ATANP > ATANP[1] and !(ATanp <= Theta and atanp >= -Theta) then 5 #Buy More else if decision[1] == 1 and ATANPmA > ATANPMA[1] and !(ATanp <= Theta and atanp >= -Theta) then 5 #Buy More else if ATANP < 0 and ATANP[1] >= 0 and (decision[1] == 1 or decision[1] == 5) then 2 #Sell else if ATANPMA < 0 and ATANPMA[1] >= 0 and (decision[1] == 1 or decision[1] == 5) then 2 #Sell else if JitterZone == 0 and ATANP <= 0 and ATANP[1] < 0 and ATANP < ATANP[1] and !(ATanp <= Theta and atanp >= -Theta) then 3 #Short else if JitterZone == 0 and ATANPMA <= 0 and ATANPMA[1] < 0 and ATANPMA < ATANPMA[1] and !(ATanp <= Theta and atanp >= -Theta) then 3 #Short else if decision[1] == 3 and ATANP < ATANP[1] and !(ATanp <= Theta and atanp >= -Theta) then 6 #Short More else if decision[1] == 3 and ATANPMA < ATANPMA[1] and !(ATanp <= Theta and atanp >= -Theta) then 6 #Short More else if ATANP > 0 and ATANP[1] < 0 and (decision[1] == 3 or decision[1] == 6) then 4 #Cover else if ATANPMA > 0 and ATANPMA[1] < 0 and (decision[1] == 3 or decision[1] == 6) then 4 #Cover else decision[1] ; Def entry = if (!isNan(Decision) && (Decision != Decision[1])) && (Decision == 1 or Decision == 3) then close else entry[1]; def exit = if Decision != Decision[1] && (Decision == 2 or Decision == 4) then close else exit[1]; def result = if Decision != Decision[1] && (decision == 2 or decision ==4) then if decision == 2 then exit - entry else entry - exit else result[1]; AddVerticalLine(ShowVerticalLine == ShowVerticalLine."Yes" and Decision == 1 and Decision != Decision[1], "Buy:" + AsDollars(close), Color.Green, Curve.SHORT_DASH); AddVerticalLine(ShowVerticalLine == ShowVerticalLine."Yes" and Decision == 3 and Decision != Decision[1], "Short:"+AsDollars(close), Color.Light_ORANGE, Curve.SHORT_DASH); AddVerticalLine(ShowVerticalLine == ShowVerticalLine."Yes" and Decision == 2 and Decision != Decision[1], "Sell:"+ AsDollars(close), Color.Red, Curve.Short_Dash); AddVerticalLIne(ShowVerticalLine == ShowVerticalLine."Yes" and Decision == 4 and Decision !=Decision[1], "Cover:"+AsDollars(Close),Color.Light_green,Curve.Short_dash); AddLabel( if ShowLabel == ShowLabel."Yes" and (ATanpma <= 10 and atanpma >= -10) && !Jitterzone then yes else no , "Caution: Near JitterZone!", Color.yellow ); AddLabel( if ShowLabel == ShowLabel."Yes" and JitterZone then yes else no , "Caution: Divergence!", Color.yellow ); AddLabel( if ShowLabel == ShowLabel."Yes" and Decision != Decision[1] then yes else no, if decision == 1 or decision == 5 then "buy" else if decision == 2 then "sell ( " + result + " )" else if decision == 3 or decision == 6 then "short" else if decision == 4 then "Cover ( " + result + " )" else "*", if decision == 1 or decision == 5 then color.uptick else if decision == 2 then color.downtick else if decision == 3 or decision == 6 then color.light_orange else if decision == 4 then color.light_green else color.white); #Volume_Cloud input showVolband = no; input Daily_MovingAvgPeriod = 9; input Band_Percent_of_DMA_P_Vol = 5; def RefVol = If ShowVolBand then MovingAverage (3, Volume(period = AggregationPeriod.DAY) * (Band_percent_of_DMA_P_Vol/100), Daily_MovingAvgPeriod) else double.NaN; AddCloud (refVol,-1*refvol, color.light_gray,color.dark_gray, yes); # -- Happy Trading 9/2/2022 - Traderzen