• Get $40 off VIP by signing up for a free account! Sign Up

Shark_Fins Indicator: B4 indicator meets Volume Waves For ThinkOrSwim

TraderZen

Member
Shark_Fins indicator is built on the foundation of B4 indicator (which relies on primary indicators for it's calculations), the visual aspects are Volume Wave like.

This indicator is not intended to replace the Smooth_Sail Indicator I have posted earlier.
Link to Smooth_Sail Indicator
It is different in many aspects. I will post a newer version of Smooth_Sail as well.

Shark_Fins uses B4 calculations which rely on primary indicators like MACD and Bollinger Bands. Smooth_Sail uses ArcTan for trend direction.

Shark Fins can be used at any time interval but it does not support multi-timeframe aggregations, and it only allows pre-determined parameters. Smooth_Sail is limited to a few time intervals, it supports multi-timeframe aggregations and its calculations can be tweaked.

V2 replaces V1 code.

V2 Changes:
Added option to set directional sensitivity of the Jitterzone high/low. (early exit vs stay in the trade longer).
Added option to turn alerts on/off.



qvf8y07.png


Code:
# SharkFins - 
# Alternative way of using B4 Indicator to Calculate Jitterzone
#
# V2: 
#    Added input to control directional sensitivity of then jitterzone
#    Addec option to turn alerts on/off 
# B4 Indicator
#
# Free for use. Header credits must be included when any form of the code included in this package is used.
# User assumes all risk. Author not responsible for errors or use of tool.
# Copyright (c) 2021 B4 Signals
#
# Get support at: https://b4signals.com
# Join us at: https://discord.gg/kD3pKE2CQd
#
#
# v3.0 - barbros / chuck - official release

declare lower;

input Directional_Sensitivity = {Default "high", "low"}; #hint Directional_Sensitivity: Yellow JitterZone directional sensitivity
input ShowMarketForecastLabel = yes;        #hint ShowMarketForecastLabel: Show the intermediate Market Forecast label
input ShowMACDBBLabel = yes;                #hint ShowMACDBBLabel: Show the MACDBB based Trend label
input ShowMACDBBCloud = no;                 #hint ShowMACDBBCloud: Show the MACDBB cloud shaded between BB
input ShowRSMCloud = no;                    #hint ShowRSMCloud: Show the vertical cloud based on RSM
input ShowHMALabel = yes;                   #hint ShowHMALabel: Show HUll Moving Average based Divergence label
input ShowSTOCHSCALPERSqueezeLabel = yes;   #hint ShowSTOCHSCALPERSqueezeLabel: Show Stochastic Scalper based squeeze label
input ShowSTOCHSCALPERSqueezeCloud = yes;   #hint ShowSTOCHSCALPERSqueezeCloud: Show Stochastic Scalper based squeeze cloud between BB
input ShowBullBearVerticalLines = yes;      #hint ShowBullBearVerticalLines: Show vertical lines for bullish or bearish direction
Input AlertMe = no;   # hint Turn Alerts on or off 


### Market Forecast

def pIntermediate = MarketForecast().Intermediate;

AddLabel(ShowMarketForecastLabel,
    "Market Forecast " +
    if pIntermediate >= 80 then "Bullish" else
    if pIntermediate <= 20 then "Bearish" else
    if pIntermediate > pIntermediate[1] then "Rising" else
    if pIntermediate < pIntermediate[1] then "Falling" else "Neutral",
    if pIntermediate >= 80 then Color.Cyan else
    if pIntermediate <= 20 then Color.Magenta else
    if pIntermediate > pIntermediate[1] then Color.Uptick else
    if pIntermediate < pIntermediate[1] then Color.DownTick else Color.Yellow #RB 
);

### MACDBB

input MACDBB_FastLength = 12;
input MACDBB_SlowLength = 26;
input MACDBB_BandLength = 15;
input MACDBB_NumDev = 1.0;

def MACDBB_Data = MACD(fastLength = MACDBB_FastLength, slowLength = MACDBB_SlowLength, MACDLength = 5);

plot MACDBB_Upper = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
                                             Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).UpperBand;
MACDBB_Upper.SetDefaultColor(Color.DownTick);
MACDBB_Upper.HideTitle();
MACDBB_Upper.HideBubble();

plot MACDBB_Lower = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
                                             Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).Lowerband;
MACDBB_Lower.SetDefaultColor(Color.Uptick);
MACDBB_Lower.HideTitle();
MACDBB_Lower.HideBubble();

plot MACDBB_Midline = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
                                               Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).MidLine;
MACDBB_Midline.SetDefaultColor(Color.Light_Orange);
MACDBB_Midline.SetStyle(Curve.FIRM);
MACDBB_MidLine.HideTitle();
MACDBB_MidLine.HideBubble();

plot MACDBB_Line = MACDBB_Data;
MACDBB_Line.AssignValueColor(
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line >= MACDBB_Upper then Color.Cyan
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line >= MACDBB_Upper then Color.Magenta
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line <= MACDBB_Lower then Color.Downtick else
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line <= MACDBB_Lower then Color.Magenta
    else Color.Yellow #RB
);
MACDBB_Line.SetLineWeight(1);

