// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ScryptoMB
//@version=5
indicator("My script", overlay=true)
useMovingAverage = input.bool(true, title="MovingAverage", group="🟣 Entry Conditions", inline="Entry C1")
// MA
maType = input.string('MA 1 Crossing Up/Down MA 2', title="MA Entry Type", options=['Price Above/Below MA 1', 'Price Crossing Up/Down MA 1', 'MA 1 Above/Below MA 2', 'MA 1 Crossing Up/Down MA 2'], group="• Moving Average")
typeMA1 = input.string("SMA", title = "Moving Average 1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "HMA"], inline='ema1', group="• Moving Average")
lenEMA1 = input.int(100, minval=1, title="Length", inline='ema1', group="• Moving Average")
typeMA2 = input.string("SMA", title = "Moving Average 2", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "HMA"], inline='ema2', group="• Moving Average")
lenEMA2 = input.int(200, minval=1, title="Length", inline='ema2', group="• Moving Average")
maTimeFrame = input.timeframe("", title='Resolution ', inline="MATFS", group="• Moving Average")
maSymbol = input.symbol("", title="Symbol", inline="MATFS", group="• Moving Average")
srcEMA = close
var bool timeFrameChart = na
if maTimeFrame == ""
timeFrameChart := true
else
timeFrameChart := false
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[0], lookahead = barmerge.lookahead_on)
// indexHighTF = barstate.isrealtime ? 1 : 0
// indexCurrTF = barstate.isrealtime ? 0 : 1
// f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[indexHighTF])[indexCurrTF]
// 4. Moving Average Calculations
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
out1 = f_secureSecurity(maSymbol, maTimeFrame, ma(srcEMA, lenEMA1, typeMA1))
out2 = f_secureSecurity(maSymbol, maTimeFrame, ma(srcEMA, lenEMA2, typeMA2))
// out1 = ma(srcEMA, lenEMA1, typeMA1)
// out2 = ma(srcEMA, lenEMA2, typeMA2)
// MovingAVerage
var bool longCond4 = na
var bool shortCond4 = na
if maType == 'MA 1 Crossing Up/Down MA 2'
longCond4 := ta.crossover(out1, out2)
shortCond4 := ta.crossunder(out1, out2)
var bool longEntry = na
var bool shortEntry = na
if useMovingAverage == true
longEntry := longCond4
if useMovingAverage == true
shortEntry := shortCond4
// Plots
plotshape(longEntry, title='Long Entry', location=location.belowbar, style=shape.labelup, color=color.new(#2C9670, 0), text='Long', textcolor=color.new(color.white, 0))
plotshape(shortEntry, title='Short Entry', location=location.abovebar, style=shape.labeldown, color=color.new(#B84343, 0), text='Short', textcolor=color.new(color.white, 0))
// EMA
emaColor1 = close > out1 ? color.teal : color.red
emaColor2 = close > out2 ? color.teal : color.red
bgCol = out1 > out2 ? color.rgb(0, 137, 123, 80) : color.rgb(255, 82, 82, 80)
emaplot1 = plot(useMovingAverage ? out1 : na, title="EMA1", color=emaColor1, linewidth=2)
emaplot2 = plot(useMovingAverage and maType == 'MA 1 Above/Below MA 2' or maType == 'MA 1 Crossing Up/Down MA 2' ? out2 : na, title="EMA2", color=emaColor2, linewidth=2)
fill(emaplot1, emaplot2, color=bgCol)
// if longEntry
// strategy.entry("Long", strategy.long)
// if shortEntry
// strategy.entry("Short", strategy.short)