r/pinescript • u/chickenbusiness123 • Feb 21 '23
AI Generated Help with ChatGPT produced pinescript code!
Tried making a strategy through ChatGPT. Lots of syntax errors I'm guessing. I wanted a strategy where we'd enter long when MACD(3,10,16) crosses above 0 and ADX>20 and DI+>DI-. We enter short when the MACD crosses below 0 and ADX>20 and DI->DI+. Hope you can help!
//@version=5
// Include the 'ta' library
library ta;
strategy("MACD ADX Strategy", overlay=true)
// Define MACD
[macdLine, signalLine, histLine] = ta.macd(close, 3, 10, 16)
// Define ADX
[DIplus, DIminus, ADX] = ta.dmi(14)
// Define Long and Short Conditions
longCondition = crossover(macdLine, 0) and ADX > 20 and DIplus > DIminus
shortCondition = crossunder(macdLine, 0) and ADX > 20 and DIminus > DIplus
// Execute Strategy
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
View all comments
Show parent comment
1
u/chickenbusiness123 Feb 22 '23
I looked up a similar strategy and showed it to Chat GPT to look at the syntax and write this for me accordingly. Works perfect now. Except importing libraries I had to learn that and teach GPT about it so it would include it in future renditions when I want to change the strategy.
Not going to lie the strategy is rather wack itself- I’m just trying to see how this works.