plot MACDBB_Dots = MACDBB_Data;
MACDBB_Dots.AssignValueColor(
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.UpTick
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.Cyan
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.DownTick
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.Magenta 
    else Color.Yellow #RB 
);
MACDBB_Dots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
MACDBB_Dots.SetLineWeight(1);
MACDBB_Dots.HideTitle();
MACDBB_Dots.HideBubble();

input MACDBB_CrossFromAboveAlert = {default "Zero", "Lower", "Middle", "Upper"};
input MACDBB_CrossFromBelowAlert = {default "Zero", "Lower", "Middle", "Upper"};

def MACDBB_CrossFromAboveVal = if MACDBB_CrossFromAboveAlert == MACDBB_CrossFromAboveAlert.Lower then MACDBB_Lower
                               else if MACDBB_CrossFromAboveAlert == MACDBB_CrossFromAboveAlert.Upper then MACDBB_Upper
                              else 0;
def MACDBB_CrossFromBelowVal = if MACDBB_CrossFromBelowAlert == MACDBB_CrossFromBelowAlert.Lower then MACDBB_Lower
                               else if MACDBB_CrossFromBelowAlert == MACDBB_CrossFromBelowAlert.Upper then MACDBB_Upper
                               else 0;

def MACDBB_Buy = MACDBB_Data > MACDBB_Upper;
def MACDBB_Sell = MACDBB_Data <= MACDBB_Lower;

AddLabel(ShowMACDBBLabel,
    "Trend " +
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then "Bullish"
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then "Bullish (reversing)"
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then "Bearish"
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then "Bearish (reversing)"
    else "Neutral",
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.upTick
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.Cyan
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.downTick
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.Magenta
    else Color.Yellow #RB
);

## RB Commented this block. 
#AddCloud(if ShowMACDBBCloud then MACDBB_Upper else MACDBB_Lower, MACDBB_Lower, Color.LIGHT_Orange);

### RSI/STOCASTIC/MACD CONFLUENCE COMBO

plot RSM_MACD_Diff = reference MACD("fast length" = 12, "slow length" = 26, "macd length" = 9).Diff;
RSM_MACD_Diff.SetDefaultColor(GetColor(5));
RSM_MACD_Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RSM_MACD_Diff.SetLineWeight(4);
RSM_MACD_Diff.DefineColor("Positive and Up", Color.upTick);
RSM_MACD_Diff.DefineColor("Positive and Down", Color.Cyan);
RSM_MACD_Diff.DefineColor("Negative and Down", Color.DownTick);
RSM_MACD_Diff.DefineColor("Negative and Up", Color.Magenta);
RSM_MACD_Diff.AssignValueColor(
    if RSM_MACD_Diff >= 0 then
        if RSM_MACD_Diff > RSM_MACD_Diff[1] then RSM_MACD_Diff.Color("Positive and Up") else RSM_MACD_Diff.Color("Positive and Down")
    else
        if RSM_MACD_Diff < RSM_MACD_Diff[1] then RSM_MACD_Diff.Color("Negative and Down") else RSM_MACD_Diff.Color("Negative and Up")
);

plot RSM_MACD_ZeroLine = 0;
RSM_MACD_ZeroLine.SetDefaultColor(Color.DARK_GRAY);
RSM_MACD_ZeroLine.HideTitle();
RSM_MACD_ZeroLine.HideBubble();

def RSM_RSI = reference RSI(length = 7).RSI;

def RSM_Stoch_Val = 100 * (close - lowest(low, 14)) / (highest(high, 14) - lowest(low, 14));
def RSM_StochSlowK = SimpleMovingAvg(SimpleMovingAvg(RSM_Stoch_Val,3),3);

def RSM_rsiGreen = RSM_RSI >= 50;
def RSM_rsiRed = RSM_RSI < 50;
def RSM_stochGreen = RSM_StochSlowK >= 50;
def RSM_stochRed = RSM_StochSlowK < 50;
def RSM_macdGreen = RSM_MACD_Diff >= 0;
def RSM_macdRed = RSM_MACD_Diff < 0;
def RSM_Buy = RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen;
def RSM_Sell = RSM_rsiRed and RSM_stochRed and RSM_macdRed;

# Shade areas based on criteria; adjust as needed
#  -- RB Commented this block 
#AddCloud(
#    if ShowRSMCloud and RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen then Double.POSITIVE_INFINITY else Double.NaN,
#    if ShowRSMCloud and RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen then Double.NEGATIVE_INFINITY else Double.NaN, Color.Light_green
#);
#AddCloud(
#    if ShowRSMCloud and RSM_rsiRed and RSM_stochRed and RSM_macdRed then Double.POSITIVE_INFINITY else Double.NaN,
#    if ShowRSMCloud and RSM_rsiRed and RSM_stochRed and RSM_macdRed then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED
#);

### Divergance
input HMA_Length = 55;
input HMA_Lookback = 2;

def HMA = HullMovingAvg(price = HL2, length = HMA_Length);
def HMA_delta = HMA[1] - HMA[HMA_Lookback + 1];
def HMA_delta_per_bar = HMA_delta / HMA_Lookback;
def HMA_next_bar = HMA[1] + HMA_delta_per_bar;
def HMA_concavity = if HMA > HMA_next_bar then 1 else -1;
def HMA_MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def HMA_MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;
def HMA_divergence = HMA - HMA_next_bar;

AddLabel(ShowHMALabel,
        "Divergence " +
        if HMA_concavity < 0 then
            if HMA_divergence[1] > HMA_divergence then "Bearish"
            else "Bearish (reversing)"
        else
            if HMA_divergence[1] < HMA_divergence then "Bullish"
            else "Bullish (reversing)",
        if HMA_concavity < 0 then
            if HMA_divergence[1] > HMA_divergence then Color.DownTick
            else Color.Magenta
        else
            if HMA_divergence[1] < HMA_divergence then Color.UpTick
            else Color.Cyan
);

### Stocastic Scalper

def STOCHSCALPER_oSS = (open[1] + close[1]) / 2;
def STOCHSCALPER_hSS = Max(high, close[1]);
def STOCHSCALPER_lSS = Min(low, close[1]);
def STOCHSCALPER_cSS = (STOCHSCALPER_oSS + STOCHSCALPER_hSS + STOCHSCALPER_lSS + close) / 4;

def STOCHSCALPER_mean = Average(STOCHSCALPER_cSS, 20);
def STOCHSCALPER_sd = StDev(STOCHSCALPER_cSS, 20);
def STOCHSCALPER_atr = Average(TrueRange(STOCHSCALPER_cSS, STOCHSCALPER_hSS, STOCHSCALPER_lSS), 20);
def STOCHSCALPER_squeeze = if (STOCHSCALPER_mean + (2 * STOCHSCALPER_sd)) < (STOCHSCALPER_mean + (1.5 * STOCHSCALPER_atr)) then yes else no;
def STOCHSCALPER_squeeze_signal = !STOCHSCALPER_squeeze[1] and STOCHSCALPER_squeeze;

## RB Commented this block
#AddCloud(if ShowSTOCHSCALPERSqueezeCloud and STOCHSCALPER_squeeze then MACDBB_Upper else Double.NaN,
#         if ShowSTOCHSCALPERSqueezeCloud and STOCHSCALPER_squeeze then MACDBB_Lower else Double.NaN, Color.YELLOW);
AddLabel(ShowSTOCHSCALPERSqueezeLabel, "Scalper Squeeze", if STOCHSCALPER_squeeze then Color.WHITE else Color.Yellow); #RB

### RSI IFT

def RSI_IFT_R = reference RSI(5, close) - 50;
def RSI_IFT_AvgRSI = MovingAverage(AverageType.Exponential,RSI_IFT_R,9);
def RSI_IFT_InverseRSI = (Power(Double.E, 2 * RSI_IFT_AvgRSI) - 1) / (Power(Double.E, 2 * RSI_IFT_AvgRSI) + 1);
def RSI_IFT_Direction = if BarNumber() == 0 then 0
                        else if (RSI_IFT_InverseRSI[1] > 0) and (RSI_IFT_InverseRSI < 0) then -1
                        else if (RSI_IFT_InverseRSI > 0) and (RSI_IFT_InverseRSI[1] < 0) then 1
                        else RSI_IFT_Direction[1];

### Fibonacci SuperTrend

input FST_Length = 11;
input FST_Retrace = 23.6;
input FST_UseHighLow = yes;

def FST_h = if FST_UseHighLow then high else close;
def FST_l = if FST_UseHighLow then low else close;
def FST_minL = Lowest(FST_l, FST_Length);
def FST_maxH = Highest(FST_h, FST_Length);

def FST_hh = if FST_h > FST_maxH[1] then FST_h else FST_hh[1];
def FST_ll = if FST_l < FST_minL[1] then FST_l else FST_ll[1];
def FST_trend = if FST_h > FST_maxH[1] then 1 else if FST_l < FST_minL[1] then -1 else FST_trend[1];
def FST_Direction = if BarNumber() == 0 then 0
                    else if FST_trend != 1 then -1
                    else if FST_trend == 1 then 1
                    else FST_Direction[1];

### Bar Color

input BarColor = { default  "x", "None", "RSM", "FibonacciSuperTrend" };    #hint BarColor: Paint bars with RSM (Default -RB) or Fibonacci SuperTrend direction


    AssignPriceColor(
        if BarColor == BarColor.FibonacciSuperTrend then
            if FST_trend == 1 then Color.UpTick else Color.DownTick
        else if BarColor == BarColor.RSM then
            if RSM_Buy then Color.UpTick
            else if RSM_Sell then Color.DownTick
            else Color.Yellow #RB
        else if barColor == Barcolor.x then Color.Current 
        else Color.Current# RB
    );


