// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
strategy(title = "BTC strat", overlay = true,initial_capital =10000)
//----STRATEGY TIMEFRAME----\\
startDate = input.time(timestamp("01 Jan 2018"), title = "Start Date", group = "Time")
bool intimeframe = time >= startDate
import EliCobra/CobraMetrics/4 as cobra
start = input.float(defval = 0.045,title = "Start",step = 0.001,group = "SAR")
increment = input.float(defval = 0.02,title = "INCREMENT",step = 0.001,group = "SAR")
maximum = input.float(defval = 0.02,title = "MAX VALUE",step = 0.001,group = "SAR")
aroonlength = input.int(38, minval=1, title = "AR Length", group = "AROON")
// -----CALCULATIONS------//
sar = ta.sar(start,increment,maximum)
aroonupper = 100 * (ta.highestbars(high, aroonlength+1) + aroonlength)/aroonlength
aroonlower = 100 * (ta.lowestbars(low, aroonlength+1) + aroonlength)/aroonlength
aroonLong = aroonupper > aroonlower
aroonShort = aroonupper <= aroonlower
Len = input.int(46, minval=1, title="DI Length",group = "DMI")
//returning the difference
//calculating +DM and -DM
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
plus = fixnan(100 * ta.rma(plusDM, Len) / Rma)
minus = fixnan(100 * ta.rma(minusDM, Len) / Rma)
// Detect buy and sell signals
buySignal = plus>minus and ( aroonLong and sarLong) and barstate.isconfirmed
sellSignal = (plus<minus or aroonShort or sarShort) and barstate.isconfirmed
if buySignal and intimeframe
strategy.entry(id = "Long",direction = strategy.long)
if sellSignal and intimeframe
strategy.entry(id = "Short",direction = strategy.short)
plotshape(buySignal, style=shape.triangleup, color=color.green, location=location.belowbar)
plotshape(sellSignal, style=shape.triangledown, color=color.red, location=location.abovebar)
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)