#Blog2 -How To Download fastbote Tradingview Strategy Pinscript code
MACD Tradingview Pinescript Algo Strategy
//@version=5
strategy(title="MACD-Fastbot",overlay=false)
trades = input.string(title="Trade", defval="Long", options=["Long", "Short"] )
// Getting inputs
fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
plot(macd, title="MACD", color=col_macd)
plot(signal, title="Signal", color=col_signal)
// strategy
b = ta.crossover(macd,signal)
s = ta.crossunder(macd,signal)
if barstate.isconfirmed
strategy.entry("Buy",strategy.long,when =b and trades=="Long",alert_message = "exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=BUY" )
strategy.close("Buy",when = s and trades=="Long",alert_message ="exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=SELL" )
strategy.entry("Sell",strategy.short,when =s and trades=="Short",alert_message ="exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=SELL" )
strategy.close("Sell",when= b and trades=="Short",alert_message = "exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=BUY" )
Moving Avrage Crosover Tradingview Pinescript Algo Strategy
//@version=5
strategy("MA strategy-Fastbot",overlay=true)
trades = input.string(title="Trade", defval="Long", options=["Long", "Short"] )
// Slow EMA
lengtha = input.int(title="Slow Length",defval=14 )
source = input.source(title="Slow Source", defval=close)
smoothing = input.string(title="Slow Type", defval="EMA", options=["SMA", "EMA"] )
ematypes = smoothing=="EMA" ? ta.ema(source, lengtha) : ta.sma(source, lengtha)
plot(ematypes, title='Slow EMA', color=color.new(#00ffaa, 70), linewidth=2, style=plot.style_line )
// Fast EMA
lengtha2 = input.int(title="Fast Length",defval=21 )
source2 = input.source(title="Fast Source", defval=close)
smoothing2 = input.string(title="Fast Type", defval="EMA", options=["SMA", "EMA"] )
ematypes2 = smoothing=="EMA" ? ta.ema(source2, lengtha2) : ta.sma(source2, lengtha2)
plot(ematypes2, title='Fast EMA', color=color.new(color.red, 20), linewidth=2, style=plot.style_line )
// strategy
b = ta.crossover(ematypes,ematypes2)
s = ta.crossunder(ematypes,ematypes2)
if barstate.isconfirmed
strategy.entry("Buy",strategy.long,when =b and trades=="Long",alert_message = "exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=BUY" )
strategy.close("Buy",when = s and trades=="Long",alert_message ="exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=XBUY" )
strategy.entry("Sell",strategy.short,when =s and trades=="Short",alert_message ="exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=SELL" )
strategy.close("Sell",when= b and trades=="Short",alert_message = "exg=NSE&sym="+syminfo.ticker+"&price="+str.tostring(close)+"&qty="+str.tostring(volume)+"&tsym=trading_symbol&typ=XSELL" )
// type in message box (for BUY) exg={{exchange}}&sym={{ticker}}&price={{close}}&qty={{volume}}&tsym=trading_symbol&typ=BUY
// type in message box (for SELL) exg={{exchange}}&sym={{ticker}}&price={{close}}&qty={{volume}}&tsym=trading_symbol&typ=SELL
// type in message box (for EXIT BUY) exg={{exchange}}&sym={{ticker}}&price={{close}}&qty={{volume}}&tsym=trading_symbol&typ=XBUY
// type in message box (for EXIT SELL) exg={{exchange}}&sym={{ticker}}&price={{close}}&qty={{volume}}&tsym=trading_symbol&typ=XSELL
Posted On - 25 Aug 2020
By - Om