// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © NKactive (replace with your name)
// Original source from (credit original writer of code)
//@version=5
strategy("NK Thor BTC", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0, slippage=1)
import EliCobra/CobraMetrics/4 as cobra
//// PLOT DATA
disp_ind = input.string ("None" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
pos_table = input.string("Middle Left", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
plot(cobra.curve(disp_ind))
cobra.cobraTable(type_table, pos_table)
// ****************************************************************************************************************************************************************
// Reset Position Label
// ****************************************************************************************************************************************************************
longMsg = ""
shortMsg = ""
// ****************************************************************************************************************************************************************
// RSI
//
// ****************************************************************************************************************************************************************
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, group="RSI Settings")
uprsi = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
downrsi = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = downrsi == 0 ? 100 : uprsi == 0 ? 0 : 100 - (100 / (1 + uprsi / downrsi))
rsi2 = ta.rsi(close, 5)
LongRSI = rsi2 > 50
ShortRSI = rsi2 < 50
//LongRSI = ta.crossover(rsi2, 50)
//ShortRSI = ta.crossunder(rsi2, 50)
if LongRSI
longMsg += "RSI "
if ShortRSI
shortMsg += "RSI "
// ****************************************************************************************************************************************************************
// MACD
// ****************************************************************************************************************************************************************
// Inputs
FastLength = input(title="MACD Fast Length", group="MACD", defval=44)
Slowlength = input(title="MACD Slow Length", group="MACD", defval=95)
MACDLength = input(title="MACD Signal Length", group="MACD", defval=31)
timeframe3=input.timeframe(defval ='1D', group = "MACD", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
MACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(close, FastLength)) - request.security(syminfo.tickerid,timeframe3 , ta.ema(close, Slowlength))
aMACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(MACD, MACDLength))
delta = MACD - aMACD
// Calculate Buy/Sell orders
LongMACD = delta>0
ShortMACD = delta<0
//LongMACD = ta.crossover(delta, 0)
//ShortMACD = ta.crossunder(delta, 0)
if LongMACD
longMsg += "MACD "
if ShortMACD
shortMsg += "MACD "
// ****************************************************************************************************************************************************************
//PUELL
// ****************************************************************************************************************************************************************
var g_pu = "PU Settings"
top = input.float(1.19, step=0.01)
bottom = input.float(2.03, step=0.01)
miningRevenue = request.security('QUANDL:BCHAIN/MIREV', 'D', close[1], barmerge.gaps_off, barmerge.lookahead_on)
ma365 = request.security('QUANDL:BCHAIN/MIREV', 'D', ta.sma(close, 365)[1], barmerge.gaps_off, barmerge.lookahead_on)
puellMultiple = miningRevenue / ma365
LongPuel = puellMultiple < top
ShortPuel = puellMultiple > bottom
if LongPuel
longMsg += "Puel "
if ShortPuel
shortMsg += "Puel "
//Plot
//plot(miningRevenue, color=color.yellow)
//plot(ma365, color=color.orange)
//plot(puellMultiple, color=color.blue)
//plot(top, color=color.green)
//plot(bottom, color=color.red)
//fill(hline(top), hline(bottom), color=color.new(color.gray, 80))
// ****************************************************************************************************************************************************************
// Use this code to debug the plots
//.****************************************************************************************************************************************************************
plot(LongRSI ? 100 : ShortRSI ? 98 : 99, linewidth = 2, color = color.purple, title = "RSI")
plot(LongMACD ? 97 : ShortMACD ? 95 : 96, linewidth = 2, color = color.lime, title = "MACD")
plot(LongPuel ? 94 : ShortPuel ? 92 : 93, linewidth = 2, color = color.aqua, title = "VWEMA")
// ****************************************************************************************************************************************************************
// Call combine signals and execute buy/sell positions within timeframe
//.****************************************************************************************************************************************************************
//Set Buy/Sell Condition
goLong = (LongRSI and LongMACD) // or (LongPuel and not (ShortMACD or ShortRSI))
goShort = (ShortRSI and ShortMACD) // or (ShortPuel and not (LongRSI or LongMACD))
// Date Range To Include
startDate = timestamp("2018-01-01T00:00")
endDate = time
// Check if the current timestamp is within the restricted range
inRestrictedRange = time >= startDate and time <= endDate
//
// Buy/Sell Signals
//
if inRestrictedRange and goLong
strategy.entry("My Long Entry Id", strategy.long, comment = longMsg)
if inRestrictedRange and goShort
strategy.entry("My Short Entry Id", strategy.short, comment = shortMsg)