Repaints Smooth-Sailing vs Jitter-Zone Indicator for Scalping For ThinkOrSwim

Repaints

TraderZen

Member
V8 is the latest version
More efficient code.
Code footprint - below 200 lines of instructions.

------------------------
V7 - First Code block below (on the top of this post)
V7 feaures-
* Added customizable cloud to indicate strong/weak trends zone.
* Vertical lines replace bubbles.
* Better default configuation.

Goal:
To help scalp choppy charts while avoiding jittery zones.
This indicator is inspired by the Directional Movement Index (DMI) and Volume Wave.
Arc Tangent is used to calculate the slope of the Directional Deltas.
Optionally combined with PPS.

Please read the top comment section in the code block before using.


UBomZSK.jpg

Code:
#-------------------------------------------------------------------------------------------------------
# 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

V6 Features -

* Adjustable and more precise, less number of Buy/Sell or Short/Cover Signal Triggering based on Geometric progression formula.
* Better default settings.
* Misc. Cosmetic improvements and additional prompts.
* Entry and Exit prices and results of the suggested last trade.
* Best used on a 1 min chart with 15M / 30M setting. (prefer using two instances of 15m, 30m one below the other, if possible).



NxyrRPz.jpg


V6 Code ---
Code:
#-------------------------------------------------------------------------------------------------------
# Smooth_Sail
#-------------------------------------------------------------------------------------------------------
# Description: Smooth_Sailing vs Jitter_Zone indicator
# Scalping Indicator for smaller time frame trading.
#     *    Indicates directional smooth sailing and Jitterzone warning.
#     *    Indicates Momentum.
#     *    Jitterzone is indicated by the yellow divergent line and yellow dots at the base of the bars.
#     *    Cyan and Magenta histogram bars indicate aggressive in the direction move.
# V2 -
#    * MultiTimeFrame (MTF) Feature.
#    ** Imp: If the TimeFrame selected is less than the TimeFrame of the Chart then the TimeFrame of the Chart is used.
#    ** PPS uses the Chart's time Frame.
#    ** ArcTan uses the MTF angle based on the slope calculation selection.
# V3 -
#    VolumeSmoothing - If VolumeSmoothing is ON then Adds volume of the current bar to the total_volume in MTF calulcation.
#                      Else if VolumeSmoothing if OFF then Waits for the total volume to be updated based on the selected MTF TimeFrame.
#                      V4- Volumesmoothing auto applies for incremental scopes.
#  V4 -
#    * - Choose between High-Low or Open-Close for slope calculation
#    * - Choose between Incremental or Aggregate slope calculation for MTF
#        Incremental setting uses the adjusted average slope of the bars from current timeframe for the duration of MTF
#        Aggregate setting uses the slope of the bars from MTF timeframe
#        Volumesmooothing applies automatically for incremental slopes.
# V5 -
#     * BUY/Sell and Short/Cover Signals
#     * Defaults values set for most scalping scenarios.
#
# V6 -
#    * Adjustable Buy/Sell Signal Triggering based on Geometric progression formula.
#    * Misc. Cosmetic improvements and additional prompts.
#    * Entry and Exit prices and results of the suggested last trade.
#
#
#
# Observaations:
#    * Best suited on a 1 min chart with 15M and 30 min settings.
#    * Use two instances of different timeframes (say 15M and 30M) one below the other for trade decisions.
#    A PivotPoint in the JitterZone coinsiding with MACD crossover is a good sign of a possible reversal.
#    A long Jitterzone is a channel - generally followed by a breakout - Specially near Day VWAP.
#    A PivotPoint in the Smooth Sailing Zone is indicative of a possibly longer trend.
#------------------------------------------------------------------------------------------------------


declare lower;

Input UseMTF = {"No", Default "Yes"};
Input MTF = { "1M", "5M", Default "15M", "30M"};
Input VolumeSmoothing = { Default "Yes", "No"};
Input Slope = {Default "Incremental" , "Aggregate"};
Input Bar_Segment = {Default "HL", "OC" };
Input fast = 2; #Average Slope.
Input SuperSlow = 5; #Projection Curve Setting - Used for the divergence sensitivity.
Input ShowJitterZone = { Default "Yes", "No"};
Input ShowLabel = { default "Yes", "No"};
Input Showbubble = {Default "yes", "No"};
Input ShowPPS = { Default "Yes", "No"};
Input Max_Theta_for_Min_Mfactor = 70; # Buy/Short signal max angle.
Input CommonRate = .969; #Sensitivity for geometric progression

