Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © NKactive
- //@version=5
- strategy("Logic Test NK.active") // , margin_long=100, margin_short=100)
- // Simple Moving Average TPI Input
- // ************************************************************************************************************************************
- // Produce a 1 or long
- // produce a -1 for short
- longConditionSMACross = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
- shortConditionSMACross = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
- float SMACrossInputTPI = 0.00
- if longConditionSMACross
- SMACrossInputTPI := 1
- if shortConditionSMACross
- SMACrossInputTPI := -1
- // RSI TPI Input
- // ************************************************************************************************************************************
- // Produce a 1 or long
- // produce a -1 for short
- rsiValue = ta.rsi(close, 7)
- longConditionRSI = rsiValue < 25
- shortConditionRSI = rsiValue > 75
- float RSIInputTPI = 0.00
- if longConditionRSI or longConditionRSI[1] or longConditionRSI[2] or longConditionRSI[3] or longConditionRSI[4] or longConditionRSI[5]
- RSIInputTPI := 1
- if shortConditionRSI or shortConditionRSI[1] or shortConditionRSI[2] or shortConditionRSI[3] or shortConditionRSI[4] or shortConditionRSI[5]
- RSIInputTPI := -1
- // RVOL TPI Input
- // ************************************************************************************************************************************
- // Produce a 1 or long
- // produce a -1 for short
- //
- // Get volume data
- averageVol = ta.sma(volume, 100)
- ratioVol = volume / averageVol
- // Generate RVOL signal
- longConditionRVOL = ratioVol >= 2.5
- shortConditionRVOL = ratioVol <= 1
- float RVOLInputTPI = 0.00
- if longConditionRVOL
- RVOLInputTPI := 1
- if shortConditionRVOL
- RVOLInputTPI := -1
- //
- // ************************************************************************************************************************************
- //
- // Logic to determine buy or sell signal
- //
- // Initialise variables
- triggerPositionBuy = false
- triggerPositionSell = false
- float triggerTPIvalue = 0.00
- //
- // Find the absolute triggerTPIvalue used to decide buy and sell signals
- triggerTPIvalue := math.avg(SMACrossInputTPI, RSIInputTPI, RVOLInputTPI)
- // Debugging code for triggerTPIvalue
- // plot(SMACrossInputTPI, color = color.blue, title = "SMACrossInputTPI") // this is the TPI input from the SMA Crossover
- // plot(RSIInputTPI, color = color.fuchsia, title = "RSIInputTPI") // this is the TPI input from the SMA Crossover
- // plot(RVOLInputTPI, color = color.green, title = "RVOLInputTPI") // this is the TPI input from the SMA Crossover
- //plot(triggerTPIvalue, color = color.white, linewidth = 2, title = "triggerTPIvalue") // this is the TPI input value calculated from the average of all the inputs
- //
- // Find the RoC of the TPI (percentage)
- //
- TPItriggerRoC = ta.roc(triggerTPIvalue, 1)
- //
- // Find trend bool for RoC Trend
- //
- TPIpositiveRoCtrend = false
- TPInegativeRoCtrend = false
- TPIpositiveRoCtrend := ta.rising(triggerTPIvalue, 1)
- TPInegativeRoCtrend := ta.falling(triggerTPIvalue, 1)
- // highest_bar_offset = ta.highest(triggerTPIvalue, 2)
- //TPItriggerRoC := highest_bar_offset - triggerTPIvalue
- plot(TPIpositiveRoCtrend ? 10 : na, title= "TPIpositiveRoCtrend", color = color.orange)
- plot(TPInegativeRoCtrend ? -10 : na, title= "TPInegativeRoCtrend", color = color.fuchsia)
- plot(triggerTPIvalue, title = "triggerTPIvalue", color = color.lime)
- plot(TPItriggerRoC, title= "TPItriggerRoC", color = color.gray)
- //
- // Combines the TPI value, RoC percent and RoC Trend
- //
- // triggerTPIvalue float
- // TPItriggerRoC float
- // TPIpositiveRoCtrend bool
- //
- if triggerTPIvalue >= 0.3 and (TPItriggerRoC >= 50 or TPIpositiveRoCtrend)
- triggerPositionBuy := true
- if triggerTPIvalue <= 0.3 and (TPItriggerRoC <= 50 or TPInegativeRoCtrend)
- triggerPositionSell := true
- //
- // Execute buy/sell positions based on the logic above
- // *************************************
- //
- if triggerPositionBuy
- strategy.entry("My Long Entry Id", strategy.long)
- if triggerPositionSell
- strategy.entry("My Short Entry Id", strategy.short)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement