Untitled
unknown
plain_text
3 years ago
1.4 kB
6
Indexable
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Algokid //@version=5 strategy("5 / 8 sma", overlay=true, margin_long=100, margin_short=100) //backtest ranges //STEP 1. Create inputs that configure the backtest's date range useDateFilter = input.bool(true, title="Begin Backtest at Start Date", group="Backtest Time Period") backtestStartDate = input.time(timestamp("1 Jan 2017"), title="Start Date", group="Backtest Time Period", tooltip="This start date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " + "zone of the chart or of your computer.") // STEP 2. See if current bar happens on, or later than, the start date inTradeWindow = not useDateFilter or time >= backtestStartDate // Input shortma = input(5,"short sma") longma = input(8,"long sma") sma1 = ta.sma(close,shortma) sma2 = ta.sma(close,longma) // rules buy = ta.crossover(sma1,sma2) sell = ta.crossunder(sma1,sma2) // Execution longCondition = buy if inTradeWindow and (longCondition) strategy.entry("My Long Entry Id", strategy.long) strategy.close_all(when = sell) //shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28)) //if (shortCondition) // strategy.entry("My Short Entry Id", strategy.short)
Editor is loading...