def p_selected = if UseMTF == UseMTF."Yes" and MTF == MTF."1M" then AggregationPeriod.Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."5M" then AggregationPeriod.Five_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."15M" then AggregationPeriod.Fifteen_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."30M" then AggregationPeriod.Thirty_Min
                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 = fast  + ( if UseMTF == UseMTF."Yes" and Slope == Slope."Incremental" then mFactor/fast else 0 );
def SlopeS = SuperSlow + ( if UseMTF == UseMTF."Yes" and Slope == Slope."Incremental" then mFactor/(SuperSlow) else 0 );

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) / ATR;
Plot DIminus = 100 * MovingAverage(averageType, minusDM, SlopeF) / ATR;
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 = Max_Theta_for_Min_Mfactor*power(commonRate,Mfactor-1);

##-- Real deal scientific slope calculation using ArcTan formula.
#def ATanP = (ATan(DX/fast) * 180 / Double.Pi);
def ATanP = (ATan(DX/SlopeF) * 180 / Double.Pi); # MTF support


def v_1 = volume(period=p);
def v_2 = volume;

#AddLabel(if showLabel == ShowLabel."yes" then yes else no,
#         "MFT=" + UseMTF + " TF=" + MTF + " Period=" + P/60000  + "M Bar=" + Bar_Segment + "Slp="
#         + if slope == slope."Incremental" then "Inc" else "Agg",       
#         color.white);

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.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 if ATanP >= ATanP[1]&& ATanP > 0 then color.cyan
    else Color.yellow
);
TDX.setLineWeight(1);
TDX.SetPaintingStrategy(PaintingStrategy.histogram);

def ATANPMA = MovingAverage(averageType2, ATanP,mFactor);
#AddLabel(yes, "ATanPMA " + ATanPMA + "ATanPMA[1] " + ATanPMA[1], color.white);
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.White
                    );

ATdx.setLineWeight(1);
ATdx.SetPaintingStrategy(PaintingStrategy.LiNE);

atdx.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(if JitterZone then Color.Yellow else if zoneline == -5 then color.uptick else if zoneline == 5 then color.downTICK else color.White);
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(2);
PPSDown.SetLineWeight(2);
PPSUp.AssignValueColor(Color.UpTick);
PPSDown.AssignValueColor(Color.DownTick);

DIminus.hide();
DIplus.hide();
DX.hide();


#Addlabel(yes, atanp + " " + atanp[1] +  " " + atanpma +  " " + atanpma[1], color.white);

##############################
# -- 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 open 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];


AddChartBubble( Showbubble == ShowBubble."Yes" and Decision == 1 and Decision != Decision[1]
               , 0, open , Color.uptick,no );
AddChartBubble( Showbubble == ShowBubble."Yes" and Decision == 5 and Decision != Decision[1]
                , 0, "+" , Color.uptick,no );

AddChartBubble( Showbubble == ShowBubble."Yes" and Decision == 3 and Decision != Decision[1]
                , 0, open, color.LIGHT_ORANGE, no );
AddChartBubble( Showbubble == ShowBubble."Yes" and Decision == 6 and Decision != Decision[1]
               , 0, "+" , Color.LIGHT_ORANGE, no);

AddChartBubble( Showbubble == ShowBubble."Yes" and Decision == 2 and Decision != Decision[1], atanpma, Close , Color.downtick);
AddChartBubble( Showbubble == ShowBubble."Yes" and Decision == 4 and Decision != Decision[1], atanpma, close, color.Light_green);

AddChartBubble (Showbubble == ShowBubble."Yes" and ((ATanpma_JZ < 0 and atanpma_JZ[1]> 0) or (ATanpma_JZ[1] < 0 and atanpma_JZ>0 )), atanpma, "!", Color.yellow, no );

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);

#addlabel(if showLabel == ShowLabel."Yes" then yes else no, "Entry " + entry + " Exit " + exit + " Result " + result, color.white);
#AddLabel(yes, "Mfactor " + mfactor + " CR " + commonRate  + " Theta " + theta , color.white);


