Swing Call - convert this TV script into TOS

Platform
  1. Thinkorswim
  2. NinjaTrader
here is the code:

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nicks1008
//@version=4
study("SWING CALLS",title="SMA call buy/sale",shorttitle = "SWING CALL",precision=1, overlay=true)
ema_value=input(5)
sma_value=input(50)
ema1=ema(close,ema_value)
sma2= sma(close,sma_value)
rs=rsi(close,14)

mycolor= iff(rs>=85 or rs<=15,color.yellow,iff(low> sma2,color.lime,iff(high<sma2,color.red,color.yellow)))

hl=input(80,title="Overbought limit of RSI",step=1)
ll=input(20,title="Oversold limit of RSI",step=1)


buyexit= crossunder(rs,hl)
sellexit=crossover(rs,ll)


plot(sma2,title="Long SMA",color=mycolor,linewidth=2,transp=40)

plotshape(buyexit,title="RSI alert Bearish", style=shape.triangledown,
                 location=location.abovebar, color=color.teal, text="↓\n ↓")
plotshape(sellexit,title="RSI alert Bullish", style=shape.triangleup,
                 location=location.belowbar, color=color.teal, text="↑ \n ↑")   
                
sellcall= crossover(sma2,ema1)and open>close
buycall=crossunder (sma2,ema1)and high>sma2
                
plotshape(buycall,title="BuyShape", style=shape.labelup,
                   location=location.belowbar, color=color.aqua, text="B",textcolor=color.white)
plotshape(sellcall,title="SellShape", style=shape.labeldown,
                   location=location.abovebar, color=color.red,transp=20, text="S",textcolor=color.black)
                  
alertcondition(buyexit or sellexit,title="Reversal", message="Possible Reversal on Swing Signal Alert")
alertcondition(buycall or sellcall,title="Buy/Sale Swing Signal", message="Swing Signal Entry Alert")
 
Last edited by a moderator:
here is the code:

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nicks1008
//@version=4
study("SWING CALLS",title="SMA call buy/sale",shorttitle = "SWING CALL",precision=1, overlay=true)
ema_value=input(5)
sma_value=input(50)
ema1=ema(close,ema_value)
sma2= sma(close,sma_value)
rs=rsi(close,14)

mycolor= iff(rs>=85 or rs<=15,color.yellow,iff(low> sma2,color.lime,iff(high<sma2,color.red,color.yellow)))

hl=input(80,title="Overbought limit of RSI",step=1)
ll=input(20,title="Oversold limit of RSI",step=1)


buyexit= crossunder(rs,hl)
sellexit=crossover(rs,ll)


plot(sma2,title="Long SMA",color=mycolor,linewidth=2,transp=40)

plotshape(buyexit,title="RSI alert Bearish", style=shape.triangledown,
                 location=location.abovebar, color=color.teal, text="↓\n ↓")
plotshape(sellexit,title="RSI alert Bullish", style=shape.triangleup,
                 location=location.belowbar, color=color.teal, text="↑ \n ↑")  
               
sellcall= crossover(sma2,ema1)and open>close
buycall=crossunder (sma2,ema1)and high>sma2
               
plotshape(buycall,title="BuyShape", style=shape.labelup,
                   location=location.belowbar, color=color.aqua, text="B",textcolor=color.white)
plotshape(sellcall,title="SellShape", style=shape.labeldown,
                   location=location.abovebar, color=color.red,transp=20, text="S",textcolor=color.black)
                 
alertcondition(buyexit or sellexit,title="Reversal", message="Possible Reversal on Swing Signal Alert")
alertcondition(buycall or sellcall,title="Buy/Sale Swing Signal", message="Swing Signal Entry Alert")
@barbaros i hope you can help me here! the indicator look pretty solid. so we can back testing. thank you in advance
 

barbaros

Administrator
Staff member
here you go

Code:
# Swing Calls
# Converted for https://b4indicators.com/threads/swing-call-convert-this-tv-script-into-tos.255/
# barbaros

