TV Advance Decline code convert to TOS code

zac31

New member
Platform
  1. Thinkorswim
  2. TradingView
Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tom1trader
// This is the NYSE Advancers - decliners which the SPX pretty much has to follow. The level gives an idea of days move
//  but I follow the direction as when more advance (green) or decline (red) the index tends to track it pretty closely.


// On SPX and correlateds - very useful for intr-day trading (Scalping or 0DTE option trades) but not for higher time fromes at all.

// I left it at 5 minutes timeframe which displays well on any intraday chart. You can change it by changing the "5" in the security
//  function on line 13 to what you want or change it to timeframe.period (no quotes). 5 min displays better on higher i.e. 15min.

//@version=4
study("ADD", overlay=false)
a = security("USI:ADD", "5", hlc3)

dircol = a>a[1] ? color.green : color.red
plot(a, title="ADD", color=dircol, linewidth=4)
m10 = sma(a, 10)
plot(m10, color=color.black, linewidth=2)
 
Last edited by a moderator:

barbaros

Administrator
Staff member
Code:
declare lower;

plot ADD = hlc3(symbol = "$ADD");
ADD.AssignValueColor(if ADD>ADD[1] then color.green else color.red);
ADD.SetLineWeight(2);

plot m10 = SimpleMovingAvg(ADD, 10);
m10.SetDefaultColor(color.gray);
m10.SetLineWeight(1);
 

barbaros

Administrator
Staff member
Here is the upper version with arrow plots.

Code:
# ADD Upper
# Created for https://b4indicators.com/threads/tv-advance-decline-code-convert-to-tos-code.348/
# Free for use for non commercial. 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.
# barbaros

declare upper;

def ADD = hlc3(symbol = "$ADD");
def ADD_dir = if ADD>ADD[1] then 1 else if ADD<ADD[1] then -1 else 0;

def m10 = SimpleMovingAvg(ADD, 10);

def direction = if ADD > m10 then
                    if ADD_dir > 0 then 1 else 0
                else if ADD < m10 then
                    if ADD_dir < 0 then -1 else 0
                else if ADD == M10 then 0
                else direction[1];

plot BuySignal = direction crosses above 0;
BuySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySignal.SetDefaultColor(Color.CYAN);

plot SellSignal = direction crosses below 0;
SellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSignal.SetDefaultColor(Color.MAGENTA);
 
Top