---------------------------- OLD Versions -- V1 to V4 -----------

Code:
#-------------------------------------------------------------------------------------------------------
# Smooth_Sailing vs Jitter_Zone indicator
# Scalping Indicator for smaller time frame trading.
#     *    Indicates directional smooth sailing and Jitterzone warning.
#     *    Indicates Momentum.
#     *    Jitterzone is indicated by the yellow divergent line and yellow dots at the base of the bars.
#     *    Cyan and Magenta histogram bars indicate aggressive in the direction move.
# Observaations:
#    A PivotPoint in the JitterZone coinsiding with MACD crossover is a good sign of a possible reversal.
#    A long Jitterzone is a channel - generally followed by a breakout - Specially near Day VWAP.
#    A PivotPoint in the Smooth Sailing Zone is indicative of a possibly longer trend.
#------------------------------------------------------------------------------------------------------


declare lower;

Input fast = 2; #Average Slope.
Input SuperSlow = 5; #Projection Curve Setting - Used for the divergence sensitivity.

Input ShowJitterZone = { Default "Yes", "No"};
Input ShowLabel = { default "Yes", "No"};
Input ShowPPS = { Default "Yes", "No"};

Def averageType = AverageType.wilders;
Def averageType2 = AverageType.hull;
def hiDiff = high - high[1];
def loDiff = low[1] - low;

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, close, low), fast);
Plot "DI+" = 100 * MovingAverage(averageType, plusDM, fast) / ATR;
Plot "DI-" = 100 * MovingAverage(averageType, minusDM, fast) / ATR;

plot DX = "DI+" - "DI-";

Plot hz=0;

##-- Real deal scientific slope calculation using ArcTan formula.
def ATanP = (ATan(DX/fast) * 180 / Double.Pi);

def v = volume;

def w = if ATanp > 0  and !(ATanP[1]> 0)
        then v
        else if ATanP < 0 and !(Atanp[1] < 0 )
        then v
        else w[1] + v;

plot TDX = w * if atanp>0 then 1 else -1;

TDX.AssignValueColor(

    if ATanP >= ATanP[1] && ATanP > 0 then color.cyan
    else if ATanP < ATanP[1]&& ATanP > 0 and  ATanP < TDX[1] then color.green
    else if ATanP < ATanP[1]&& ATanP < 0 then color.magenta
    else if ATanP >= ATanP[1]&& ATanP < 0 and ATanP > TDX[1] then color.pink
    else if ATanP >= ATanP[1]&& ATanP > 0 then color.cyan
    else Color.white
);
TDX.setLineWeight(1);
TDX.SetPaintingStrategy(PaintingStrategy.histogram);

def ATANPMA = MovingAverage(averageType2, ATanP, Superslow);
plot ATDX =  W * 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.White
                    );

ATdx.setLineWeight(1);
ATdx.SetPaintingStrategy(PaintingStrategy.LiNE_vs_Triangles);

atdx.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(if JitterZone then Color.Yellow else if zoneline == -5 then color.uptick else if zoneline == 5 then color.downTICK else color.White);
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(2);
PPSDown.SetLineWeight(2);
PPSUp.AssignValueColor(Color.UpTick);
PPSDown.AssignValueColor(Color.DownTick);

"DI-".hide();
"DI+".hide();
DX.hide();




sI6x1DN.png


clJCqBp.png



V2 -- with Multi-Time-Frame Support

Code:
#-------------------------------------------------------------------------------------------------------
# Smooth_Sailing vs Jitter_Zone indicator
# Scalping Indicator for smaller time frame trading.
#     *    Indicates directional smooth sailing and Jitterzone warning.
#     *    Indicates Momentum.
#     *    Jitterzone is indicated by the yellow divergent line and yellow dots at the base of the bars.
#     *    Cyan and Magenta histogram bars indicate aggressive in the direction move.
# V2 -
#    * MultiTimeFrame Feature.
#    ** Imp: If the TimeFrame selected is less than the TimeFrame of the Chart then the TimeFrame of the Chart is used.
#    ** PPS uses the Chart's time Frame.
#    ** ArcTan uses the MTF angle
# Observaations:
#    A PivotPoint in the JitterZone coinsiding with MACD crossover is a good sign of a possible reversal.
#    A long Jitterzone is a channel - generally followed by a breakout - Specially near Day VWAP.
#    A PivotPoint in the Smooth Sailing Zone is indicative of a possibly longer trend.
#------------------------------------------------------------------------------------------------------