### Strategy
input BullBear_Include_FST = yes;       #hint BullBear_Include_FST: Include Fibonacci SuperTrend in the vertical line strategy
input BullBear_Include_RSI_IFT = yes;   #hint BullBear_Include_RSI_IFT: Include RSI IFT in the vertical line strategy

def BullBear_Buy = (!BullBear_Include_FST or FST_Direction == 1) and
                   (!BullBear_Include_RSI_IFT or RSI_IFT_Direction == 1);
def BullBear_Sell = (!BullBear_Include_FST or FST_Direction == -1) and
                    (!BullBear_Include_RSI_IFT or RSI_IFT_Direction == -1);

## - RB commented this block. 
AddVerticalLine(ShowBullBearVerticalLines and BullBear_Buy and !BullBear_Buy[1],
                AsDollars(close),
                Color.UpTick, Curve.SHORT_DASH);
AddVerticalLine(ShowBullBearVerticalLines and BullBear_Sell and !BullBear_Sell[1],
                AsDollars(close),
                Color.DownTick, Curve.SHORT_DASH);

def Strategy_Buy = BullBear_Buy and MACDBB_Buy and RSM_Buy;
def Strategy_Sell = BullBear_Sell and MACDBB_Sell and RSM_Sell;
def Strategy_BuySignal = Strategy_Buy and !Strategy_Buy[1];
def Strategy_SellSignal = Strategy_Sell and !Strategy_Sell[1];

plot BuyArrow = if Strategy_BuySignal then 0 else Double.NaN;
BuyArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuyArrow.SetDefaultColor(Color.WHITE);
BuyArrow.HideTitle();
BuyArrow.HideBubble();

plot SellArrow = if Strategy_SellSignal then 0 else Double.NaN;
SellArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellArrow.SetDefaultColor(Color.WHITE);
SellArrow.HideTitle();
SellArrow.HideBubble();

### Alerts

Alert(Alertme and Strategy_BuySignal, "Long Entry", Alert.BAR, Sound.DING);
Alert(Alertme and Strategy_SellSignal, "Short Entry", Alert.BAR, Sound.DING);
Alert(Alertme and (MACDBB_Line crosses above MACDBB_CrossFromAboveVal), "MACDBB Crossed Up", Alert.BAR, Sound.DING);
Alert(alertme and (MACDBB_Line crosses below MACDBB_CrossFromBelowVal), "MACDBB Crossed Down", Alert.BAR, Sound.DING);
Alert(alertme and (STOCHSCALPER_squeeze_signal), "Scalper Squeeze", Alert.BAR, Sound.DING);


### Hide all plots  
MACDBB_Upper.hide();
MACDBB_Lower.hide();
MACDBB_Midline.hide();
MACDBB_Line.hide();
MACDBB_Dots.Hide();

RSM_MACD_Diff.Hide();
RSM_MACD_ZeroLine.Hide();


BuyArrow.Hide();
SellArrow.Hide();

### --- Draw ShartkFin  -- 

Input UseMTF = {default "Yes", "no"};
Input MTF = { "1M", "5M", Default "15M", "30M"};

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 p_selected < getAggregationPeriod() then getAggregationPeriod() 
        else p_selected;

def Hz =0; 
Plot p_Hz = hz;

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


Def Decision =      if MACDBB_Line >= MACDBB_Upper then if MACDBB_Line >= MACDBB_Line[1] then 2 else 1 #Cyan
               else if MACDBB_Line >= MACDBB_Upper  then if MACDBB_Line < MACDBB_Line[1] then 1 else 1 #Green
               else if MACDBB_Line <= MACDBB_Lower then if MACDBB_Line <= MACDBB_Line[1] then -2 else -1 #Magenta 
               else if MACDBB_Line <= MACDBB_Lower then if MACDBB_Line > MACDBB_Line[1]  then -1 else  -1 #red 
               else if macdBB_Line >= MACDBB_Line[1] then  3 #Yellow 
               else if macdBB_Line < macdBB_Line[1] then  -3 #Yellow
               else decision[1];#Yellow

def w_1 = if Decision > 0 and !(decision[1] > 0)  
         then v_1
        else if Decision < 0 and !(Decision[1] < 0 )
         then v_1
        else w_1[1] + v_1;


plot TDX;
Def Dir = if Strategy_Buy then 1 else if Strategy_Sell then -1 else 1 ; # -- Older style RB 
def Dir2 =  if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then 1 
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then 1
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then -1
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then -1
    else if MACDBB_Line > MACDBB_Line[1] then 1 
    else -1;


TDX = w_1 * (if Directional_Sensitivity == Directional_Sensitivity."high" then dir2 else dir);

TDX.AssignValueColor(

if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.green
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.green
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.red
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.red
    else Color.Yellow
);
TDX.setLineWeight(1);
TDX.SetPaintingStrategy(PaintingStrategy.histogram);
 