input ema_1 = 5;
input sma_1 = 50;
input hl = 80;
input ll = 20;

def ema1 = MovAvgExponential(close, ema_1);
plot sma2 = SimpleMovingAvg(close, sma_1);
def rs = rsi(price = close, length = 14);

plot buyexit = rs crosses below hl;
plot sellexit = rs crosses above ll;

sma2.AssignValueColor(
    if rs>=85 or rs<=15 then color.yellow
    else if low> sma2 then color.lime
    else if high<sma2 then color.red
    else color.yellow
);

buyexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
buyexit.SetDefaultColor(color.white);

sellexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
sellexit.SetDefaultColor(color.white);

def sellcall = sma2 crosses above ema1 and open > close;
def buycall = sma2 crosses below ema1 and high > sma2;

AddChartBubble(buycall, low, "B", color.cyan, no);
AddChartBubble(sellcall, high, "S", color.red, yes);

Alert(buycall, "Buy", Alert.BAR, Sound.DING);
Alert(sellcall, "Sell", Alert.BAR, Sound.DING);
 
here you go

Code:
# Swing Calls
# Converted for https://b4indicators.com/threads/swing-call-convert-this-tv-script-into-tos.255/
# barbaros

input ema_1 = 5;
input sma_1 = 50;
input hl = 80;
input ll = 20;

def ema1 = MovAvgExponential(close, ema_1);
plot sma2 = SimpleMovingAvg(close, sma_1);
def rs = rsi(price = close, length = 14);

plot buyexit = rs crosses below hl;
plot sellexit = rs crosses above ll;

sma2.AssignValueColor(
    if rs>=85 or rs<=15 then color.yellow
    else if low> sma2 then color.lime
    else if high<sma2 then color.red
    else color.yellow
);

buyexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
buyexit.SetDefaultColor(color.white);

sellexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
sellexit.SetDefaultColor(color.white);

def sellcall = sma2 crosses above ema1 and open > close;
def buycall = sma2 crosses below ema1 and high > sma2;

AddChartBubble(buycall, low, "B", color.cyan, no);
AddChartBubble(sellcall, high, "S", color.red, yes);

Alert(buycall, "Buy", Alert.BAR, Sound.DING);
Alert(sellcall, "Sell", Alert.BAR, Sound.DING);
@barbaros thank you some much! you are the best!
 
here you go

Code:
# Swing Calls
# Converted for https://b4indicators.com/threads/swing-call-convert-this-tv-script-into-tos.255/
# barbaros

input ema_1 = 5;
input sma_1 = 50;
input hl = 80;
input ll = 20;

def ema1 = MovAvgExponential(close, ema_1);
plot sma2 = SimpleMovingAvg(close, sma_1);
def rs = rsi(price = close, length = 14);

plot buyexit = rs crosses below hl;
plot sellexit = rs crosses above ll;

sma2.AssignValueColor(
    if rs>=85 or rs<=15 then color.yellow
    else if low> sma2 then color.lime
    else if high<sma2 then color.red
    else color.yellow
);

buyexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
buyexit.SetDefaultColor(color.white);

sellexit.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
sellexit.SetDefaultColor(color.white);

def sellcall = sma2 crosses above ema1 and open > close;
def buycall = sma2 crosses below ema1 and high > sma2;

AddChartBubble(buycall, low, "B", color.cyan, no);
AddChartBubble(sellcall, high, "S", color.red, yes);

Alert(buycall, "Buy", Alert.BAR, Sound.DING);
Alert(sellcall, "Sell", Alert.BAR, Sound.DING);
hi @barbaros a quick favor to make this indicator even better. can you add paint color candles at the signal? example: if is a long signal to paint the candles blue if is short paint the candles yellow or some other color and leave the other candles at currently. also add the scan. i'm sorry to bother you a lot. really appreciate your help, thanks in advance
 
hello everyone! any help creating the scan for this great indicator.. is pretty good, i hope everyone are enjoy the great job the @barbaros did it.. thanks in advance.
 
Top