declare lower;

Input fast = 2; #Average Slope.
Input SuperSlow = 5; #Projection Curve Setting - Used for the divergence sensitivity.

Input ShowJitterZone = { Default "Yes", "No"};
Input ShowLabel = { default "Yes", "No"};
Input ShowPPS = { Default "Yes", "No"};
Input UseMTF = {Default "No", "Yes"};
Input MTF = {Default "1_Min", "5_Min", "15_Min", "30_Min"};

def p_selected = if UseMTF == UseMTF."Yes" and MTF == MTF."1_Min" then AggregationPeriod.Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."5_Min" then AggregationPeriod.Five_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."15_Min" then AggregationPeriod.Fifteen_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."30_Min" then AggregationPeriod.Thirty_Min
                else getAggregationPeriod() ;

def p = if p_selected < getAggregationPeriod() then getAggregationPeriod() else p_selected;

Def averageType = AverageType.wilders;
Def averageType2 = AverageType.hull;
def hiDiff = high(period=p) - high(period=p)[1];
def loDiff = low(period=p)[1] - low(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)), fast);
Plot "DI+" = 100 * MovingAverage(averageType, plusDM, fast) / ATR;
Plot "DI-" = 100 * MovingAverage(averageType, minusDM, fast) / ATR;

plot DX = "DI+" - "DI-";

Plot hz=0;

##-- Real deal scientific slope calculation using ArcTan formula.
def ATanP = (ATan(DX/fast) * 180 / Double.Pi);

def v  = volume(period=p);

AddLabel(if showLabel == ShowLabel."yes" then yes else no, "UseMFT= " + UseMTF + ", MTF= " + MTF + ", Period= " + P , color.white);

def w = if ATanp > 0  and !(ATanP[1]> 0)
        then v
        else if ATanP < 0 and !(Atanp[1] < 0 )
        then v
        else w[1] + v;

plot TDX = w * if atanp>0 then 1 else -1;

TDX.AssignValueColor(

    if ATanP >= ATanP[1] && ATanP > 0 then color.cyan
    else if ATanP < ATanP[1]&& ATanP > 0 and  ATanP < TDX[1] then color.green
    else if ATanP < ATanP[1]&& ATanP < 0 then color.magenta
    else if ATanP >= ATanP[1]&& ATanP < 0 and ATanP > TDX[1] then color.pink
    else if ATanP >= ATanP[1]&& ATanP > 0 then color.cyan
    else Color.white
);
TDX.setLineWeight(1);
TDX.SetPaintingStrategy(PaintingStrategy.histogram);

def ATANPMA = MovingAverage(averageType2, ATanP, Superslow);
plot ATDX =  W * 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.White
                    );

ATdx.setLineWeight(1);
ATdx.SetPaintingStrategy(PaintingStrategy.LiNE_vs_Triangles);

atdx.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(if JitterZone then Color.Yellow else if zoneline == -5 then color.uptick else if zoneline == 5 then color.downTICK else color.White);
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(2);
PPSDown.SetLineWeight(2);
PPSUp.AssignValueColor(Color.UpTick);
PPSDown.AssignValueColor(Color.DownTick);

"DI-".hide();
"DI+".hide();
DX.hide();
3MvSt2k.png

V3 - Volume Smoothing for Multi Time Frame Histograms.

