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.
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).
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();
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();
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.
#-------------------------------------------------------------------------------------------------------
# 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();