Market_Delta For ThinkOrSwim

serendipity2020

Member
Plus
This script is used to identify market cumulative delta primarily on futures market on 3 or 5 min chart but works on all intra-day charts as well.

When you identify that the deltas are not decreasing rapidly, when price is going down rapidly, you can assume that its bullish setup as the volume is not going down with that speed and vice-versa.

The author states:
Market Delta is suitable for daytrading on intraday timeframes, is a volume based indicator which allows to see the UP VOLUME vs the DOWN VOLUME, the DELTA (difference) and the CUMULATIVE DELTA (cumulative sum of difference) between them
This indicator is based on contracts volume (data avaiable), not in ask/bid volume (data not avaiable)
ttQN3D8.png


Hello @samer800
Can you convert https://www.tradingview.com/script/NH4wEdWp-Market-Delta-Makit0/ to ToS?
Appreciate your help and thanks in advance!
 
Last edited by a moderator:

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

Hello @samer800
Can you convert https://www.tradingview.com/script/NH4wEdWp-Market-Delta-Makit0/ to ToS?

This script is used to identify market cumulative delta primarily on futures market on 3 or 5 min chart but works on all intra-day charts as well.

When you identify that the deltas are not decreasing rapidly, when price is going down rapidly, you can assume that its bullish setup as the volume is not going down with that speed and vice-versa.

Appreciate your help and thanks in advance!
find below.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © makit0
#// MARKET DELTA INDICATOR v0.5 beta
#study("Market_Delta_v0.5Beta",shorttitle='MD')
# converted by Sam4Cok@Samer800    - 01/2024
declare lower;

input mode = {"Volume", "Delta", "Cumulative Delta", default "Candles"};#  #'Mode'
input showZeroLine = no;#(false,'Show Zero line')

#// show/hide variables for the different modes
def na = Double.NaN;
def last = IsNaN(close);
def showVol = mode == mode."Volume";
def showDelta = mode == mode."Delta";
def showCumDelta = mode == mode."Cumulative Delta";
def showCandles = mode == mode."Candles";
def mintick = TickSize();
DefineGlobalColor("up",  CreateColor(76,175,80));
DefineGlobalColor("dn",  CreateColor(255,82,82));
#// volume & delta calculus
def up = open > close;
def candleRange = (high - low) / mintick;
def candleTopWick = if up then ((high - open) / mintick) else ((high - close) / mintick);
def candleBottomWick = if up then (close - low) / mintick else (open - low) / mintick;
def ticksUp = if up  then candleTopWick + candleBottomWick else candleRange;
def ticksDown = if up then candleRange else candleTopWick + candleBottomWick;
def totalTicks = ticksUp + ticksDown;
def volByTick = if totalTicks == 0 then 0 else volume / totalTicks;
def volUp = ticksUp * volByTick;
def volDown = ticksDown * volByTick;
def delta = volUp - volDown;

#// cumulative delta reset at globex and rth openings
def time = GetTime();
def rthOpen =  (time-1) == RegularTradingStart(GetYYYYMMDD());
def cumDelta = if rthOpen then delta else cumDelta[1] + delta;

#// getting ohlc values to plot the cumulative delta candles.
def o1 = if rthOpen then 0 else cumDelta[1];
def h1 = if delta >= 0 then cumDelta else
        if rthOpen then 0 else cumDelta[1];
def l1 = if delta <= 0 then cumDelta else
        if rthOpen then 0 else cumDelta[1];
def c1 = cumDelta;
#// fixing scale autoresize in volume and delta modes
def o;
def h;
def l;
def c;
if !showCandles {
    o = na;
    h = na;
    l = na;
    c = na;
} else {
    o = o1;
    h = h1;
    l = l1;
    c = c1;
}
AddChart(open = if o<=c then c else na, high = h , low = l ,   close = o,
         type = ChartType.CANDLE, growcolor =  GlobalColor("up"));

AddChart(open = if o>=c then o else na, high = h , low = l ,   close = c,
         type = ChartType.CANDLE, growcolor =  GlobalColor("dn"));

#// plotting volume, delta and cumulative delta. I wanted to define the style as histogram but due a bug at auto resizing the scale for the candle mode, I coded the style as areabr and circles, but the style to use here is histogram.
plot upVol = if showVol then volUp else na; # 'Up volume'
plot dnVol = if showVol then -volDown else na; # 'Down volume'
plot deltaL = if showDelta then delta else  na; # 'Delta'
plot cum = if showCumDelta then cumDelta else na; # 'Cumulative Delta'
plot zero = if showZeroLine and !last then 0 else na;# 'Zero line'
zero.SetDefaultColor(Color.GRAY);
zero.SetStyle(Curve.SHORT_DASH);
upVol.SetDefaultColor(Color.GREEN);
dnVol.SetDefaultColor(Color.RED);
deltaL.SetPaintingStrategy(PaintingStrategy.POINTS);
deltaL.AssignValueColor(if delta > 0 then Color.GREEN else Color.RED);
deltaL.SetLineWeight(3);
cum.AssignValueColor(if cumDelta > 0 then Color.GREEN else Color.RED);