Code:
#-------------------------------------------------------------------------------------------------------
# Smooth_Sailing vs Jitter_Zone indicator
# Scalping Indicator for smaller time frame trading.
#     *    Indicates directional smooth sailing and Jitterzone warning.
#     *    Indicates Momentum.
#     *    Jitterzone is indicated by the yellow divergent line and yellow dots at the base of the bars.
#     *    Cyan and Magenta histogram bars indicate aggressive in the direction move.
# V2 -
#    * MultiTimeFrame Feature.
#    ** Imp: If the TimeFrame selected is less than the TimeFrame of the Chart then the TimeFrame of the Chart is used.
#    ** PPS uses the Chart's time Frame.
#    ** ArcTan uses the MTF angle
# V3 -
#    VolumeSmoothing - If VolumeSmoothing is ON then Adds volume of the current bar to the total_volume in MTF calulcation.
#                      Else if VolumeSmoothing if OFF then Waits for the total volume to be updated based on the selected MTF TimeFrame.
# Observaations:
#    A PivotPoint in the JitterZone coinsiding with MACD crossover is a good sign of a possible reversal.
#    A long Jitterzone is a channel - generally followed by a breakout - Specially near Day VWAP.
#    A PivotPoint in the Smooth Sailing Zone is indicative of a possibly longer trend.
#------------------------------------------------------------------------------------------------------


declare lower;

Input fast = 2; #Average Slope.
Input SuperSlow = 5; #Projection Curve Setting - Used for the divergence sensitivity.

Input ShowJitterZone = { Default "Yes", "No"};
Input ShowLabel = { default "Yes", "No"};
Input ShowPPS = { Default "Yes", "No"};
Input UseMTF = {Default "No", "Yes"};
Input MTF = {Default "1_Min", "5_Min", "15_Min", "30_Min"};
Input VolumeSmoothing = { "Yes", default "No"};


def p_selected = if UseMTF == UseMTF."Yes" and MTF == MTF."1_Min" then AggregationPeriod.Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."5_Min" then AggregationPeriod.Five_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."15_Min" then AggregationPeriod.Fifteen_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."30_Min" then AggregationPeriod.Thirty_Min
                else getAggregationPeriod() ;

def p = if p_selected < getAggregationPeriod() then getAggregationPeriod() else p_selected;

Def averageType = AverageType.wilders;
Def averageType2 = AverageType.hull;
def hiDiff = high(period=p) - high(period=p)[1];
def loDiff = low(period=p)[1] - low(period=p);
#def hiDiff = close(period=p) - close(period=p)[1];
#def loDiff = 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)), fast);
Plot "DI+" = 100 * MovingAverage(averageType, plusDM, fast) / ATR;
Plot "DI-" = 100 * MovingAverage(averageType, minusDM, fast) / ATR;

plot DX = "DI+" - "DI-";

Plot hz=0;

##-- Real deal scientific slope calculation using ArcTan formula.
def ATanP = (ATan(DX/fast) * 180 / Double.Pi);

def v_1 = volume(period=p);
def v_2 = volume;

AddLabel(if showLabel == ShowLabel."yes" then yes else no, "UseMFT= " + UseMTF + ", MTF= " + MTF + ", Period= " + P/60000  + " Min", color.white);
AddLabel(if showLabel == ShowLabel."yes" then yes else no, "VolumeSmoothing " + VolumeSmoothing, color.white);


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 then color.cyan
    else if ATanP < ATanP[1]&& ATanP > 0 and  ATanP < TDX[1] then color.green
    else if ATanP < ATanP[1]&& ATanP < 0 then color.magenta
    else if ATanP >= ATanP[1]&& ATanP < 0 and ATanP > TDX[1] then color.pink
    else if ATanP >= ATanP[1]&& ATanP > 0 then color.cyan
    else Color.white
);
TDX.setLineWeight(1);
TDX.SetPaintingStrategy(PaintingStrategy.histogram);

def ATANPMA = MovingAverage(averageType2, ATanP, Superslow);
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.White
                    );

ATdx.setLineWeight(1);
ATdx.SetPaintingStrategy(PaintingStrategy.LiNE_vs_Triangles);

atdx.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(if JitterZone then Color.Yellow else if zoneline == -5 then color.uptick else if zoneline == 5 then color.downTICK else color.White);
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(2);
PPSDown.SetLineWeight(2);
PPSUp.AssignValueColor(Color.UpTick);
PPSDown.AssignValueColor(Color.DownTick);

"DI-".hide();
"DI+".hide();
DX.hide();

V4 is now available -
Recommended settings -
1) On the 1 Min chart choose MTF = 5_Min for higher sensitivity [quick exits] OR MTF=15_Min to stay in the trade longer.

2) Use Bar_Segment = OpenClose for very choppy stocks to further adjust sensitivity.