Last edited:

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

Funny to find this. I've been using Momentum waves and B4 with great success already and stumbled upon your post. Really works well in this bear market. Will have to try this since it seems more cohesive. Thanks for posting this. Cheers.
 
Is it possible to get this to work on a tick chart? I use tick 233 & 333 charts

This is a MTF script. It overlays a higher aggregation volume calculation onto a lower timeframe.
Because a tick charts x and y-axis only use data related to price and volume lots. It has no comprehension of intraday time. So MTF studies cannot be used on tick charts.
I4AbMjt.png

Here is a version that removes the MTF volume calculation to allow this script to be utilized on tick charts:
Ruby:
# modified tick chart version --  removes MTF volume calculation  @merryday 2/2023
# SharkFins -
# Alternative way of using B4 Indicator to Calculate Jitterzone
#
# V2:
#    Added input to control directional sensitivity of then jitterzone
#    Addec option to turn alerts on/off
# B4 Indicator
#
# Free for use. Header credits must be included when any form of the code included in this package is used.
# User assumes all risk. Author not responsible for errors or use of tool.
# Copyright (c) 2021 B4 Signals
#
# Get support at: https://b4signals.com
# Join us at: https://discord.gg/kD3pKE2CQd
#
#
# v3.0 - barbros / chuck - official release

declare lower;

input Directional_Sensitivity = {Default "high", "low"}; #hint Directional_Sensitivity: Yellow JitterZone directional sensitivity
input ShowMarketForecastLabel = yes;        #hint ShowMarketForecastLabel: Show the intermediate Market Forecast label
input ShowMACDBBLabel = yes;                #hint ShowMACDBBLabel: Show the MACDBB based Trend label
input ShowMACDBBCloud = no;                 #hint ShowMACDBBCloud: Show the MACDBB cloud shaded between BB
input ShowRSMCloud = no;                    #hint ShowRSMCloud: Show the vertical cloud based on RSM
input ShowHMALabel = yes;                   #hint ShowHMALabel: Show HUll Moving Average based Divergence label
input ShowSTOCHSCALPERSqueezeLabel = yes;   #hint ShowSTOCHSCALPERSqueezeLabel: Show Stochastic Scalper based squeeze label
input ShowSTOCHSCALPERSqueezeCloud = yes;   #hint ShowSTOCHSCALPERSqueezeCloud: Show Stochastic Scalper based squeeze cloud between BB
input ShowBullBearVerticalLines = yes;      #hint ShowBullBearVerticalLines: Show vertical lines for bullish or bearish direction
Input AlertMe = no;   # hint Turn Alerts on or off


### Market Forecast

def pIntermediate = MarketForecast().Intermediate;

AddLabel(ShowMarketForecastLabel,
    "Market Forecast " +
    if pIntermediate >= 80 then "Bullish" else
    if pIntermediate <= 20 then "Bearish" else
    if pIntermediate > pIntermediate[1] then "Rising" else
    if pIntermediate < pIntermediate[1] then "Falling" else "Neutral",
    if pIntermediate >= 80 then Color.Cyan else
    if pIntermediate <= 20 then Color.Magenta else
    if pIntermediate > pIntermediate[1] then Color.Uptick else
    if pIntermediate < pIntermediate[1] then Color.DownTick else Color.Yellow #RB
);

### MACDBB

input MACDBB_FastLength = 12;
input MACDBB_SlowLength = 26;
input MACDBB_BandLength = 15;
input MACDBB_NumDev = 1.0;

def MACDBB_Data = MACD(fastLength = MACDBB_FastLength, slowLength = MACDBB_SlowLength, MACDLength = 5);

plot MACDBB_Upper = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
                                             Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).UpperBand;
MACDBB_Upper.SetDefaultColor(Color.DownTick);
MACDBB_Upper.HideTitle();
MACDBB_Upper.HideBubble();

plot MACDBB_Lower = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
                                             Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).Lowerband;
MACDBB_Lower.SetDefaultColor(Color.Uptick);
MACDBB_Lower.HideTitle();
MACDBB_Lower.HideBubble();

plot MACDBB_Midline = reference BollingerBands(price = MACDBB_Data, length = MACDBB_BandLength,
                                               Num_Dev_Dn = -MACDBB_NumDev, Num_Dev_Up = MACDBB_NumDev).MidLine;
MACDBB_Midline.SetDefaultColor(Color.Light_Orange);
MACDBB_Midline.SetStyle(Curve.FIRM);
MACDBB_MidLine.HideTitle();
MACDBB_MidLine.HideBubble();

plot MACDBB_Line = MACDBB_Data;
MACDBB_Line.AssignValueColor(
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line >= MACDBB_Upper then Color.Cyan
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line >= MACDBB_Upper then Color.Magenta
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line <= MACDBB_Lower then Color.Downtick else
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line <= MACDBB_Lower then Color.Magenta
    else Color.Yellow #RB
);
MACDBB_Line.SetLineWeight(1);

