Three Step Future-Trend [BigBeluga] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
mod note: Schwab does not update InertiaALL in real time; therefore this script will lag.
https://usethinkscript.com/threads/...in-real-time-in-thinkorswim.8794/#post-116082

TrADAaN.png

Author Message:
Three Step Future-Trend by BigBeluga is a forward-looking trend analysis tool designed to project potential future price direction based on historical periods. This indicator aggregates data from three consecutive periods, using price averages and delta volume analysis to forecast trend movement and visualize it on the chart with a projected trend line and volume metrics.
https://www.tradingview.com/script/ay15DZnZ-Three-Step-Future-Trend-BigBeluga/


CODE:

CSS:
# Indicator for TOS
#// © BigBeluga
# indicator('Three Step Future-Trend [BigBeluga]', overlay = true)
# Converted by Sam4Cok@Samer800    - 12/2024

input FutureTrendPlotType = {Default "Line", "Candels", "Don't Show"};
input labelOptions = {Default "Label & Bubble", "Label Only", "Bubble Only", "Don't Show"};
input src = close;
input period = 25; #, 'Period')
input highLowLength = 50;

def na = Double.NaN;
def last = isNaN(close);
def line = FutureTrendPlotType == FutureTrendPlotType."Line";
def candle = FutureTrendPlotType == FutureTrendPlotType."Candels";
def lab = labelOptions == labelOptions."Label Only" or labelOptions == labelOptions."Label & Bubble";
def bub = labelOptions == labelOptions."Bubble Only" or labelOptions == labelOptions."Label & Bubble";
#-- color
DefineGlobalColor("up", CreateColor(0, 230, 118));
DefineGlobalColor("dn", CreateColor(212, 37, 131));
DefineGlobalColor("dup", CreateColor(0, 112, 58));
DefineGlobalColor("ddn", CreateColor(112, 20, 69));

def hh = highest(high, highLowLength);
def ll = lowest(low, highLowLength);

def volUp = if close > open then volume else 0;
def volDn = if close > open then 0 else volume;
def delta_vol = volUp - volDn;
def delta1 = sum(delta_vol, period);
def delta2 = sum(delta_vol, period)[period];
def delta3 = sum(delta_vol, period)[period * 2];
def total1 = sum(volume, period);
def total2 = sum(volume, period)[period];
def total3 = sum(volume, period)[period * 2];

def col1 = highestAll(inertiaAll(delta1, 2));
def col2 = highestAll(inertiaAll(delta2, 2));
def col3 = highestAll(inertiaAll(delta3, 2));

def hhL1 = inertiaAll(highestAll(inertiaAll(hh, 2)), period);
def llL1 = inertiaAll(lowestAll(inertiaAll(ll, 2)), period);
def hhL2 = inertiaAll(highestAll(inertiaAll(hh[period], 2)), period*2);
def llL2 = inertiaAll(lowestAll(inertiaAll(ll[period], 2)), period*2);
def hhL3 = inertiaAll(highestAll(inertiaAll(hh[period*2], 2)), period*3);
def llL3 = inertiaAll(lowestAll(inertiaAll(ll[period*2], 2)), period*3);

#  HH - LL
plot hhLine1 = hhL1;
plot llLine1 = llL1;
plot hhLine2 = if isNaN(hhL1) then hhL2 else na;
plot llLine2 = if isNaN(llL1) then llL2 else na;
plot hhLine3 = if (isNaN(hhL1) and isNaN(hhL2)) then hhL3 else na;
plot llLine3 = if (isNaN(llL1) and isNaN(llL2)) then llL3 else na;

hhLine1.SetLineWeight(2);
llLine1.SetLineWeight(2);
hhLine2.SetLineWeight(2);
llLine2.SetLineWeight(2);
hhLine3.SetLineWeight(2);
llLine3.SetLineWeight(2);
hhLine1.AssignValueColor(if col1 > 0 then GlobalColor("up") else GlobalColor("dn"));
hhLine2.AssignValueColor(if col2 > 0 then GlobalColor("up") else GlobalColor("dn"));
hhLine3.AssignValueColor(if col3 > 0 then GlobalColor("up") else GlobalColor("dn"));
llLine1.AssignValueColor(if col1 > 0 then GlobalColor("up") else GlobalColor("dn"));
llLine2.AssignValueColor(if col2 > 0 then GlobalColor("up") else GlobalColor("dn"));
llLine3.AssignValueColor(if col3 > 0 then GlobalColor("up") else GlobalColor("dn"));