ShiCNYU.jpg

#-------------------------------------------------------------------------------------------------------
# Smooth_Sailing vs Jitter_Zone indicator
# Scalping Indicator for smaller time frame trading.
# * Indicates directional smooth sailing and Jitterzone warning.
# * Indicates Momentum.
# * Jitterzone is indicated by the yellow divergent line and yellow dots at the base of the bars.
# * Cyan and Magenta histogram bars indicate aggressive in the direction move.
# V2 -
# * MultiTimeFrame (MTF) Feature.
# ** Imp: If the TimeFrame selected is less than the TimeFrame of the Chart then the TimeFrame of the Chart is used.
# ** PPS uses the Chart's time Frame.
# ** ArcTan uses the MTF angle based on the slope calculation selection.
# V3 -
# VolumeSmoothing - If VolumeSmoothing is ON then Adds volume of the current bar to the total_volume in MTF calulcation.
# Else if VolumeSmoothing if OFF then Waits for the total volume to be updated based on the selected MTF TimeFrame.
# V4- Volumesmoothing auto applies for incremental scopes.
# V4 -
# * - Choose between High-Low or Open-Close for slope calculation
# * - Choose between Incremental or Aggregate slope calculation for MTF
# Incremental setting uses the adjusted average slope of the bars from current timeframe for the duration of MTF
# Aggregate setting uses the slope of the bars from MTF timeframe
# Volumesmooothing applies automatically for incremental slopes.
#
# Observaations:
# A PivotPoint in the JitterZone coinsiding with MACD crossover is a good sign of a possible reversal.
# A long Jitterzone is a channel - generally followed by a breakout - Specially near Day VWAP.
# A PivotPoint in the Smooth Sailing Zone is indicative of a possibly longer trend.
#------------------------------------------------------------------------------------------------------

Code:
#-------------------------------------------------------------------------------------------------------
# Smooth_Sailing vs Jitter_Zone indicator
# Scalping Indicator for smaller time frame trading.
#     *    Indicates directional smooth sailing and Jitterzone warning.
#     *    Indicates Momentum.
#     *    Jitterzone is indicated by the yellow divergent line and yellow dots at the base of the bars.
#     *    Cyan and Magenta histogram bars indicate aggressive in the direction move.
# V2 -
#    * MultiTimeFrame (MTF) Feature.
#    ** Imp: If the TimeFrame selected is less than the TimeFrame of the Chart then the TimeFrame of the Chart is used.
#    ** PPS uses the Chart's time Frame.
#    ** ArcTan uses the MTF angle based on the slope calculation selection.
# V3 -
#    VolumeSmoothing - If VolumeSmoothing is ON then Adds volume of the current bar to the total_volume in MTF calulcation.
#                      Else if VolumeSmoothing if OFF then Waits for the total volume to be updated based on the selected MTF TimeFrame.
#                      V4- Volumesmoothing auto applies for incremental scopes.
#  V4 -
#    * - Choose between High-Low or Open-Close for slope calculation
#    * - Choose between Incremental or Aggregate slope calculation for MTF
#        Incremental setting uses the adjusted average slope of the bars from current timeframe for the duration of MTF
#        Aggregate setting uses the slope of the bars from MTF timeframe
#        Volumesmooothing applies automatically for incremental slopes.
#
# Observaations:
#    A PivotPoint in the JitterZone coinsiding with MACD crossover is a good sign of a possible reversal.
#    A long Jitterzone is a channel - generally followed by a breakout - Specially near Day VWAP.
#    A PivotPoint in the Smooth Sailing Zone is indicative of a possibly longer trend.
#------------------------------------------------------------------------------------------------------


declare lower;

Input fast = 2; #Average Slope.
Input SuperSlow = 5; #Projection Curve Setting - Used for the divergence sensitivity.

Input ShowJitterZone = { Default "Yes", "No"};
Input ShowLabel = { default "Yes", "No"};
Input ShowPPS = { Default "Yes", "No"};
Input UseMTF = {Default "No", "Yes"};
Input MTF = {Default "1_Min", "5_Min", "15_Min", "30_Min"};
Input VolumeSmoothing = { "Yes", default "No"};
Input Slope = {Default "Incremental" , "Aggregate"};
Input Bar_Segment = {Default "HiLo", "OpenClose" };