AddCloud(cum, 0, GlobalColor("up"), GlobalColor("dn"));
AddCloud(upVol, 0, GlobalColor("up"));
AddCloud(0, dnVol, GlobalColor("dn"));


#-- End of Code
 
find below.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 a
#// © makit0
#// MARKET DELTA INDICATOR v0.5 beta
#study("Market_Delta_v0.5Beta",shorttitle='MD')
# converted by Sam4Cok@Samer800    - 01/2024
declare lower;

input mode = {"Volume", "Delta", "Cumulative Delta", default "Candles"};#  #'Mode'
input showZeroLine = no;#(false,'Show Zero line')

#// show/hide variables for the different modes
def na = Double.NaN;
def last = IsNaN(close);
def showVol = mode == mode."Volume";
def showDelta = mode == mode."Delta";
def showCumDelta = mode == mode."Cumulative Delta";
def showCandles = mode == mode."Candles";
def mintick = TickSize();
DefineGlobalColor("up",  CreateColor(76,175,80));
DefineGlobalColor("dn",  CreateColor(255,82,82));
#// volume & delta calculus
def up = open > close;
def candleRange = (high - low) / mintick;
def candleTopWick = if up then ((high - open) / mintick) else ((high - close) / mintick);
def candleBottomWick = if up then (close - low) / mintick else (open - low) / mintick;
def ticksUp = if up  then candleTopWick + candleBottomWick else candleRange;
def ticksDown = if up then candleRange else candleTopWick + candleBottomWick;
def totalTicks = ticksUp + ticksDown;
def volByTick = if totalTicks == 0 then 0 else volume / totalTicks;
def volUp = ticksUp * volByTick;
def volDown = ticksDown * volByTick;
def delta = volUp - volDown;

#// cumulative delta reset at globex and rth openings
def time = GetTime();
def rthOpen =  (time-1) == RegularTradingStart(GetYYYYMMDD());
def cumDelta = if rthOpen then delta else cumDelta[1] + delta;

#// getting ohlc values to plot the cumulative delta candles.
def o1 = if rthOpen then 0 else cumDelta[1];
def h1 = if delta >= 0 then cumDelta else
        if rthOpen then 0 else cumDelta[1];
def l1 = if delta <= 0 then cumDelta else
        if rthOpen then 0 else cumDelta[1];
def c1 = cumDelta;
#// fixing scale autoresize in volume and delta modes
def o;
def h;
def l;
def c;
if !showCandles {
    o = na;
    h = na;
    l = na;
    c = na;
} else {
    o = o1;
    h = h1;
    l = l1;
    c = c1;
}
AddChart(open = if o<=c then c else na, high = h , low = l ,   close = o,
         type = ChartType.CANDLE, growcolor =  GlobalColor("up"));

AddChart(open = if o>=c then o else na, high = h , low = l ,   close = c,
         type = ChartType.CANDLE, growcolor =  GlobalColor("dn"));

#// plotting volume, delta and cumulative delta. I wanted to define the style as histogram but due a bug at auto resizing the scale for the candle mode, I coded the style as areabr and circles, but the style to use here is histogram.
plot upVol = if showVol then volUp else na; # 'Up volume'
plot dnVol = if showVol then -volDown else na; # 'Down volume'
plot deltaL = if showDelta then delta else  na; # 'Delta'
plot cum = if showCumDelta then cumDelta else na; # 'Cumulative Delta'
plot zero = if showZeroLine and !last then 0 else na;# 'Zero line'
zero.SetDefaultColor(Color.GRAY);
zero.SetStyle(Curve.SHORT_DASH);
upVol.SetDefaultColor(Color.GREEN);
dnVol.SetDefaultColor(Color.RED);
deltaL.SetPaintingStrategy(PaintingStrategy.POINTS);
deltaL.AssignValueColor(if delta > 0 then Color.GREEN else Color.RED);
deltaL.SetLineWeight(3);
cum.AssignValueColor(if cumDelta > 0 then Color.GREEN else Color.RED);

AddCloud(cum, 0, GlobalColor("up"), GlobalColor("dn"));
AddCloud(upVol, 0, GlobalColor("up"));
AddCloud(0, dnVol, GlobalColor("dn"));


#-- End of Code
Awesome. Thanks!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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