Tests to find the best AI for trading strategies
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.
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")
// 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)
// 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
// Trading logic: Only execute trades within the selected date range
inDateRange = 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")
// 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
// Trading conditions
longCondition = ta.crossover(close, upper)
exitLongCondition = ta.crossunder(close, lower)
// 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)
// 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)
// 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
// 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")
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
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// 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)
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// 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)
// Lag Reduction
bool modeLag = input.bool(defval=false, title="Reduced Lag Mode")
bool modeFast = input.bool(defval=false, title="Fast Response Mode")
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// 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")
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// Gaussian Channel Indicator - courtesy of @DonovanWall
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// This study uses Ehlers Gaussian Filter technique combined with lag reduction and
true range to analyze trend activity.
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// 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
// 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)
// 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)
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// 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
// 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
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
// 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")
// 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")
// 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
start_date = timestamp("2018-01-01")
end_date = timestamp("2069-01-01")
// Entry Conditions
long_condition = close > lower and close < upper and k < oversold and k > k[1]
// Trading Logic
if time >= start_date and time <= end_date
if long_condition
strategy.entry("Long", strategy.long)
if k > overbought
strategy.close("Long")
// Exit
if strategy.position_size > 0 and exitCondition
strategy.close("Long")
// Plot Channels
plot(middle, "Middle Line", color=color.blue)
plot(upper, "Upper Channel", color=color.red)
plot(lower, "Lower Channel", color=color.green)
// 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)
// Conditions
// Long entry: Price closes above upper Gaussian line AND Stoch RSI K > D
(stochastic is "up")
longCondition = close > gaussUpper and k > d
// 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")
// 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")
// 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
// 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")
// 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)
// 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)
// Calculate RSI
rsi = ta.rsi(close, rsiLength)
// Trading Conditions
stochUp = k > d
priceAboveUpper = ta.crossover(close, upperChannel)
priceBelowUpper = ta.crossunder(close, upperChannel)
// Strategy Execution
if timeInRange
strategy.entry("Long", strategy.long, when=priceAboveUpper and stochUp)
strategy.close("Long", when=priceBelowUpper)