def p_selected = if UseMTF == UseMTF."Yes" and MTF == MTF."1_Min" then AggregationPeriod.Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."5_Min" then AggregationPeriod.Five_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."15_Min" then AggregationPeriod.Fifteen_Min
                else if UseMTF == UseMTF."Yes" and MTF == MTF."30_Min" then AggregationPeriod.Thirty_Min
                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 = fast  + ( if UseMTF == UseMTF."Yes" and Slope == Slope."Incremental" then mFactor/fast else 0 );
def SlopeS = SuperSlow + ( if UseMTF == UseMTF."Yes" and Slope == Slope."Incremental" then mFactor*(fast/SuperSlow) else 0 );

Def averageType = AverageType.wilders;
Def averageType2 = AverageType.hull;
def hiDiff = IF Bar_Segment == Bar_segment."HiLo" then high(period=p) - high(period=p)[1] else  close(period=p) - close(period=p)[1];
def loDiff = If Bar_Segment == Bar_segment."HiLo" then low(period=p)[1] - low(period=p) else open(period=p)[1] - open(period=p);
#def hiDiff = close(period=p) - close(period=p)[1];
#def loDiff = 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 "DI+" = 100 * MovingAverage(averageType, plusDM, SlopeF) / ATR;
Plot "DI-" = 100 * MovingAverage(averageType, minusDM, SlopeF) / ATR;

plot DX = "DI+" - "DI-";

Plot hz=0;

##-- Real deal scientific slope calculation using ArcTan formula.
def ATanP = (ATan(DX/fast) * 180 / Double.Pi);

def v_1 = volume(period=p);
def v_2 = volume;

AddLabel(if showLabel == ShowLabel."yes" then yes else no, "UseMFT= " + UseMTF + ", MTF= " + MTF + ", Period= " + P/60000  + " Min", color.white);
#AddLabel(if showLabel == ShowLabel."yes" then yes else no, "VolumeSmoothing " + VolumeSmoothing, color.white);


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 then color.cyan
    else if ATanP < ATanP[1]&& ATanP > 0 and  ATanP < TDX[1] then color.green
    else if ATanP < ATanP[1]&& ATanP < 0 then color.magenta
    else if ATanP >= ATanP[1]&& ATanP < 0 and ATanP > TDX[1] then color.pink
    else if ATanP >= ATanP[1]&& ATanP > 0 then color.cyan
    else Color.white
);
TDX.setLineWeight(1);
TDX.SetPaintingStrategy(PaintingStrategy.histogram);

def ATANPMA = MovingAverage(averageType2, ATanP, If UseMTF == UseMTF."Yes" then 3 else SlopeS );
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.White
                    );

ATdx.setLineWeight(1);
ATdx.SetPaintingStrategy(PaintingStrategy.LiNE_vs_Triangles);

atdx.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(if JitterZone then Color.Yellow else if zoneline == -5 then color.uptick else if zoneline == 5 then color.downTICK else color.White);
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(2);
PPSDown.SetLineWeight(2);
PPSUp.AssignValueColor(Color.UpTick);
PPSDown.AssignValueColor(Color.DownTick);

"DI-".hide();
"DI+".hide();
DX.hide();
 
Last edited:
It will be interesting to attempt that - given the fact that volume is also involved in the calculations. I'll mess with it and post the results.
input agg = AggregationPeriod.FIFTEEN_MIN ;
def volume= volume(period = agg);
 
Can this be made into a MTF version thanks
New V2 code is added int the first post of this thread.
Multi Time Frame support is now available. Please read the Comment section [Top block] in the code before using.

Multi Time Frame support can be turned ON or OFF.

Select a timeframe higher than the Chart's time frame.
A new image is added to the post.
An image with two instances of the code shows the MTF and Default histograms.
 
V3 - Added Volume Smoothing option for MTF.

input agg = AggregationPeriod.FIFTEEN_MIN ;
def volume= volume(period = agg);
Definitely!

What I meant to say was - there will sometimes be a visual disjoint in case of the MTF - The angle of the slopes need to be calculated based on the chosen time frame instead of the chart's current (lower) timeframe.

