Hi all,
I am learning Pinescript and I am trying to build a simple strategy that, given in input a start date (day and month) and a window duration, defines a "sensitive area" (e.g. from 15 days before the start to the half of the seasonal window). Then, in this sensitive area it checks if there is a technical pattern (a crossover of the upper BB in this case) and if yes, then enters long.
It is obviously for learning purposes, I will not trade this.
The strategy compiles but then when i go to the strategy tester it says that there is no case in which the strategy enters. It seems to me impossible, and i tried with many commodity ETFs such as CORN, USO, WHEAT, UNG etc
Can you help me to find the mistake? I am trying for instance with these parameters on ETF CORN: 1st of June start, window duration 30 days, entry tolerance 15 days. Technical condition: crossover on the upper Bollinger band
Here is the code. I havemade a bit alone and a bit with chatGPT support.
Thanks a lot for your kind support
******
//@version=5
strategy("Test Seasonality", shorttitle="Test Seasonality", overlay=true)
// Input
startDay = input(1, title="Start Day")
startMonth = input(6, title="Start Month")
windowDuration = input(30, title="Window Duration")
entryTolerance = input(15, title="Entry Tolerance")
// Computation of seasonal window and sensitive window
seasonalWindowStart = timestamp(year, startMonth, startDay)
seasonalWindowEnd = seasonalWindowStart + windowDuration
sensitiveWindowStart = seasonalWindowStart - entryTolerance
sensitiveWindowEnd = sensitiveWindowStart + windowDuration/2
// Technical indicator Bollinger Bands
length = input(20, title="Length")
mult = input(2, title="Multiplier")
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
// Technical pattern
techCondition = close[1] < basis[1] - dev[1] and close > basis - dev
// Check if there are open positions
openTrades = strategy.opentrades
// Entry condition
longCondition = (techCondition) and time >= sensitiveWindowStart and time <= sensitiveWindowEnd
// Exit conditions
seasonalWindowExpired = time >= seasonalWindowEnd
// Strategy logic
if (longCondition and openTrades == 0)
strategy.entry("Long", strategy.long)
if (seasonalWindowExpired)
strategy.close("Long")
I am learning Pinescript and I am trying to build a simple strategy that, given in input a start date (day and month) and a window duration, defines a "sensitive area" (e.g. from 15 days before the start to the half of the seasonal window). Then, in this sensitive area it checks if there is a technical pattern (a crossover of the upper BB in this case) and if yes, then enters long.
It is obviously for learning purposes, I will not trade this.
The strategy compiles but then when i go to the strategy tester it says that there is no case in which the strategy enters. It seems to me impossible, and i tried with many commodity ETFs such as CORN, USO, WHEAT, UNG etc
Can you help me to find the mistake? I am trying for instance with these parameters on ETF CORN: 1st of June start, window duration 30 days, entry tolerance 15 days. Technical condition: crossover on the upper Bollinger band
Here is the code. I havemade a bit alone and a bit with chatGPT support.
Thanks a lot for your kind support
******
//@version=5
strategy("Test Seasonality", shorttitle="Test Seasonality", overlay=true)
// Input
startDay = input(1, title="Start Day")
startMonth = input(6, title="Start Month")
windowDuration = input(30, title="Window Duration")
entryTolerance = input(15, title="Entry Tolerance")
// Computation of seasonal window and sensitive window
seasonalWindowStart = timestamp(year, startMonth, startDay)
seasonalWindowEnd = seasonalWindowStart + windowDuration
sensitiveWindowStart = seasonalWindowStart - entryTolerance
sensitiveWindowEnd = sensitiveWindowStart + windowDuration/2
// Technical indicator Bollinger Bands
length = input(20, title="Length")
mult = input(2, title="Multiplier")
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
// Technical pattern
techCondition = close[1] < basis[1] - dev[1] and close > basis - dev
// Check if there are open positions
openTrades = strategy.opentrades
// Entry condition
longCondition = (techCondition) and time >= sensitiveWindowStart and time <= sensitiveWindowEnd
// Exit conditions
seasonalWindowExpired = time >= seasonalWindowEnd
// Strategy logic
if (longCondition and openTrades == 0)
strategy.entry("Long", strategy.long)
if (seasonalWindowExpired)
strategy.close("Long")
thanks