- I want to run/execute the script every 1 minute.
- Everytime it checks if there is no position opened.
- If there is no position opened then it opens a new position.
I just need a hint how to open a position every 1 minute.
I am going to implement it into the following strategy
//@version=5
strategy("Jopin - modify 1", overlay=true)
// Setting up timeperiod for testing
startPeriodYear = input(2023, "Backtest Start Year")
startPeriodMonth = input(4, "Backtest Start Month")
startPeriodDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(startPeriodYear, startPeriodMonth, startPeriodDay, 0, 0)
stopPeriodYear = input(2023, "Backtest Stop Year")
stopPeriodMonth = input(4, "Backtest Stop Month")
stopPeriodDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(stopPeriodYear, stopPeriodMonth, stopPeriodDay, 0, 0)
// Moving Averages
ema14 = ema(close, 14)
ema28 = ema(close, 28)
sma56 = sma(close, 56)
// Strategy
goLong = cross(ema14, sma56) and ema14 > ema28
goShort = cross(ema14, sma56) and ema14 < ema28
// Strategy.When to enter
if time >= testPeriodStart
if time <= testPeriodStop
strategy.entry("Go Long", strategy.long, 1.0, when=goLong)
strategy.entry("Go Short", strategy.short, 1.0, when=goShort)
// Strategy.When to take profit
if time >= testPeriodStart
if time <= testPeriodStop
strategy.exit("Close Long", "Go Long", profit=2000)
strategy.exit("Close Short", "Go Short", profit=2000)
I've edited the following code
//@version=2
strategy("Jopin - modify 2", overlay=true)
// Setting up timeperiod for testing
startPeriodYear = input(2023, "Backtest Start Year")
startPeriodMonth = input(3, "Backtest Start Month")
startPeriodDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(startPeriodYear, startPeriodMonth, startPeriodDay, 0, 0)
stopPeriodYear = input(2023, "Backtest Stop Year")
stopPeriodMonth = input(3, "Backtest Stop Month")
stopPeriodDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(stopPeriodYear, stopPeriodMonth, stopPeriodDay, 0, 0)
// Strategy.When to enter
if time >= testPeriodStart
if time <= testPeriodStop
strategy.entry("Go Long", strategy.long, 1.0)
strategy.entry("Go Short", strategy.short, 1.0)
// Strategy.When to take profit
if time >= testPeriodStart
if time <= testPeriodStop
strategy.exit("Close Long", "Go Long", profit=2000)
strategy.exit("Close Short", "Go Short", profit=2000)
I need a function which every minute trigger my code (1. check if there is opened a LONG or SHORT position, 2. IF NOT... Then it opens a LONG or SHORT position).