plot MACDBB_Dots = MACDBB_Data;
MACDBB_Dots.AssignValueColor(
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.UpTick
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.Cyan
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.DownTick
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.Magenta
    else Color.Yellow #RB
);
MACDBB_Dots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
MACDBB_Dots.SetLineWeight(1);
MACDBB_Dots.HideTitle();
MACDBB_Dots.HideBubble();

input MACDBB_CrossFromAboveAlert = {default "Zero", "Lower", "Middle", "Upper"};
input MACDBB_CrossFromBelowAlert = {default "Zero", "Lower", "Middle", "Upper"};

def MACDBB_CrossFromAboveVal = if MACDBB_CrossFromAboveAlert == MACDBB_CrossFromAboveAlert.Lower then MACDBB_Lower
                               else if MACDBB_CrossFromAboveAlert == MACDBB_CrossFromAboveAlert.Upper then MACDBB_Upper
                              else 0;
def MACDBB_CrossFromBelowVal = if MACDBB_CrossFromBelowAlert == MACDBB_CrossFromBelowAlert.Lower then MACDBB_Lower
                               else if MACDBB_CrossFromBelowAlert == MACDBB_CrossFromBelowAlert.Upper then MACDBB_Upper
                               else 0;

def MACDBB_Buy = MACDBB_Data > MACDBB_Upper;
def MACDBB_Sell = MACDBB_Data <= MACDBB_Lower;

AddLabel(ShowMACDBBLabel,
    "Trend " +
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then "Bullish"
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then "Bullish (reversing)"
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then "Bearish"
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then "Bearish (reversing)"
    else "Neutral",
    if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.upTick
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.Cyan
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.downTick
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.Magenta
    else Color.Yellow #RB
);

## RB Commented this block.
#AddCloud(if ShowMACDBBCloud then MACDBB_Upper else MACDBB_Lower, MACDBB_Lower, Color.LIGHT_Orange);

### RSI/STOCASTIC/MACD CONFLUENCE COMBO

plot RSM_MACD_Diff = reference MACD("fast length" = 12, "slow length" = 26, "macd length" = 9).Diff;
RSM_MACD_Diff.SetDefaultColor(GetColor(5));
RSM_MACD_Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RSM_MACD_Diff.SetLineWeight(4);
RSM_MACD_Diff.DefineColor("Positive and Up", Color.upTick);
RSM_MACD_Diff.DefineColor("Positive and Down", Color.Cyan);
RSM_MACD_Diff.DefineColor("Negative and Down", Color.DownTick);
RSM_MACD_Diff.DefineColor("Negative and Up", Color.Magenta);
RSM_MACD_Diff.AssignValueColor(
    if RSM_MACD_Diff >= 0 then
        if RSM_MACD_Diff > RSM_MACD_Diff[1] then RSM_MACD_Diff.Color("Positive and Up") else RSM_MACD_Diff.Color("Positive and Down")
    else
        if RSM_MACD_Diff < RSM_MACD_Diff[1] then RSM_MACD_Diff.Color("Negative and Down") else RSM_MACD_Diff.Color("Negative and Up")
);

plot RSM_MACD_ZeroLine = 0;
RSM_MACD_ZeroLine.SetDefaultColor(Color.DARK_GRAY);
RSM_MACD_ZeroLine.HideTitle();
RSM_MACD_ZeroLine.HideBubble();

def RSM_RSI = reference RSI(length = 7).RSI;

def RSM_Stoch_Val = 100 * (close - lowest(low, 14)) / (highest(high, 14) - lowest(low, 14));
def RSM_StochSlowK = SimpleMovingAvg(SimpleMovingAvg(RSM_Stoch_Val,3),3);

def RSM_rsiGreen = RSM_RSI >= 50;
def RSM_rsiRed = RSM_RSI < 50;
def RSM_stochGreen = RSM_StochSlowK >= 50;
def RSM_stochRed = RSM_StochSlowK < 50;
def RSM_macdGreen = RSM_MACD_Diff >= 0;
def RSM_macdRed = RSM_MACD_Diff < 0;
def RSM_Buy = RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen;
def RSM_Sell = RSM_rsiRed and RSM_stochRed and RSM_macdRed;

# Shade areas based on criteria; adjust as needed
#  -- RB Commented this block
#AddCloud(
#    if ShowRSMCloud and RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen then Double.POSITIVE_INFINITY else Double.NaN,
#    if ShowRSMCloud and RSM_rsiGreen and RSM_stochGreen and RSM_macdGreen then Double.NEGATIVE_INFINITY else Double.NaN, Color.Light_green
#);
#AddCloud(
#    if ShowRSMCloud and RSM_rsiRed and RSM_stochRed and RSM_macdRed then Double.POSITIVE_INFINITY else Double.NaN,
#    if ShowRSMCloud and RSM_rsiRed and RSM_stochRed and RSM_macdRed then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED
#);

### Divergance
input HMA_Length = 55;
input HMA_Lookback = 2;