AddCloud(if col1 > 0 then hhLine1 else na, llLine1, GlobalColor("dup"));
AddCloud(if col2 > 0 then hhLine2 else na, llLine2, GlobalColor("dup"));
AddCloud(if col3 > 0 then hhLine3 else na, llLine3, GlobalColor("dup"));
AddCloud(if col1 > 0 then na else hhLine1, llLine1, GlobalColor("ddn"));
AddCloud(if col2 > 0 then na else hhLine2, llLine2, GlobalColor("ddn"));
AddCloud(if col3 > 0 then na else hhLine3, llLine3, GlobalColor("ddn"));

#-- Future_trend Trend
def values = if last[-1] then (src[period] + src[period * 2] + src[period * 3]) / 3 else values[1];
def delta  = (delta_vol + delta_vol[period] + delta_vol[period * 2]) / 3;
def diff   = if !last then src - values else diff[1];
def vol_delta = if !last then Average(delta, period) else vol_delta[1];
def col = vol_delta;
def future_trend = if !last then close else if last then diff + values else na;

plot futureTrend = if line and last[-1] and future_trend then future_trend else na;
futureTrend.SetLineWeight(2);
futureTrend.AssignValueColor(if col > 0 then GlobalColor("up") else GlobalColor("dn"));

#-- Bubble
def bubCond = bub and isNaN(futureTrend[-1]) and !isNaN(futureTrend);
AddChartBubble(bubCond[1], futureTrend[1], AsDollars(futureTrend[1]) + "\n" + Round(vol_delta[1]/1000, 2) + "K",
               if col[1] > 0 then GlobalColor("up") else GlobalColor("dn"), if col[1] > 0 then no else yes);

#-- Candles
def valuesO = if last[-1] then (open [period] + open [period * 2] + open [period * 3]) / 3 else valuesO[1];
def valuesC = if last[-1] then (close[period] + close[period * 2] + close[period * 3]) / 3 else valuesC[1];

def diffO = if !last then open  - valuesO else diffO[1];
def diffC = if !last then close - valuesC else diffC[1];
def UpO  = if candle and last then diffO + valuesO else na;
def UpC  = if candle and last then diffC + valuesC else na;

def up = UpC > UpO;

AddChart(open = if up then UpC else na, high = UpC , low = UpO ,   close = UpO,
         type = ChartType.CANDLE, growcolor = GlobalColor("up"));

AddChart(open = if up then na else UpO, high = UpO , low = UpC ,   close = UpC,
         type = ChartType.CANDLE, growcolor = GlobalColor("dn"));

def CandCond = bub and isNaN(UpC[-1]) and !isNaN(UpC);
AddChartBubble(CandCond[1], UpC[1], AsDollars(UpC[1]) + "\n" + Round(vol_delta[1]/1000, 2) + "K",
               if col[1] > 0 then GlobalColor("up") else GlobalColor("dn"), if col[1] > 0 then no else yes);

#-- Labels
AddLabel(lab, "Period[0-" + period + "]: Delta(" + Round(delta1 / 1000000, 2) + "M)" +
            ",Total(" + Round(total1 / 1000000, 2) + "M)", if delta1 > 0 then Color.GREEN else Color.RED);
AddLabel(lab, "Period[" + period + "-"+ period*2 + "]: Delta(" + Round(delta2 / 1000000, 2) + "M)" +
            ",Total(" + Round(total2 / 1000000, 2) + "M)", if delta2 > 0 then Color.GREEN else Color.RED);
AddLabel(lab, "Period[" + period*2 + "-"+ period*3 + "]: Delta(" + Round(delta3 / 1000000, 2) + "M)" +
            ",Total(" + Round(total3 / 1000000, 2) + "M)", if delta3 > 0 then Color.GREEN else Color.RED);

#--END of CODE
 
Last edited by a moderator:
  • Love
Reactions: IPA

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
430 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