Also - One may choose to add the bar volume for the lower time frame bar; or else/otherwise wait to add the volume(period=MTF_Period).
So, I added this option.

V3 - Updated : Back-tested, kept the High-Low. Sentiment matters.
Thanks for the feedback.

V4 is now available.

V5 is now available

V6 is now available.
 
Hi TraderZen,
Do you have a scanner for your Jitter Zone? Something to scan on an up or down arrow?
Your indicator is great!!!
Thanks
Brian
 
Hi TraderZen,
Do you have a scanner for your Jitter Zone? Something to scan on an up or down arrow?
Your indicator is great!!!
Thanks
Brian
Hi Brian-

Thank you for your kind words! IMHO, there is room for many improvements. Constructive criticism is welcome.

I do not have such a scanner ready, but it is possible - I'll publish something over the weekend (hopefully).
On which time-frame(s) do you intend to use such a scanner?

I plan to share the next version of the indicator soon.
 
Lately I have been trading options, a daily chart would be great.
I use ADX with DMI and I find your indicator makes calls before my ADX manual call.
BUT
Your calls have taught me that they work earlier. Your arrows are spot on!! Have you back tested your calls on this? I think this is a winner.
Thank you
Brian
 
Lately I have been trading options, a daily chart would be great.
I use ADX with DMI and I find your indicator makes calls before my ADX manual call.
BUT
Your calls have taught me that they work earlier. Your arrows are spot on!! Have you back tested your calls on this? I think this is a winner.
Thank you
Brian

z9LJMRh.jpg

Brian,
The Arrow is not my code. It is a pre-canned indicator called PPS (Persons Pivot Study). You can add it to any chart from Studies list. Look into Pivot points to know more about them.
That said - I have posted a new indicator today - MTF Anticipate Price Level Indicator - it is based on similar calculations and I find it very useful for options trading - combined with Smooth_Sail and SharkFins.
My ArcTan and Geometric Progressions based calculations coincides with the PPS for a good reason though - I calculate angle between the candles - when the angle exceeds the threshold the direction changes - PPS does the same but instead it uses price level to conclude the same - most of the times they coincide.

if PPS turns on in the JitterZone - yes that is a good early sign but overall trend momentum matters - so MTF Anticipated Price Level Indicator is a good tool for that.

Hopefully I'll get a chance to work on the scanner soon.
 
z9LJMRh.jpg

Brian,
The Arrow is not my code. It is a pre-canned indicator called PPS (Persons Pivot Study). You can add it to any chart from Studies list. Look into Pivot points to know more about them.
That said - I have posted a new indicator today - MTF Anticipate Price Level Indicator - it is based on similar calculations and I find it very useful for options trading - combined with Smooth_Sail and SharkFins.
My ArcTan and Geometric Progressions based calculations coincides with the PPS for a good reason though - I calculate angle between the candles - when the angle exceeds the threshold the direction changes - PPS does the same but instead it uses price level to conclude the same - most of the times they coincide.

if PPS turns on in the JitterZone - yes that is a good early sign but overall trend momentum matters - so MTF Anticipated Price Level Indicator is a good tool for that.

Hopefully I'll get a chance to work on the scanner soon.
OK, no rush, I can do a scan on PPS and then use your indicator to follow along. I agree, you need momentum, but this is an early heads up, which is great.
Thanks again :cool:(y)
 
https://postimg.cc/xkXFycgs any way to get an area shaded with pct above below zero line that we can identify peaks above below shaded are?
Easily! but without much effort - It cannot be a pure percent though, as this indicator is not an oscillator. We rely on cumulative Vol. Therefore, such a band can be based on a percent of average relative volume.
So if a fin's cumulative vol crosses above 5% of say 9DMA Vol level, it is in a strong trend. I'll add it.
 
V8 is now available.
V8 replaces V7.
New code available at the top of the first post.
More efficient code - Smaller codebase.
Thank you for taking the time to create this indicator. I'm currently using the first version as it seems to work well for spotting divergences on the Renko chart. My question is if there is a way I could make the current version work for Renko as well. If there's a block of code I could remove or a simple alteration I could make (I'm not a skilled Thinkscripter by any stretch so the simpler the better), that would be very helpful as I would like to take full advantage of your latest innovations. Thanks again for all your work!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
511 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top