def HMA = HullMovingAvg(price = HL2, length = HMA_Length);
def HMA_delta = HMA[1] - HMA[HMA_Lookback + 1];
def HMA_delta_per_bar = HMA_delta / HMA_Lookback;
def HMA_next_bar = HMA[1] + HMA_delta_per_bar;
def HMA_concavity = if HMA > HMA_next_bar then 1 else -1;
def HMA_MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def HMA_MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.NaN;
def HMA_divergence = HMA - HMA_next_bar;

AddLabel(ShowHMALabel,
        "Divergence " +
        if HMA_concavity < 0 then
            if HMA_divergence[1] > HMA_divergence then "Bearish"
            else "Bearish (reversing)"
        else
            if HMA_divergence[1] < HMA_divergence then "Bullish"
            else "Bullish (reversing)",
        if HMA_concavity < 0 then
            if HMA_divergence[1] > HMA_divergence then Color.DownTick
            else Color.Magenta
        else
            if HMA_divergence[1] < HMA_divergence then Color.UpTick
            else Color.Cyan
);

### Stocastic Scalper

def STOCHSCALPER_oSS = (open[1] + close[1]) / 2;
def STOCHSCALPER_hSS = Max(high, close[1]);
def STOCHSCALPER_lSS = Min(low, close[1]);
def STOCHSCALPER_cSS = (STOCHSCALPER_oSS + STOCHSCALPER_hSS + STOCHSCALPER_lSS + close) / 4;

def STOCHSCALPER_mean = Average(STOCHSCALPER_cSS, 20);
def STOCHSCALPER_sd = StDev(STOCHSCALPER_cSS, 20);
def STOCHSCALPER_atr = Average(TrueRange(STOCHSCALPER_cSS, STOCHSCALPER_hSS, STOCHSCALPER_lSS), 20);
def STOCHSCALPER_squeeze = if (STOCHSCALPER_mean + (2 * STOCHSCALPER_sd)) < (STOCHSCALPER_mean + (1.5 * STOCHSCALPER_atr)) then yes else no;
def STOCHSCALPER_squeeze_signal = !STOCHSCALPER_squeeze[1] and STOCHSCALPER_squeeze;

## RB Commented this block
#AddCloud(if ShowSTOCHSCALPERSqueezeCloud and STOCHSCALPER_squeeze then MACDBB_Upper else Double.NaN,
#         if ShowSTOCHSCALPERSqueezeCloud and STOCHSCALPER_squeeze then MACDBB_Lower else Double.NaN, Color.YELLOW);
AddLabel(ShowSTOCHSCALPERSqueezeLabel, "Scalper Squeeze", if STOCHSCALPER_squeeze then Color.WHITE else Color.Yellow); #RB

### RSI IFT

def RSI_IFT_R = reference RSI(5, close) - 50;
def RSI_IFT_AvgRSI = MovingAverage(AverageType.Exponential,RSI_IFT_R,9);
def RSI_IFT_InverseRSI = (Power(Double.E, 2 * RSI_IFT_AvgRSI) - 1) / (Power(Double.E, 2 * RSI_IFT_AvgRSI) + 1);
def RSI_IFT_Direction = if BarNumber() == 0 then 0
                        else if (RSI_IFT_InverseRSI[1] > 0) and (RSI_IFT_InverseRSI < 0) then -1
                        else if (RSI_IFT_InverseRSI > 0) and (RSI_IFT_InverseRSI[1] < 0) then 1
                        else RSI_IFT_Direction[1];

### Fibonacci SuperTrend

input FST_Length = 11;
input FST_Retrace = 23.6;
input FST_UseHighLow = yes;

def FST_h = if FST_UseHighLow then high else close;
def FST_l = if FST_UseHighLow then low else close;
def FST_minL = Lowest(FST_l, FST_Length);
def FST_maxH = Highest(FST_h, FST_Length);

def FST_hh = if FST_h > FST_maxH[1] then FST_h else FST_hh[1];
def FST_ll = if FST_l < FST_minL[1] then FST_l else FST_ll[1];
def FST_trend = if FST_h > FST_maxH[1] then 1 else if FST_l < FST_minL[1] then -1 else FST_trend[1];
def FST_Direction = if BarNumber() == 0 then 0
                    else if FST_trend != 1 then -1
                    else if FST_trend == 1 then 1
                    else FST_Direction[1];

### Bar Color

input BarColor = { default  "x", "None", "RSM", "FibonacciSuperTrend" };    #hint BarColor: Paint bars with RSM (Default -RB) or Fibonacci SuperTrend direction


    AssignPriceColor(
        if BarColor == BarColor.FibonacciSuperTrend then
            if FST_trend == 1 then Color.UpTick else Color.DownTick
        else if BarColor == BarColor.RSM then
            if RSM_Buy then Color.UpTick
            else if RSM_Sell then Color.DownTick
            else Color.Yellow #RB
        else if barColor == Barcolor.x then Color.Current
        else Color.Current# RB
    );


### Strategy
input BullBear_Include_FST = yes;       #hint BullBear_Include_FST: Include Fibonacci SuperTrend in the vertical line strategy
input BullBear_Include_RSI_IFT = yes;   #hint BullBear_Include_RSI_IFT: Include RSI IFT in the vertical line strategy

def BullBear_Buy = (!BullBear_Include_FST or FST_Direction == 1) and
                   (!BullBear_Include_RSI_IFT or RSI_IFT_Direction == 1);
def BullBear_Sell = (!BullBear_Include_FST or FST_Direction == -1) and
                    (!BullBear_Include_RSI_IFT or RSI_IFT_Direction == -1);

## - RB commented this block.
AddVerticalLine(ShowBullBearVerticalLines and BullBear_Buy and !BullBear_Buy[1],
                AsDollars(close),
                Color.UpTick, Curve.SHORT_DASH);
AddVerticalLine(ShowBullBearVerticalLines and BullBear_Sell and !BullBear_Sell[1],
                AsDollars(close),
                Color.DownTick, Curve.SHORT_DASH);

def Strategy_Buy = BullBear_Buy and MACDBB_Buy and RSM_Buy;
def Strategy_Sell = BullBear_Sell and MACDBB_Sell and RSM_Sell;
def Strategy_BuySignal = Strategy_Buy and !Strategy_Buy[1];
def Strategy_SellSignal = Strategy_Sell and !Strategy_Sell[1];

plot BuyArrow = if Strategy_BuySignal then 0 else Double.NaN;
BuyArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuyArrow.SetDefaultColor(Color.WHITE);
BuyArrow.HideTitle();
BuyArrow.HideBubble();

plot SellArrow = if Strategy_SellSignal then 0 else Double.NaN;
SellArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellArrow.SetDefaultColor(Color.WHITE);
SellArrow.HideTitle();
SellArrow.HideBubble();

### Alerts

Alert(Alertme and Strategy_BuySignal, "Long Entry", Alert.BAR, Sound.DING);
Alert(Alertme and Strategy_SellSignal, "Short Entry", Alert.BAR, Sound.DING);
Alert(Alertme and (MACDBB_Line crosses above MACDBB_CrossFromAboveVal), "MACDBB Crossed Up", Alert.BAR, Sound.DING);
Alert(alertme and (MACDBB_Line crosses below MACDBB_CrossFromBelowVal), "MACDBB Crossed Down", Alert.BAR, Sound.DING);
Alert(alertme and (STOCHSCALPER_squeeze_signal), "Scalper Squeeze", Alert.BAR, Sound.DING);


### Hide all plots
MACDBB_Upper.hide();
MACDBB_Lower.hide();
MACDBB_Midline.hide();
MACDBB_Line.hide();
MACDBB_Dots.Hide();

RSM_MACD_Diff.Hide();
RSM_MACD_ZeroLine.Hide();


BuyArrow.Hide();
SellArrow.Hide();

### --- Draw ShartkFin  --


def Hz =0;
Plot p_Hz = hz;

def v_1 = volume;
def v_2 = volume;


Def Decision =      if MACDBB_Line >= MACDBB_Upper then if MACDBB_Line >= MACDBB_Line[1] then 2 else 1 #Cyan
               else if MACDBB_Line >= MACDBB_Upper  then if MACDBB_Line < MACDBB_Line[1] then 1 else 1 #Green
               else if MACDBB_Line <= MACDBB_Lower then if MACDBB_Line <= MACDBB_Line[1] then -2 else -1 #Magenta
               else if MACDBB_Line <= MACDBB_Lower then if MACDBB_Line > MACDBB_Line[1]  then -1 else  -1 #red
               else if macdBB_Line >= MACDBB_Line[1] then  3 #Yellow
               else if macdBB_Line < macdBB_Line[1] then  -3 #Yellow
               else decision[1];#Yellow

def w_1 = if Decision > 0 and !(decision[1] > 0)
         then v_1
        else if Decision < 0 and !(Decision[1] < 0 )
         then v_1
        else w_1[1] + v_1;


plot TDX;
Def Dir = if Strategy_Buy then 1 else if Strategy_Sell then -1 else 1 ; # -- Older style RB
def Dir2 =  if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then 1
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then 1
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then -1
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then -1
    else if MACDBB_Line > MACDBB_Line[1] then 1
    else -1;


TDX = w_1 * (if Directional_Sensitivity == Directional_Sensitivity."high" then dir2 else dir);

TDX.AssignValueColor(

if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.green
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line > MACDBB_Upper then Color.green
    else if MACDBB_Line < MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.red
    else if MACDBB_Line > MACDBB_Line[1] and MACDBB_Line < MACDBB_Lower then Color.red
    else Color.Yellow
);
TDX.setLineWeight(1);
TDX.SetPaintingStrategy(PaintingStrategy.histogram);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
130 Online
Create Post

Similar threads

Similar threads

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