You are on page 1of 1

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © vishva989

//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)

ma(source, length, type) =>


switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")


rsitLengthInput = input.int(14, minval=1, title="RSIT Length", group="RSI
Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
rsitSourceInput = input.source(close, "Source", group="RSI Settings")
oversold= input.float(30,minval=1, title="OverSold", group="RSI Settings")
overbought= input.float(70,minval=1, title="OverBought", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger
Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)


down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
upt = ta.rma(math.max(ta.change(rsitSourceInput), 0), rsitLengthInput)
downt = ta.rma(-math.min(ta.change(rsitSourceInput), 0), rsitLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsit = downt == 0 ? 100 : upt == 0 ? 0 : 100 - (100 / (1 + upt / downt))
rsiMA = ma(rsi, maLengthInput, maTypeInput)

//plot(rsi,color=color.green)
//plot(rsit,color=color.red)

longCondition = ta.crossover(rsi,overbought)
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long,100)

shortCondition =ta.crossunder(rsi, overbought)


if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short,100)

You might also like