Untitled

 avatar
unknown
plain_text
a month ago
1.8 kB
5
Indexable
//@version=6
strategy("RSI MA Strategy with EMA 610 and RSI Source EMA 55 - Long Only", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=10, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1)

// RSI Settings
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
ema55Length = input.int(55, title="EMA 55 Length", group="RSI Settings") // EMA 55 for RSI Source
rsiSourceInput = ta.ema(close, ema55Length) // RSI Source is EMA 55

// RSI Calculation
change = ta.change(rsiSourceInput)
up = ta.rma(math.max(change, 0), rsiLengthInput)
down = ta.rma(-math.min(change, 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

// Moving Average Settings
maTypeInput = input.string("SMA", "Type", options = ["None", "SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Moving Average Settings")
maLengthInput = input.int(14, "Length", group="Moving Average Settings")

// Moving Average Calculation
ma(source, length, MAtype) =>
    switch MAtype
        "SMA"        => 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)

smoothingMA = ma(rsi, maLengthInput, maTypeInput)

// Entry and Exit Conditions
longCondition = ta.crossover(rsi, smoothingMA)
exitCondition = ta.crossunder(rsi, smoothingMA)

// Strategy Execution
if (longCondition)
    strategy.entry("Long", strategy.long)

if (exitCondition)
    strategy.close("Long")

// Plotting RSI and MA
plot(rsi, title="RSI", color=color.purple)
plot(smoothingMA, title="Smoothing MA", color=color.orange)




Editor is loading...
Leave a Comment