100% found this document useful (1 vote)
193 views29 pages

Tests to find the best AI for trading strategies

The document outlines various AI models tested for trading strategies, specifically focusing on the Bollinger Bands strategy in PineScript v6. It provides detailed instructions for converting a TradingView indicator into a strategy, including trading logic, date range inputs, and specific coding practices to follow. Additionally, it includes example codes from different AI models that successfully implement the Bollinger Bands strategy with the specified requirements.

Uploaded by

Jim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
193 views29 pages

Tests to find the best AI for trading strategies

The document outlines various AI models tested for trading strategies, specifically focusing on the Bollinger Bands strategy in PineScript v6. It provides detailed instructions for converting a TradingView indicator into a strategy, including trading logic, date range inputs, and specific coding practices to follow. Additionally, it includes example codes from different AI models that successfully implement the Bollinger Bands strategy with the specified requirements.

Uploaded by

Jim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 29

Tests to find the best AI for trading strategies

My Michael Ionita

Easy Prompt
ChatGPT o1 Code
Claude 3.5 Code
HorizonAI Code
Gemini 1.5 Pro
DeepSeek R1 Code
Medium Prompt
ChatGPT o1 Code
Claude 3.5 Code
HorizonAI Code
Gemini 1.5 Pro Code
DeepSeek R1 Code
Hard Prompt v1
ChatGPT o1 Code
Claude 3.5 Code
HorizonAI Code
Gemini 1.5 Pro Code
DeepSeek R1 Code
Hard Prompt v2
ChatGPT o1 Code
Claude 3.5 Code
HorizonAI Code
Gemini 1.5 Pro Code
DeepSeek R1 Code

Easy Prompt
You are a professional PineScript v6 developer.
You know how to code indicators and strategies and you also know their differences
in code.
I need your help to turn a TradingView indicator into a strategy please.

When to buy and when to sell:


- Go long when price closes above the upper Bollinger Band.
- Close long when price closed below the lower Bollinger Band.

Respect these instructions:


- Convert all Indicator specific code to Strategy specific code. Don't use any code
that a TradingView Strategy won't support. Especially timeframes and gaps. Define
those in code so they are semantically the same as before.
- Preserve the timeframe logic if there is one. Fill gaps.
- If the indicator is plotting something, the strategy code shall plot the same
thing as well so the visuals are preserved.
- Don't trigger a short. Simply go Long and Flat.
- Always use 100% of capital.
- Set commission to 0.1%.
- Set slippage to 0.
- strategy.commission.percent and strategy.slippage don't exist in PineScript.
Please avoid this mistake. Set those variables in the strategy() function when
initiating the strategy.
- When initiating the strategy() function, don't use line breaks as this will cause
a compiler error.
- Leave all other strategy settings to default values (aka. don't set them at all).
- Never use lookahead_on because that’s cheating.
- Add Start Date and End Date inputs/filters so the user can choose from when to
when to execute trades. Start with 1st January 2018 and go to 31st December 2069.
- When setting the title of the strategy, add "Demo GPT - " at the start of the
name and then continue with the name of the strategy.

This is the code of the Indicator you shall migrate to a TradingView Strategy:
//@version=5
indicator(shorttitle="BB", title="Bollinger Bands", overlay=true, timeframe="",
timeframe_gaps=true)
length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

ma(source, length, _type) =>


switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

basis = ma(src, length, maType)


dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500, display =
display.data_window)
plot(basis, "Basis", color=#2962FF, offset = offset)
p1 = plot(upper, "Upper", color=#F23645, offset = offset)
p2 = plot(lower, "Lower", color=#089981, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
ChatGPT o1 Code
//@version=5
strategy(title="Demo GPT - Bollinger Bands", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Inputs
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval = -500, maxval = 500, display =
display.data_window)

// Date range inputs


startDate = input.time(timestamp("2018-01-01"), title="Start Date")
endDate = input.time(timestamp("2069-12-31"), title="End Date")

// Basis MA function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Calculate Bollinger Bands
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// Plot the bands


plot(basis, "Basis", color=#2962FF, offset=offset)
p1 = plot(upper, "Upper", color=#F23645, offset=offset)
p2 = plot(lower, "Lower", color=#089981, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))

// Trading logic: Only execute trades within the selected date range
inDateRange = time >= startDate and time <= endDate

longCondition = close > upper and inDateRange


exitCondition = close < lower and inDateRange

if longCondition and strategy.position_size <= 0


strategy.entry("Long", strategy.long)

if exitCondition and strategy.position_size > 0


strategy.close("Long")
Claude 3.5 Code
//@version=5
strategy("Demo GPT - Bollinger Bands Strategy", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Date Range Inputs


startDate = input.time(timestamp("2018-01-01"), "Start Date")
endDate = input.time(timestamp("2069-12-31"), "End Date")

// BB Inputs
length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)",
"WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

// MA Function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

// Calculate BB values
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// Plotting (preserved from indicator)


offset = input.int(0, "Offset", minval=-500, maxval=500,
display=display.data_window)
plot(basis, "Basis", color=#2962FF, offset=offset)
p1 = plot(upper, "Upper", color=#F23645, offset=offset)
p2 = plot(lower, "Lower", color=#089981, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))

// Trading conditions
longCondition = ta.crossover(close, upper)
exitLongCondition = ta.crossunder(close, lower)

// Execute trades within date range


if time >= startDate and time <= endDate
if longCondition
strategy.entry("Long", strategy.long)
if exitLongCondition
strategy.close("Long")
HorizonAI Code
//@version=5
strategy("Demo GPT - Bollinger Bands Strategy", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Date Inputs
startDate = input.time(timestamp("1 January 2018 00:00 +0000"), "Start Date")
endDate = input.time(timestamp("31 Dec 2069 23:59 +0000"), "End Date")
timeCondition = time >= startDate and time <= endDate

// BB Inputs
length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval = -500, maxval = 500, display =
display.data_window)

// MA Function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

// Calculate BB
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// Plotting
plot(basis, "Basis", color=#2962FF, offset = offset)
p1 = plot(upper, "Upper", color=#F23645, offset = offset)
p2 = plot(lower, "Lower", color=#089981, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

// Strategy Logic
longCondition = close > upper and timeCondition
exitLongCondition = close < lower and timeCondition

if (longCondition)
strategy.entry("BB Long", strategy.long)

if (exitLongCondition)
strategy.close("BB Long")
Gemini 1.5 Pro
//@version=5
strategy(title="Demo GPT - Bollinger Bands Strategy", overlay=true,
margin_long=100, margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Inputs
length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval = -500, maxval = 500, display =
display.data_window)
startDate = input.time(timestamp("2018-01-01"), title="Start Date")
endDate = input.time(timestamp("2069-12-31"), title="End Date")

// Time filter
time_cond = time >= startDate and time <= endDate

// MA function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

// Bollinger Band calculations


basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// Entry and exit conditions


longCondition = ta.crossover(close, upper)
closeLongCondition = ta.crossunder(close, lower)

// Entry and exit orders


if time_cond
if (longCondition)
strategy.entry("Long", strategy.long)
if (strategy.position_size > 0 and closeLongCondition)
strategy.close("Long")

// Plotting
plot(basis, "Basis", color=#2962FF, offset = offset)
p1 = plot(upper, "Upper", color=#F23645, offset = offset)
p2 = plot(lower, "Lower", color=#089981, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
DeepSeek R1 Code
//@version=5
strategy(shorttitle="BB Strategy", title="Demo GPT - Bollinger Bands Strategy",
overlay=true, commission_type=strategy.commission.percent, commission_value=0.1,
slippage=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// Inputs
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval = -500, maxval = 500)

// Date Range Filter


startDate = input.time(title="Start Date", defval=timestamp("2018-01-01"),
confirm=false)
endDate = input.time(title="End Date", defval=timestamp("2069-12-31"),
confirm=false)
timeAllowed = time >= startDate and time <= endDate

// MA Type Selector
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

// Calculations
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// Preserve Indicator Plots


plot(basis, "Basis", color=#2962FF, offset=offset)
p1 = plot(upper, "Upper", color=#F23645, offset=offset)
p2 = plot(lower, "Lower", color=#089981, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))

// Strategy Logic
enterLong = ta.crossover(close, upper) and timeAllowed
exitLong = ta.crossunder(close, lower) and timeAllowed

if enterLong
strategy.entry("Long", strategy.long)
if exitLong
strategy.close("Long")

Medium Prompt
You are a professional PineScript v6 developer.
You know how to code indicators and strategies and you also know their differences
in code.
I need your help to improve this TradingView strategy please.
Add this indicator to this strategy and remove the plots and fills it has:
//@version=5
indicator(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price,
precision=2, timeframe="", timeframe_gaps=true)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")

Now improve the strategy like so:


- Open long position as soon as the gaussian channel is green, the close price is
above the high gaussian channel band and when the Stochastic RSI is above 80 or
below 20.
- Close long positions when the close price crosses the high gaussian channel band
to the downside.

Respect these instructions:


- For the indicator we are adding, preserve the timeframe logic it has if there is
one, fill gaps whenever possible.
- Keep all existing plots & visuals (don't remove them).
- Don't trigger a short. Simply go Long and Flat.
- Always use 100% of capital.
- Set commission to 0.1%.
- Set slippage to 0.
- strategy.commission.percent and strategy.slippage don't exist in PineScript.
Please avoid this mistake. Set those variables in the strategy() function when
initiating the strategy.
- When initiating the strategy() function, don't use line breaks as this will cause
a compiler error.
- Leave all other strategy settings to default values (aka. don't set them at all).
- Never use lookahead_on because that’s cheating.
- Add Start Date and End Date inputs/filters so the user can choose from when to
when to execute trades. Start with 1st January 2018 and go to 31st December 2069.
- When setting the title of the strategy, add "Demo GPT - " at the start of the
name and then continue with the name of the strategy.

This is the code of the TradingView Strategy to improve with the instructions
above:
//@version=5
strategy(title="Gaussian Channel Strategy v3.0", overlay=true,
calc_on_every_tick=false, initial_capital=1000,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
commission_type=strategy.commission.percent, commission_value=0.1, slippage=3,
fill_orders_on_standard_ohlc=true)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Gaussian Channel Indicator - courtesy of @DonovanWall
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Date condition inputs


startDate = input.time(timestamp("1 January 2018 00:00 +0000"), "Start Date",
group="Main Algo Settings")
endDate = input.time(timestamp("31 Dec 2069 23:59 +0000"), "End Date", group="Main
Algo Settings")
timeCondition = time >= startDate and time <= endDate

// This study is an experiment utilizing the Ehlers Gaussian Filter technique


combined with lag reduction techniques and true range to analyze trend activity.
// Gaussian filters, as Ehlers explains it, are simply exponential moving averages
applied multiple times.
// First, beta and alpha are calculated based on the sampling period and number of
poles specified. The maximum number of poles available in this script is 9.
// Next, the data being analyzed is given a truncation option for reduced lag,
which can be enabled with "Reduced Lag Mode".
// Then the alpha and source values are used to calculate the filter and filtered
true range of the dataset.
// Filtered true range with a specified multiplier is then added to and subtracted
from the filter, generating a channel.
// Lastly, a one pole filter with a N pole alpha is averaged with the filter to
generate a faster filter, which can be enabled with "Fast Response Mode".

// Custom bar colors are included.

// Note: Both the sampling period and number of poles directly affect how much lag
the indicator has, and how smooth the output is.
// Larger inputs will result in smoother outputs with increased lag, and
smaller inputs will have noisier outputs with reduced lag.
// For the best results, I recommend not setting the sampling period any lower
than the number of poles + 1. Going lower truncates the equation.

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Updates:
// Huge shoutout to @e2e4mfck for taking the time to improve the calculation
method!
// -> migrated to v4
// -> pi is now calculated using trig identities rather than being explicitly
defined.
// -> The filter calculations are now organized into functions rather than being
individually defined.
// -> Revamped color scheme.

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Functions - courtesy of @e2e4mfck
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Filter function
f_filt9x (_a, _s, _i) =>
int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0,
int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = .0, _x = (1 - _a)
// Weights.
// Initial weight _m1 is a pole number and equal to _i
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ?
10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ?
10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5
: _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1
: 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
// filter
_f := math.pow(_a, _i) * nz(_s) +
_i * _x * nz(_f[1]) - (_i >= 2 ?
_m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ?
_m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ?
_m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ?
_m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ?
_m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ?
_m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ?
_m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ?
_m9 * math.pow(_x, 9) * nz(_f[9]) : 0)

// 9 var declaration fun


f_pole (_a, _s, _i) =>
_f1 = f_filt9x(_a, _s, 1), _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2)
: 0), _f3 = (_i >= 3 ? f_filt9x(_a, _s, 3) : 0)
_f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5)
: 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0)
_f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8)
: 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0)
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 :
_i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 :
_i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Source
src = input(defval=hlc3, title="Source")

// Poles
int N = input.int(defval=4, title="Poles", minval=1, maxval=9)

// Period
int per = input.int(defval=144, title="Sampling Period", minval=2)

// True Range Multiplier


float mult = input.float(defval=1.414, title="Filtered True Range Multiplier",
minval=0)

// Lag Reduction
bool modeLag = input.bool(defval=false, title="Reduced Lag Mode")
bool modeFast = input.bool(defval=false, title="Fast Response Mode")
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Beta and Alpha Components


beta = (1 - math.cos(4*math.asin(1)/per)) / (math.pow(1.414, 2/N) - 1)
alpha = - beta + math.sqrt(math.pow(beta, 2) + 2*beta)

// Lag
lag = (per - 1)/(2*N)

// Data
srcdata = modeLag ? src + (src - src[lag]) : src
trdata = modeLag ? ta.tr(true) + (ta.tr(true) - ta.tr(true)[lag]) : ta.tr(true)

// Filtered Values
[filtn, filt1] = f_pole(alpha, srcdata, N)
[filtntr, filt1tr] = f_pole(alpha, trdata, N)

// Lag Reduction
filt = modeFast ? (filtn + filt1)/2 : filtn
filttr = modeFast ? (filtntr + filt1tr)/2 : filtntr

// Bands
hband = filt + filttr*mult
lband = filt - filttr*mult

// Colors
color1 = #0aff68
color2 = #00752d
color3 = #ff0a5a
color4 = #990032
fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
barcolor = (src > src[1]) and (src > filt) and (src < hband) ? #0aff68 : (src >
src[1]) and (src >= hband) ? #0aff1b : (src <= src[1]) and (src > filt) ? #00752d :
(src < src[1]) and (src < filt) and (src > lband) ? #ff0a5a : (src <
src[1]) and (src <= lband) ? #ff0a11 : (src >= src[1]) and (src < filt) ? #990032 :
#cccccc

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Outputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// Filter Plot
filtplot = plot(filt, title="Filter", color=fcolor, linewidth=3)

// Band Plots
hbandplot = plot(hband, title="Filtered True Range High Band", color=fcolor)
lbandplot = plot(lband, title="Filtered True Range Low Band", color=fcolor)

// Channel Fill
fill(hbandplot, lbandplot, title="Channel Fill", color=color.new(fcolor, 80))

// Bar Color
barcolor(barcolor)
// Trading Logic
longCondition = ta.crossover(close, hband) and timeCondition
closeAllCondition = ta.crossunder(close, hband) and timeCondition

if longCondition
strategy.entry("long", strategy.long)

if closeAllCondition
strategy.close("long")
ChatGPT o1 Code
//@version=5
strategy(title="Demo GPT - Gaussian Channel Strategy v3.0", overlay=true,
margin_long=100, margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Date condition inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
startDate = input.time(timestamp("1 January 2018 00:00 +0000"), "Start Date",
inline="dt")
endDate = input.time(timestamp("31 Dec 2069 23:59 +0000"), "End Date",
inline="dt")
timeCondition = time >= startDate and time <= endDate

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Stochastic RSI Integration (from provided indicator) - without its plots/fills
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
rsiSrc = input.source(close, "RSI Source")

rsi1 = ta.rsi(rsiSrc, lengthRSI)


k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
// Stoch RSI plots and fills removed as instructed

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Gaussian Channel Indicator - courtesy of @DonovanWall
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------

// This study uses Ehlers Gaussian Filter technique combined with lag reduction and
true range to analyze trend activity.

// Functions - courtesy of @e2e4mfck


f_filt9x (_a, _s, _i) =>
int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0,
int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = .0, _x = (1 - _a)
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ?
10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ?
10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5
: _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1
: 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
_f := math.pow(_a, _i)*nz(_s)
+ _i * _x * nz(_f[1])
- (_i >= 2 ? _m2*math.pow(_x, 2)*nz(_f[2]) : 0)
+ (_i >= 3 ? _m3*math.pow(_x, 3)*nz(_f[3]) : 0)
- (_i >= 4 ? _m4*math.pow(_x, 4)*nz(_f[4]) : 0)
+ (_i >= 5 ? _m5*math.pow(_x, 5)*nz(_f[5]) : 0)
- (_i >= 6 ? _m6*math.pow(_x, 6)*nz(_f[6]) : 0)
+ (_i >= 7 ? _m7*math.pow(_x, 7)*nz(_f[7]) : 0)
- (_i >= 8 ? _m8*math.pow(_x, 8)*nz(_f[8]) : 0)
+ (_i == 9 ? _m9*math.pow(_x, 9)*nz(_f[9]) : 0)

f_pole (_a, _s, _i) =>


_f1 = f_filt9x(_a, _s, 1), _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2) : 0), _f3
= (_i >= 3 ? f_filt9x(_a, _s, 3) : 0)
_f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5)
: 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0)
_f7 = (_i >= 7 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8)
: 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0)
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 :
_i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 :
_i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
src = input(defval=hlc3, title="Source")
int N = input.int(defval=4, title="Poles", minval=1, maxval=9)
int per = input.int(defval=144, title="Sampling Period", minval=2)
float mult = input.float(defval=1.414, title="Filtered True Range Multiplier",
minval=0)
bool modeLag = input.bool(defval=false, title="Reduced Lag Mode")
bool modeFast = input.bool(defval=false, title="Fast Response Mode")

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
beta = (1 - math.cos(4*math.asin(1)/per)) / (math.pow(1.414, 2/N) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2*beta)
lag = (per - 1)/(2*N)

// Data
srcdata = modeLag ? src + (src - src[lag]) : src
trdata = modeLag ? ta.tr(true) + (ta.tr(true) - ta.tr(true)[lag]) : ta.tr(true)
// Filtered Values
[filtn, filt1] = f_pole(alpha, srcdata, N)
[filtntr, filt1tr] = f_pole(alpha, trdata, N)
filt = modeFast ? (filtn + filt1)/2 : filtn
filttr = modeFast ? (filtntr + filt1tr)/2 : filtntr

// Bands
hband = filt + filttr*mult
lband = filt - filttr*mult

// Colors
fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
barcolor = (src > src[1]) and (src > filt) and (src < hband) ? #0aff68 :
(src > src[1]) and (src >= hband) ? #0aff1b :
(src <= src[1]) and (src > filt) ? #00752d :
(src < src[1]) and (src < filt) and (src > lband) ? #ff0a5a :
(src < src[1]) and (src <= lband) ? #ff0a11 :
(src >= src[1]) and (src < filt) ? #990032 : #cccccc

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Outputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
filtplot = plot(filt, title="Filter", color=fcolor, linewidth=3)
hbandplot = plot(hband, title="Filtered True Range High Band", color=fcolor)
lbandplot = plot(lband, title="Filtered True Range Low Band", color=fcolor)
fill(hbandplot, lbandplot, title="Channel Fill", color=color.new(fcolor, 80))
barcolor(barcolor)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Trading Logic
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Conditions:
// - Open long if timeCondition, gaussian channel is green (filt > filt[1]), close
> hband, and Stoch RSI > 80 or < 20
// - Close long if close crosses hband to the downside
longCondition = timeCondition and (filt > filt[1]) and (close > hband) and ((k >
80) or (k < 20))
closeAllCondition = timeCondition and ta.crossunder(close, hband)

if longCondition
strategy.entry("long", strategy.long)

if closeAllCondition
strategy.close("long")
Claude 3.5 Code
//@version=5
strategy(title="Demo GPT - Gaussian Channel with Stoch RSI Strategy",
overlay=true, margin_long=100, margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Date inputs
startDate = input.time(timestamp("1 January 2018 00:00 +0000"), "Start Date",
group="Main Algo Settings")
endDate = input.time(timestamp("31 Dec 2069 23:59 +0000"), "End Date", group="Main
Algo Settings")
timeCondition = time >= startDate and time <= endDate

// Stochastic RSI Inputs


smoothK = input.int(3, "Stoch RSI K", minval=1, group="Stoch RSI Settings")
smoothD = input.int(3, "Stoch RSI D", minval=1, group="Stoch RSI Settings")
lengthRSI = input.int(14, "RSI Length", minval=1, group="Stoch RSI Settings")
lengthStoch = input.int(14, "Stochastic Length", minval=1, group="Stoch RSI
Settings")
rsiSource = input(close, title="RSI Source", group="Stoch RSI Settings")

// Calculate Stochastic RSI


rsi1 = ta.rsi(rsiSource, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

// Gaussian Channel Functions


f_filt9x(_a, _s, _i) =>
int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0,
int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = .0, _x = (1 - _a)
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ?
10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ?
10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5
: _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1
: 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
_f := math.pow(_a, _i) * nz(_s) +
_i * _x * nz(_f[1]) - (_i >= 2 ?
_m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ?
_m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ?
_m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ?
_m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ?
_m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ?
_m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ?
_m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ?
_m9 * math.pow(_x, 9) * nz(_f[9]) : 0)

f_pole(_a, _s, _i) =>


_f1 = f_filt9x(_a, _s, 1), _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2)
: 0), _f3 = (_i >= 3 ? f_filt9x(_a, _s, 3) : 0)
_f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5)
: 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0)
_f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8)
: 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0)
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 :
_i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 :
_i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]

// Gaussian Channel Inputs


src = input(hlc3, title="Source", group="Gaussian Channel Settings")
N = input.int(4, title="Poles", minval=1, maxval=9, group="Gaussian Channel
Settings")
per = input.int(144, title="Sampling Period", minval=2, group="Gaussian Channel
Settings")
mult = input.float(1.414, title="Filtered True Range Multiplier", minval=0,
group="Gaussian Channel Settings")
modeLag = input.bool(false, title="Reduced Lag Mode", group="Gaussian Channel
Settings")
modeFast = input.bool(false, title="Fast Response Mode", group="Gaussian Channel
Settings")

// Gaussian Channel Calculations


beta = (1 - math.cos(4*math.asin(1)/per)) / (math.pow(1.414, 2/N) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2*beta)
lag = (per - 1)/(2*N)
srcdata = modeLag ? src + (src - src[lag]) : src
trdata = modeLag ? ta.tr(true) + (ta.tr(true) - ta.tr(true)[lag]) : ta.tr(true)
[filtn, filt1] = f_pole(alpha, srcdata, N)
[filtntr, filt1tr] = f_pole(alpha, trdata, N)
filt = modeFast ? (filtn + filt1)/2 : filtn
filttr = modeFast ? (filtntr + filt1tr)/2 : filtntr
hband = filt + filttr*mult
lband = filt - filttr*mult

// Colors
color1 = #0aff68
color2 = #00752d
color3 = #ff0a5a
color4 = #990032
fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
barcolor = (src > src[1]) and (src > filt) and (src < hband) ? #0aff68 : (src >
src[1]) and (src >= hband) ? #0aff1b : (src <= src[1]) and (src > filt) ? #00752d :
(src < src[1]) and (src < filt) and (src > lband) ? #ff0a5a : (src <
src[1]) and (src <= lband) ? #ff0a11 : (src >= src[1]) and (src < filt) ? #990032 :
#cccccc

// Plotting
filtplot = plot(filt, title="Filter", color=fcolor, linewidth=3)
hbandplot = plot(hband, title="Filtered True Range High Band", color=fcolor)
lbandplot = plot(lband, title="Filtered True Range Low Band", color=fcolor)
fill(hbandplot, lbandplot, title="Channel Fill", color=color.new(fcolor, 80))
barcolor(barcolor)

// Trading Conditions
isGreenChannel = filt > filt[1]
isPriceAboveHighBand = close > hband
isStochExtreme = k >= 80 or k <= 20
longCondition = isGreenChannel and isPriceAboveHighBand and isStochExtreme and
timeCondition
closeAllCondition = ta.crossunder(close, hband) and timeCondition

// Strategy Execution
if longCondition
strategy.entry("long", strategy.long)

if closeAllCondition
strategy.close("long")
HorizonAI Code
//@version=5
strategy(title="Demo GPT - Gaussian Channel with Stoch RSI Strategy", overlay=true,
margin_long=100, margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Date condition inputs


startDate = input.time(timestamp("1 January 2018 00:00 +0000"), "Start Date",
group="Main Algo Settings")
endDate = input.time(timestamp("31 Dec 2069 23:59 +0000"), "End Date", group="Main
Algo Settings")
timeCondition = time >= startDate and time <= endDate

// Stochastic RSI Inputs


smoothK = input.int(3, "K", minval=1, group="Stoch RSI Settings")
smoothD = input.int(3, "D", minval=1, group="Stoch RSI Settings")
lengthRSI = input.int(14, "RSI Length", minval=1, group="Stoch RSI Settings")
lengthStoch = input.int(14, "Stochastic Length", minval=1, group="Stoch RSI
Settings")
rsiSource = input(close, title="RSI Source", group="Stoch RSI Settings")

// Calculate Stochastic RSI


rsi1 = ta.rsi(rsiSource, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

// Gaussian Channel Settings


src = input(hlc3, title="Source", group="Gaussian Channel Settings")
N = input.int(4, "Poles", minval=1, maxval=9, group="Gaussian Channel Settings")
per = input.int(144, "Sampling Period", minval=2, group="Gaussian Channel
Settings")
mult = input.float(1.414, "Filtered True Range Multiplier", minval=0,
group="Gaussian Channel Settings")
modeLag = input.bool(false, "Reduced Lag Mode", group="Gaussian Channel Settings")
modeFast = input.bool(false, "Fast Response Mode", group="Gaussian Channel
Settings")

// Gaussian Channel Functions


f_filt9x(_a, _s, _i) =>
int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0,
int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = .0, _x = (1 - _a)
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ?
10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ?
10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5
: _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1
: 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
_f := math.pow(_a, _i) * nz(_s) +
_i * _x * nz(_f[1]) - (_i >= 2 ?
_m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ?
_m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ?
_m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ?
_m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ?
_m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ?
_m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ?
_m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ?
_m9 * math.pow(_x, 9) * nz(_f[9]) : 0)

f_pole(_a, _s, _i) =>


_f1 = f_filt9x(_a, _s, 1), _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2) : 0), _f3 = (_i
>= 3 ? f_filt9x(_a, _s, 3) : 0)
_f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5)
: 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0)
_f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8)
: 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0)
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 :
_i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 :
_i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]

// Gaussian Channel Calculations


beta = (1 - math.cos(4*math.asin(1)/per)) / (math.pow(1.414, 2/N) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2*beta)
lag = (per - 1)/(2*N)

srcdata = modeLag ? src + (src - src[lag]) : src


trdata = modeLag ? ta.tr(true) + (ta.tr(true) - ta.tr(true)[lag]) : ta.tr(true)

[filtn, filt1] = f_pole(alpha, srcdata, N)


[filtntr, filt1tr] = f_pole(alpha, trdata, N)

filt = modeFast ? (filtn + filt1)/2 : filtn


filttr = modeFast ? (filtntr + filt1tr)/2 : filtntr

hband = filt + filttr*mult


lband = filt - filttr*mult

// Colors
fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
isGreen = filt > filt[1]

// Plots
plot(filt, "Filter", color=fcolor, linewidth=3)
hbandplot = plot(hband, "High Band", color=fcolor)
lbandplot = plot(lband, "Low Band", color=fcolor)
fill(hbandplot, lbandplot, color=color.new(fcolor, 80))

// Trading Conditions
stochSignal = k > 80 or k < 20
longCondition = isGreen and close > hband and stochSignal and timeCondition
closeCondition = ta.crossunder(close, hband) and timeCondition

// Execute Strategy
if longCondition
strategy.entry("Long", strategy.long)

if closeCondition
strategy.close("Long")
Gemini 1.5 Pro Code
Only got errors :(
DeepSeek R1 Code
//@version=5
strategy(title="Demo GPT - Gaussian Channel Strategy v3.0", overlay=true,
calc_on_every_tick=false, initial_capital=1000,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
commission_type=strategy.commission.percent, commission_value=0.1, slippage=0,
fill_orders_on_standard_ohlc=true)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Gaussian Filter Functions (Must be declared first)
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
f_filt9x(_a, _s, _i) =>
var int _m2 = 0, var int _m3 = 0, var int _m4 = 0, var int _m5 = 0, var int _m6
= 0,
var int _m7 = 0, var int _m8 = 0, var int _m9 = 0, var float _f = .0
_x = 1 - _a
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ?
10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ?
10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5
: _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1
: 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
_f := math.pow(_a, _i) * nz(_s) + _i * _x * nz(_f[1]) - (_i >= 2 ? _m2 *
math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ? _m3 * math.pow(_x, 3) * nz(_f[3]) :
0) - (_i >= 4 ? _m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ? _m5 *
math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ? _m6 * math.pow(_x, 6) * nz(_f[6]) :
0) + (_i >= 7 ? _m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ? _m8 *
math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ? _m9 * math.pow(_x, 9) * nz(_f[9]) :
0)

f_pole(_a, _s, _i) =>


_f1 = f_filt9x(_a, _s, 1)
_f2 = _i >= 2 ? f_filt9x(_a, _s, 2) : 0.0
_f3 = _i >= 3 ? f_filt9x(_a, _s, 3) : 0.0
_f4 = _i >= 4 ? f_filt9x(_a, _s, 4) : 0.0
_f5 = _i >= 5 ? f_filt9x(_a, _s, 5) : 0.0
_f6 = _i >= 6 ? f_filt9x(_a, _s, 6) : 0.0
_f7 = _i >= 7 ? f_filt9x(_a, _s, 7) : 0.0
_f8 = _i >= 8 ? f_filt9x(_a, _s, 8) : 0.0
_f9 = _i == 9 ? f_filt9x(_a, _s, 9) : 0.0
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 : _i == 4 ? _f4 : _i == 5 ?
_f5 : _i == 6 ? _f6 : _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Date Range
startDate = input.time(timestamp("1 January 2018 00:00 +0000"), "Start Date",
group="Main Settings")
endDate = input.time(timestamp("31 Dec 2069 23:59 +0000"), "End Date", group="Main
Settings")
timeCondition = time >= startDate and time <= endDate
// Gaussian Channel
int poles = input.int(4, "Poles", 1, 9, group="Gaussian Channel")
int period = input.int(144, "Sampling Period", 2, group="Gaussian Channel")
float mult = input.float(1.414, "True Range Multiplier", group="Gaussian Channel")
bool reducedLag = input.bool(false, "Reduced Lag Mode", group="Gaussian Channel")
bool fastResponse = input.bool(false, "Fast Response Mode", group="Gaussian
Channel")

// Stochastic RSI
smoothK = input.int(3, "K", 1, group="Stochastic RSI")
smoothD = input.int(3, "D", 1, group="Stochastic RSI")
lengthRSI = input.int(14, "RSI Length", 1, group="Stochastic RSI")
lengthStoch = input.int(14, "Stochastic Length", 1, group="Stochastic RSI")

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Calculations
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Gaussian Channel
beta = (1 - math.cos(4*math.asin(1)/period)) / (math.pow(1.414, 2/poles) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2*beta)
lag = (period - 1)/(2*poles)

src = hlc3
srcData = reducedLag ? src + (src - src[lag]) : src
trData = reducedLag ? ta.tr + (ta.tr - ta.tr[lag]) : ta.tr

[filterMain, filter1] = f_pole(alpha, srcData, poles)


[filterTRMain, filterTR1] = f_pole(alpha, trData, poles)

finalFilter = fastResponse ? (filterMain + filter1)/2 : filterMain


finalTR = fastResponse ? (filterTRMain + filterTR1)/2 : filterTRMain

hband = finalFilter + finalTR * mult


lband = finalFilter - finalTR * mult

// Stochastic RSI
rsi = ta.rsi(close, lengthRSI)
k = ta.sma(ta.stoch(rsi, rsi, rsi, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Trading Logic
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
gaussianGreen = finalFilter > finalFilter[1]
priceAbove = close > hband
stochCondition = k > 80 or k < 20

longCondition = gaussianGreen and priceAbove and stochCondition and timeCondition


exitCondition = ta.crossunder(close, hband) and timeCondition

strategy.entry("Long", strategy.long, when=longCondition)


strategy.close("Long", when=exitCondition)

//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Visuals
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
filterColor = finalFilter > finalFilter[1] ? #0aff68 : #ff0a5a
plot(finalFilter, "Filter", filterColor, 2)
plot(hband, "High Band", filterColor)
plot(lband, "Low Band", filterColor)
fill(plot(hband), plot(lband), color.new(filterColor, 90), "Channel Fill")

Hard Prompt v1
I’d like you to create a PineScript v6 trading strategy based on the Gaussian
Channel and add Stochastic RSI to avoid bad trades. I want to be able to copy paste
it into TradingView, save it and it runs.
Long only, no shorting. Never use lookahead_on. Always trade with 100% of equity.
0.1% commission. 0 ticks slippage. Start trading on 2018-01-01 until 2069-01-01.
Avoid compiler errors. Use only functions that exist and PineScript v5 supports.
ChatGPT o1 Code
//@version=5
strategy("Gaussian Channel Stoch RSI Strategy", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// User inputs
length = input.int(50, "Gaussian Length")
mult = input.float(2.0, "Channel Multiplier", step=0.1)
rsiLength = input.int(14, "RSI Length")
stochLength = input.int(14, "Stoch RSI Length")
kLength = input.int(3, "K Smoothing")
dLength = input.int(3, "D Smoothing")

// Calculate Gaussian-based moving average (approximation by cascaded SMAs)


f_gaussian(src, len) =>
sm1 = ta.sma(src, len)
sm2 = ta.sma(sm1, len)
sm3 = ta.sma(sm2, len)
sm4 = ta.sma(sm3, len)
// Weighted sum to approximate gaussian curve
(sm1 + 2*sm2 + 3*sm3 + 4*sm4) / (1+2+3+4)

gauss = f_gaussian(close, length)


std = ta.stdev(close, length)
up = gauss + std * mult
down = gauss - std * mult

// Stoch RSI Calculation


rsi = ta.rsi(close, rsiLength)
lowestRSI = ta.lowest(rsi, stochLength)
highestRSI = ta.highest(rsi, stochLength)
stochRsi = (rsi - lowestRSI) / (highestRSI - lowestRSI) * 100.0
k = ta.sma(stochRsi, kLength)
d = ta.sma(k, dLength)

// Conditions
bar_time = time
inDateRange = bar_time >= timestamp("2018-01-01T00:00:00") and bar_time <
timestamp("2069-01-01T00:00:00")

// Entry condition: For example, enter long when price breaks above upper band and
Stoch RSI is oversold (k < 20 and k < d)
enterLong = inDateRange and close > up and k < 20 and k < d

// Exit condition: For example, exit when price crosses below the gaussian midline
exitLong = inDateRange and close < gauss

// Strategy logic
if enterLong
strategy.entry("Long", strategy.long)

if exitLong
strategy.close("Long")
Claude 3.5 Code
//@version=5
strategy("Gaussian Channel with Stoch RSI Strategy", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Input parameters
len = input.int(20, "Gaussian Channel Length")
mult = input.float(2.0, "Channel Multiplier")
srcInput = input(close, "Source")

// Stoch RSI Parameters


rsiPeriod = input.int(14, "RSI Length")
stochPeriod = input.int(14, "Stochastic Length")
smoothK = input.int(3, "Smooth K")
smoothD = input.int(3, "Smooth D")
oversoldLevel = input.float(20, "Oversold Level")
overboughtLevel = input.float(80, "Overbought Level")

// Calculate Gaussian Channel


basis = ta.sma(srcInput, len)
dev = ta.stdev(srcInput, len)
upper = basis + dev * mult
lower = basis - dev * mult

// Calculate Stochastic RSI


rsi1 = ta.rsi(close, rsiPeriod)
stoch_rsi = ta.stoch(rsi1, rsi1, rsi1, stochPeriod)
k = ta.sma(stoch_rsi, smoothK)
d = ta.sma(k, smoothD)

// Plot indicators
plot(basis, "Basis", color=color.blue)
plot(upper, "Upper", color=color.red)
plot(lower, "Lower", color=color.red)

// Trading conditions
longCondition = ta.crossover(close, lower) and k < oversoldLevel
exitCondition = ta.crossunder(close, upper) or k > overboughtLevel

// Date range filter


inDateRange = time >= timestamp("2018-01-01") and time <= timestamp("2069-01-01")
// Execute trades
if inDateRange
if longCondition
strategy.entry("Long", strategy.long)
if exitCondition
strategy.close("Long")

// Plot trade signals


plotshape(longCondition, "Buy Signal", location=location.belowbar,
color=color.green, style=shape.triangleup, size=size.small)
plotshape(exitCondition, "Sell Signal", location=location.abovebar,
color=color.red, style=shape.triangledown, size=size.small)
HorizonAI Code
//@version=5
strategy("Gaussian Channel Strategy", overlay=true, initial_capital=10000,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
commission_type=strategy.commission.percent, commission_value=0.1)

// Date Range
start_date = timestamp("2018-01-01")
end_date = timestamp("2069-01-01")

// Gaussian Channel Parameters


length = input(20, "Channel Length")
mult = input(2.0, "Channel Multiplier")

// Calculate Gaussian Channel


basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev

// Stochastic RSI Parameters


rsi_length = input(14, "RSI Length")
stoch_length = input(14, "Stochastic Length")
smooth_k = input(3, "Smooth K")
smooth_d = input(3, "Smooth D")
oversold = input(20, "Oversold Level")
overbought = input(80, "Overbought Level")

// Calculate Stochastic RSI


rsi1 = ta.rsi(close, rsi_length)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, stoch_length), smooth_k)
d = ta.sma(k, smooth_d)

// Entry Conditions
long_condition = close > lower and close < upper and k < oversold and k > k[1]

// Plot Gaussian Channel


plot(basis, "Basis", color=color.blue)
plot(upper, "Upper", color=color.red)
plot(lower, "Lower", color=color.red)

// Trading Logic
if time >= start_date and time <= end_date
if long_condition
strategy.entry("Long", strategy.long)
if k > overbought
strategy.close("Long")

// Plot entry signals


plotshape(long_condition, "Long Entry", shape.triangleup, location.belowbar,
color.green, size=size.small)
Gemini 1.5 Pro Code
//@version=5
strategy("Gaussian Channel with Stochastic RSI", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Date range for trading


start_date = timestamp(2018, 1, 1, 0, 0)
end_date = timestamp(2069, 1, 1, 0, 0)

// Gaussian Channel Calculation


period = 20
mult = 2.0
src = close
basis = ta.sma(src, period)
dev = mult * ta.stdev(src, period)
upper = basis + dev
lower = basis - dev

// Stochastic RSI Calculation


lengthRSI = 14
lengthStoch = 14
smoothK = 3
smoothD = 3
rsi = ta.rsi(close, lengthRSI)
k = ta.sma(ta.stoch(rsi, rsi, rsi, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

// Entry and Exit Conditions


longCondition = close > lower and k > 20 and d > 20 and time >= start_date and time
<= end_date
exitCondition = close < basis or k < 80 and d < 80

// Check for date range


if time >= start_date and time <= end_date
// Entry
if longCondition
strategy.entry("Long", strategy.long)

// Exit
if strategy.position_size > 0 and exitCondition
strategy.close("Long")

// Plot Gaussian Channel


plot(basis, color=color.blue)
plot(upper, color=color.gray)
plot(lower, color=color.gray)

// Plot Stochastic RSI


plot(k, color=color.orange)
plot(d, color=color.purple)
// Plot Buy/Sell Signals for visualization
plotshape(longCondition, style=shape.triangleup, color=color.green,
location=location.belowbar, size=size.small)
plotshape(exitCondition and strategy.position_size > 0, style=shape.triangledown,
color=color.red, location=location.abovebar, size=size.small)
DeepSeek R1 Code
//@version=5
strategy("Gaussian Channel with Stochastic RSI", overlay=true,
initial_capital=10000, default_qty_type=strategy.percent_of_equity,
default_qty_value=100, commission_type=strategy.commission.percent,
commission_value=0.1, slippage=0)

// Gaussian Channel Parameters


gc_length = input.int(20, "Gaussian Channel Length", minval=1)
gc_mult = input.float(2.0, "Gaussian Channel Multiplier", minval=0.1)

middle = ta.ema(close, gc_length)


stdev = ta.stdev(close, gc_length)
upper = middle + gc_mult * stdev
lower = middle - gc_mult * stdev

// Plot Channels
plot(middle, "Middle Line", color=color.blue)
plot(upper, "Upper Channel", color=color.red)
plot(lower, "Lower Channel", color=color.green)

// Stochastic RSI Parameters


rsi_length = input.int(14, "RSI Length", minval=1)
stoch_length = input.int(14, "Stochastic Length", minval=1)
smooth_k = input.int(3, "Smooth %K", minval=1)
oversold = input.int(20, "Oversold Level", minval=0, maxval=100)
overbought = input.int(80, "Overbought Level", minval=0, maxval=100)

// Calculate Stochastic RSI


rsi = ta.rsi(close, rsi_length)
lowest_rsi = ta.lowest(rsi, stoch_length)
highest_rsi = ta.highest(rsi, stoch_length)
stoch_rsi = highest_rsi != lowest_rsi ? (rsi - lowest_rsi) / (highest_rsi -
lowest_rsi) * 100 : 0
k = ta.sma(stoch_rsi, smooth_k)

// Entry/Exit Conditions
enterLong = ta.crossover(close, lower) and ta.crossover(k, oversold)
exitLong = ta.crossover(close, upper) or ta.crossunder(k, overbought)

// Strategy Execution
if (time >= timestamp(2018, 01, 01, 0, 0) and time < timestamp(2069, 01, 01, 0, 0))
if enterLong
strategy.entry("Long", strategy.long)
if exitLong
strategy.close("Long")

Hard Prompt v2
I’d like you to create a PineScript v6 trading strategy based on the Gaussian
Channel and add Stochastic RSI to avoid bad trades. I want to be able to copy paste
it into TradingView, save it and it runs. Gaussian Channel shall indicate the
overall trend, up or down. StochasticRSI shall help to avoid unnecessary trades.
Buy when price closed above the upper Gaussian Channel line AND when Stochastic is
up. Sell when price closes below the upper Gaussian Channel line.
Long only, no shorting. Never use lookahead_on. Always trade with 100% of equity.
0.1% commission. 0 ticks slippage. Start trading on 2018-01-01 until 2069-01-01.
Avoid compiler errors. Use only functions that exist and PineScript v5 supports.
ChatGPT o1 Code
//@version=5
strategy("Gaussian Channel + Stoch RSI Strategy", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// User Inputs
length = input.int(20, "Gaussian Length", minval=5)
multiplier = input.float(2.0, "Channel Multiplier", step=0.1)
rsiLength = input.int(14, "RSI Length", minval=1)
stochLength= input.int(14, "Stoch RSI Length", minval=1)
kLength = input.int(3, "Stoch K Smoothing", minval=1)
dLength = input.int(3, "Stoch D Smoothing", minval=1)

// Gaussian Weighted Moving Average Function


f_gaussian(source, length) =>
half = (length - 1) / 2.0
sum = 0.0
norm = 0.0
// Gaussian standard deviation chosen as length/6 for a smooth curve
denom = (length / 6.0) * (length / 6.0)
for i = 0 to length - 1
x = i - half
w = math.exp(-(x * x) / (2 * denom))
sum += source[i] * w
norm += w
sum / norm

// Gaussian Weighted Standard Deviation Function


f_gaussian_std(source, length) =>
half = (length - 1) / 2.0
gavg = f_gaussian(source, length)
sum = 0.0
norm = 0.0
denom = (length / 6.0) * (length / 6.0)
for i = 0 to length - 1
x = i - half
w = math.exp(-(x * x)/(2*denom))
diff = source[i] - gavg
sum += diff * diff * w
norm += w
math.sqrt(sum/norm)

// Compute Gaussian Channel


gaussMid = f_gaussian(close, length)
gaussStd = f_gaussian_std(close, length)
gaussUpper = gaussMid + gaussStd * multiplier
gaussLower = gaussMid - gaussStd * multiplier

// Stochastic RSI Calculation


rsi = ta.rsi(close, rsiLength)
rsiLowest = ta.lowest(rsi, stochLength)
rsiHighest = ta.highest(rsi, stochLength)
stoch = 100 * (rsi - rsiLowest) / math.max(rsiHighest - rsiLowest, 1e-10)
k = ta.sma(stoch, kLength)
d = ta.sma(k, dLength)

// Conditions
// Long entry: Price closes above upper Gaussian line AND Stoch RSI K > D
(stochastic is "up")
longCondition = close > gaussUpper and k > d

// Exit condition: Price closes below upper Gaussian line


exitCondition = close < gaussUpper

// Only trade in the specified date range


inDateRange = time >= timestamp("2018-01-01T00:00:00") and time < timestamp("2069-
01-01T00:00:00")

// Submit Orders
if inDateRange
if longCondition and strategy.position_size <= 0
strategy.entry("Long", strategy.long)
if exitCondition and strategy.position_size > 0
strategy.close("Long")

// Plot Gaussian Channel


plot(gaussMid, "Gaussian Mid", color=color.new(color.yellow, 0))
plot(gaussUpper, "Gaussian Upper", color=color.new(color.green, 0))
plot(gaussLower, "Gaussian Lower", color=color.new(color.red, 0))
Claude 3.5 Code
//@version=5
strategy("Gaussian Channel with Stochastic RSI Strategy", overlay=true,
margin_long=100, margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Input parameters
channelLen = input.int(20, "Gaussian Channel Length")
mult = input.float(2.0, "Channel Multiplier")
stochLen = input.int(14, "Stochastic RSI Length")
smoothK = input.int(3, "Stoch RSI Smooth K")
smoothD = input.int(3, "Stoch RSI Smooth D")
rsiLen = input.int(14, "RSI Length")

// Calculate Gaussian Channel


basis = ta.sma(close, channelLen)
dev = mult * ta.stdev(close, channelLen)
upper = basis + dev
lower = basis - dev

// Calculate Stochastic RSI


rsi1 = ta.rsi(close, rsiLen)
stoch_rsi = ta.stoch(rsi1, rsi1, rsi1, stochLen)
k = ta.sma(stoch_rsi, smoothK)
d = ta.sma(k, smoothD)

// Plot indicators
plot(basis, "Basis", color=color.blue)
plot(upper, "Upper", color=color.red)
plot(lower, "Lower", color=color.red)
// Plot Stochastic RSI on separate pane
plot(k, "Stoch RSI %K", color=color.blue, display=display.none)
plot(d, "Stoch RSI %D", color=color.red, display=display.none)

// Trading conditions
stochRising = k > d
closedAboveUpper = close > upper
closedBelowUpper = close < upper

// Set date range


startDate = timestamp("2018-01-01T00:00:00")
endDate = timestamp("2069-01-01T00:00:00")
inDateRange = time >= startDate and time <= endDate

// Entry conditions
longCondition = closedAboveUpper and stochRising and inDateRange and
strategy.position_size == 0

// Exit conditions
exitLong = closedBelowUpper and strategy.position_size > 0

// Execute trades
if (longCondition)
strategy.entry("Long", strategy.long)

if (exitLong)
strategy.close("Long")
HorizonAI Code
//@version=5
strategy("Gaussian Channel with StochRSI Strategy", overlay=true, margin_long=100,
margin_short=100, initial_capital=100000,
commission_type=strategy.commission.percent, commission_value=0.1,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)

// Input parameters
length = input.int(20, "Gaussian Channel Length")
mult = input.float(2.0, "Gaussian Channel Multiplier")
stochLength = input.int(14, "Stoch RSI Length")
stochRsiOverbought = input.int(80, "Stoch RSI Overbought")
stochRsiOversold = input.int(20, "Stoch RSI Oversold")

// Calculate Gaussian Channel


basis = ta.sma(close, length)
dev = ta.stdev(close, length)
upper = basis + dev * mult
lower = basis - dev * mult

// Calculate Stochastic RSI


rsi = ta.rsi(close, stochLength)
stoch = ta.stoch(rsi, rsi, rsi, stochLength)
stochK = ta.sma(stoch, 3)
stochD = ta.sma(stochK, 3)

// Trading conditions
longCondition = close > upper and stochK > stochD and stochK > stochRsiOversold
exitLong = close < upper

// Date range
inDateRange = time >= timestamp("2018-01-01") and time <= timestamp("2069-01-01")

// Plot indicators
plot(basis, "Basis", color=color.blue)
plot(upper, "Upper", color=color.green)
plot(lower, "Lower", color=color.red)

// Strategy entries and exits


if inDateRange
if longCondition
strategy.entry("Long", strategy.long)
if exitLong
strategy.close("Long")

// Plot signals
plotshape(longCondition, "Buy", shape.triangleup, location.belowbar, color.green,
size=size.small)
plotshape(exitLong, "Sell", shape.triangledown, location.abovebar, color.red,
size=size.small)

// Additional indicator values in Data Window


plotchar(stochK, "Stoch K", "", location.top)
plotchar(stochD, "Stoch D", "", location.top)
Gemini 1.5 Pro Code
Errors. No useful code given.
DeepSeek R1 Code
//@version=5
strategy("Gaussian Channel with Stochastic RSI Strategy", overlay=true,
commission_type=strategy.commission.percent, commission_value=0.1, slippage=0,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
process_orders_on_close=true)

// Gaussian Channel Inputs


lengthGC = input.int(20, "Gaussian Channel Length", minval=1)
multiplier = input.float(2.0, "Standard Deviation Multiplier", minval=0.1)

// Calculate Gaussian Channel


basis = ta.ema(close, lengthGC)
deviation = multiplier * ta.stdev(close, lengthGC)
upperChannel = basis + deviation
lowerChannel = basis - deviation

// Plot Gaussian Channel


plot(basis, "Basis", color=color.blue)
plot(upperChannel, "Upper Channel", color=color.green)
plot(lowerChannel, "Lower Channel", color=color.red)

// Stochastic RSI Inputs


rsiLength = input.int(14, "RSI Length", minval=1)
stochLength = input.int(14, "Stochastic Length", minval=1)
smoothK = input.int(3, "Smooth K", minval=1)
smoothD = input.int(3, "Smooth D", minval=1)

// Calculate RSI
rsi = ta.rsi(close, rsiLength)

// Calculate Stochastic RSI


lowestRSI = ta.lowest(rsi, stochLength)
highestRSI = ta.highest(rsi, stochLength)
stochRSI = (rsi - lowestRSI) / (highestRSI - lowestRSI) * 100
k = ta.sma(stochRSI, smoothK)
d = ta.sma(k, smoothD)

// Trading Conditions
stochUp = k > d
priceAboveUpper = ta.crossover(close, upperChannel)
priceBelowUpper = ta.crossunder(close, upperChannel)

// Date Range Filter


startDate = input.time(timestamp("2018-01-01"), "Start Date")
endDate = input.time(timestamp("2069-01-01"), "End Date")
timeInRange = time >= startDate and time <= endDate

// Strategy Execution
if timeInRange
strategy.entry("Long", strategy.long, when=priceAboveUpper and stochUp)
strategy.close("Long", when=priceBelowUpper)

You might also like