Untitled
unknown
plain_text
2 years ago
14 kB
13
Indexable
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // Β© ScryptoMB // entry conditions useATR = input.bool(false, title="ATR", group="π£ Entry Conditions", inline="Entry C1") useADX = input.bool(false, title="ADX", group="π£ Entry Conditions", inline="Entry C1") useOBV =input.bool(false, title="OBV", group="π£ Entry Conditions", inline="Entry C1") useMovingAverage = input.bool(false, title="MovingAverage", group="π£ Entry Conditions", inline="Entry C1") useSuperTrend = input.bool(false, title="SuperTrend", group="π£ Entry Conditions", inline="Entry C1") useRSI = input.bool(false, title="RSI", group="π£ Entry Conditions", inline="Entry C2") useStochRSI = input.bool(false, title="StochRSI", group="π£ Entry Conditions", inline="Entry C2") useVWAP = input.bool(false, title="VWAP", group="π£ Entry Conditions", inline="Entry C2") useBollinger = input.bool(false, title="Bollinger", group="π£ Entry Conditions", inline="Entry C2") useWaveTrend = input.bool(false, title="WaveTrend", group="π£ Entry Conditions", inline="Entry C2") // ATR atrEntryLength = input.int(14, title='Lengthββββββββββ', inline='ATR 0', group="β’ ATR") atrLong = input.string('Greater Than', title="ATR Longβββββββ", options=['Smaller Than', 'Greater Than', 'Crossing Up', 'Crossing Down'], inline='ATR 1', group="β’ ATR") atrShort = input.string('Greater Than', title="ATR Shortββββββββββ", options=['Smaller Than', 'Greater Than', 'Crossing Up', 'Crossing Down'], inline='ATR 2', group="β’ ATR") atrLongValue = input.int(50, title='', inline='ATR 1', group="β’ ATR") atrShortValue = input.int(50, title='', inline='ATR 2', group="β’ ATR") atrTimeFrame = input.timeframe("", title='Resolutionββββββββββ', inline="ATRTFS", group="β’ ATR") atrSymbol = input.symbol("", title="Symbol", inline="ATRTFS", group="β’ ATR") // ADX adxlen = input(14, title="ADX Smoothing", inline="ADX1", group="β’ ADX") dilen = input(14, title="DI Length", inline="ADX1", group="β’ ADX") adxLong = input.string('Greater Than', title="ADX Longβββββββ", options=['Smaller Than', 'Greater Than', 'Crossing Up', 'Crossing Down'], inline='ADX 1', group="β’ ADX") adxShort = input.string('Greater Than', title="ADX Shortβββββ", options=['Smaller Than', 'Greater Than', 'Crossing Up', 'Crossing Down'], inline='ADX 2', group="β’ ADX") adxLongValue = input.int(20, title='', inline='ADX 1', group="β’ ADX") adxShortValue = input.int(20, title='', inline='ADX 2', group="β’ ADX") adxTimeFrame = input.timeframe("", title='Resolutionββββββ', inline="ADXTFS", group="β’ ADX") adxSymbol = input.symbol("", title="Symbol", inline="ADXTFS", group="β’ ADX") // OBV obvDivType = input.string("Regular", title='Divergence Type', options=['Regular', 'Hidden', 'Regular & Hidden'], inline='obv0', group="β’ OBV") lbL = input.int(5, title='Lookback Left', inline='obv1', group="β’ OBV") lbR = input.int(1, title='Lookback Right', inline='obv1', group="β’ OBV") rangeLower = input.int(2, title='Lower Rangeβ', inline='obv2', group="β’ OBV") rangeUpper = input.int(100, title='Upper Rangeββ', inline='obv2', group="β’ OBV") // MA maType = input.string('Price Above/Below MA 1', 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'], inline='ema0', 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 // SuperTrend typeST = input.string("Direction", title = "ST Entry Type", options=["Direction", "Direction Change"], inline='ema1', group="β’ SuperTrend", tooltip='Direction:\nCondition true whenever SuperTrend is in upward/downward direction\n\nDirection Change:\nCondition true whenever SuperTrend direction changes') stFactor = input.int(3, title='Factorββββββββββββ', inline='ST1', group="β’ SuperTrend") stPeriod = input.int(10, title='Period', inline='ST1', group="β’ SuperTrend") stTimeFrame = input.timeframe("", title='Resolutionββββ', inline="STTFS", group="β’ SuperTrend") stSymbol = input.symbol("", title="Symbol", inline="STTFS", group="β’ SuperTrend") // RSI rsiLength = input.int(14, title='Length', inline='rsi0', group='β’ RSI') rsiSource = input.source(close, title='Source', inline='rsi0', group='β’ RSI') rsiLong = input.string('Smaller Than', title="RSI Longβββββββ", options=['Smaller Than', 'Greater Than', 'Crossing Up', 'Crossing Down'], inline='RSI 1', group="β’ RSI") rsiShort = input.string('Greater Than', title="RSI Shortββββββββββ", options=['Smaller Than', 'Greater Than', 'Crossing Up', 'Crossing Down'], inline='RSI 2', group="β’ RSI") rsiLongValue = input.int(25, title='', inline='RSI 1', group="β’ RSI") rsiShortValue = input.int(75, title='', inline='RSI 2', group="β’ RSI") rsiTimeFrame = input.timeframe("", title='Resolutionββββββββββ', inline="RSITFS", group="β’ RSI") rsiSymbol = input.symbol("", title="Symbol", inline="RSITFS", group="β’ RSI") // Stochastic RSI //@version=5 strategy(title='Strategy Builder', overlay=true, initial_capital=10000, pyramiding=16, calc_on_order_fills=false, process_orders_on_close=false, calc_on_every_tick=true, backtest_fill_limits_assumption=1, slippage=2, commission_type=strategy.commission.percent, commission_value=0.03, use_bar_magnifier=true, close_entries_rule="ANY") // Non repainting security function f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on) // 1. ATR calculations atrCalc = ta.atr(atrEntryLength) // atrValue = f_secureSecurity(atrSymbol, atrTimeFrame, atrCalc) atrValue = atrCalc // 2. ADX Calculations dirmov(len) => up = ta.change(high) down = -ta.change(low) plusDM = na(up) ? na : (up > down and up > 0 ? up : 0) minusDM = na(down) ? na : (down > up and down > 0 ? down : 0) truerange = ta.rma(ta.tr, len) plus = fixnan(100 * ta.rma(plusDM, len) / truerange) minus = fixnan(100 * ta.rma(minusDM, len) / truerange) [plus, minus] adx(dilen, adxlen) => [plus, minus] = dirmov(dilen) sum = plus + minus adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen) adxCalc = adx(dilen, adxlen) // adxValue = f_secureSecurity(adxSymbol, adxTimeFrame, adxCalc) adxValue = adxCalc // 3. OBV Calculations // Oscillator new_volume = close > close[1] ? volume : close[1] > close ? -volume : 0 osc = ta.cum(new_volume) // Divergences plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true _inRange(cond) => bars = ta.barssince(cond == true) rangeLower <= bars and bars <= rangeUpper // Wavetrend does a Regular Bullish oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) // Price does a Lower Low priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) // Wavetrend does a Hidden Bullish oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) // Price does a Higher Low priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1) // Wavetrend does a Regular Bearish oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) // Price does a Higher High priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) // Wavetrend does a Hidden Bearish oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) // Price does a Lower High priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1) // Entry conditions bullCond = priceLL and oscHL and plFound hiddenBullCond = priceHL and oscLL and plFound bearCond = priceHH and oscLH and phFound hiddenBearCond = priceLH and oscHH and phFound // 4. Moving Average Calculations ma(source, length, type) => switch type "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) "HMA" => ta.wma(2*ta.wma(source, length/2)-ta.wma(source, length), math.floor(math.sqrt(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) // 5. SuperTrend Calculations [supertrend, direction] = ta.supertrend(3, 10) // 6. RSI Calculations rsiCalc = ta.rsi(rsiSource, rsiLength) // 7. StochRSI Calculations // 8. VWAP Calculations // 9. Bollinger Calculations // 10. WaveTrend Calculations // Entry Logics // ATR var bool longCond1 = na if atrLong == 'Greater Than' longCond1 := atrValue > atrLongValue if atrLong == 'Smaller Than' longCond1 := atrValue < atrLongValue if atrLong == 'Crossing Up' longCond1 := ta.crossover(atrValue, atrLongValue) if atrLong == 'Crossing Down' longCond1 := ta.crossunder(atrValue, atrLongValue) var bool shortCond1 = na if atrShort == 'Greater Than' shortCond1 := atrValue > atrShortValue if atrShort == 'Smaller Than' shortCond1 := atrValue < atrShortValue if atrShort == 'Crossing Up' shortCond1 := ta.crossover(atrValue, atrShortValue) if atrShort == 'Crossing Down' shortCond1 := ta.crossunder(atrValue, atrShortValue) // ADX var bool longCond2 = na if adxLong == 'Greater Than' longCond2 := adxValue > adxLongValue if adxLong == 'Smaller Than' longCond2 := adxValue < adxLongValue if adxLong == 'Crossing Up' longCond2 := ta.crossover(adxValue, adxLongValue) if adxLong == 'Crossing Down' longCond2 := ta.crossunder(adxValue, adxLongValue) var bool shortCond2 = na if adxShort == 'Greater Than' shortCond2 := adxValue > adxShortValue if adxShort == 'Smaller Than' shortCond2 := adxValue < adxShortValue if adxShort == 'Crossing Up' shortCond2 := ta.crossover(adxValue, adxShortValue) if adxShort == 'Crossing Down' shortCond2 := ta.crossunder(adxValue, adxShortValue) // OBV var bool longCond3 = na var bool shortCond3 = na if obvDivType == 'Regular' longCond3 := bullCond shortCond3 := bearCond if obvDivType == 'Hidden' longCond3 := hiddenBullCond shortCond3 := hiddenBearCond if obvDivType == 'Regular & Hidden' longCond3 := bullCond or hiddenBullCond shortCond3 := bearCond or hiddenBearCond // MovingAVerage var bool longCond4 = na var bool shortCond4 = na if maType == 'Price Above/Below MA 1' longCond4 := close > out1 shortCond4 := close < out1 if maType == 'Price Crossing Up/Down MA 1' longCond4 := ta.crossover(close, out1) shortCond4 := ta.crossunder(close, out1) if maType == 'MA 1 Above/Below MA 2' longCond4 := out1 > out2 shortCond4 := out1 < out2 if maType == 'MA 1 Crossing Up/Down MA 2' longCond4 := ta.crossover(out1, out2) shortCond4 := ta.crossunder(out1, out2) // SuperTrend var bool longCond5 = na var bool shortCond5 = na if typeST == 'Direction' longCond5 := direction == -1 ? true : na shortCond5 := direction == 1 ? true : na if typeST == 'Direction Change' longCond5 := direction == -1 and direction[1] == 1 ? true : na shortCond5 := direction == 1 and direction[1] == -1 ? true : na // RSI var bool longCond6 = na if rsiLong == 'Greater Than' longCond6 := rsiCalc > rsiLongValue if rsiLong == 'Smaller Than' longCond6 := rsiCalc < rsiLongValue if rsiLong == 'Crossing Up' longCond6 := ta.crossover(rsiCalc, rsiLongValue) if rsiLong == 'Crossing Down' longCond6 := ta.crossunder(rsiCalc, rsiLongValue) var bool shortCond6 = na if rsiShort == 'Greater Than' shortCond6 := rsiCalc > rsiShortValue if rsiShort == 'Smaller Than' shortCond6 := rsiCalc < rsiShortValue if rsiShort == 'Crossing Up' shortCond6 := ta.crossover(rsiCalc, rsiShortValue) if rsiShort == 'Crossing Down' shortCond6 := ta.crossunder(rsiCalc, rsiShortValue) // StochRSI longCond7 = false shortCond7 = false // VWAP longCond8 = false shortCond8 = false // Bollinger longCond9 = false shortCond9 = false // WaveTrend longCond10 = false shortCond10 = false var bool longEntry = na var bool shortEntry = na if useRSI == true longEntry := longCond6 if useRSI == true shortEntry := shortCond6 // 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) // SuperTrend stUp = plot(useSuperTrend and direction < 0 ? supertrend : na, "Up direction", color = color.rgb(41, 98, 255), style=plot.style_linebr, linewidth=2) stDown = plot(useSuperTrend and direction > 0 ? supertrend : na, "Down direction", color = color.rgb(255, 152, 0), style=plot.style_linebr, linewidth=2) plotLow = plot(low, color=color.rgb(0,0,0,100)) plotHigh = plot(high, color=color.rgb(0,0,0,100)) fill(stUp, plotHigh, color=color.rgb(41, 98, 255, 85)) fill(stDown, plotLow, color=color.rgb(255, 152, 0, 85))
Editor is loading...