Create strategies codes with ChatGPT for ProRealTime
Forums › ProRealTime English forum › General trading discussions › Create strategies codes with ChatGPT for ProRealTime
- This topic has 76 replies, 18 voices, and was last updated 3 months ago by GraHal.
-
-
05/31/2023 at 9:20 AM #215486
TraderGlyn it be good to start a new Topic for Bard.google.com coded Algo’s etc?
Have you got an Algo you can post (in a new Topic), it be very interesting to see the results from google AI?
I’m not a skilled coder and don’t have my own algo unfortunately.
Bard, at least for now, appears unable to write ProRealCode even after giving it a sample of correct code to learn from. I was surprised as Bard AI is described as a complex language model capable of “machine learning”. In this respect it seems way behind ChatGPT 4 currently.
With that said, this technology surely holds incredibly useful potential for us traders.1 user thanked author for this post.
05/31/2023 at 7:35 PM #215517Hi all, I am back after a long break. Chatgpt got me interested back into experimenting with strategies. It makes starting up a workflow so much more easier.
Here’s a simple strategy I asked it to make with Nichola’s prompt(with many thanks)
Seems to do pretty well. Alteast to help in formalising the initial strategy
123456789101112131415161718192021222324252627282930313233343536defparam cumulateOrders = falsedefparam flatafter = 235959 // Prevent any overnight trades// Define opening periodstartHour = 80000 // DAX opens at 8:00 local timeendHour = 110000 // Ends at 11:00 local time// Variable to keep track of the high and low since 1amonce highestSince1am = highonce lowestSince1am = low// Update the high and low since 1am every barif time >= 10000 and time < startHour thenhighestSince1am = max(highestSince1am, high)lowestSince1am = min(lowestSince1am, low)endif// If current time is within the opening hours and price crosses over the highest price since 1am, then buyif time >= startHour and time <= endHour and close > highestSince1am thenbuy at marketset stop ploss abs(low[1]-close) / pointsizeset target pprofit 50 * pointsizeendif// If current time is within the opening hours and price crosses under the lowest price since 1am, then sellshortif time >= startHour and time <= endHour and close < lowestSince1am thensellshort at marketset stop ploss abs(high[1]-close) / pointsizeset target pprofit 50 * pointsizeendif// Reset the highest and lowest variables for the next dayif time >= 235959 thenhighestSince1am = highlowestSince1am = lowendif06/01/2023 at 7:53 AM #215526Thank you @monochrome
and what was your prompt to get a so nicely coded strategy please?
06/01/2023 at 8:08 PM #215562This was my initial ask –
Code me a strategy for DAX in the 5 min timeframe. During the opening 3 hours buy when price crosses over the highest price since 1am and vice versa for sell. Profit target is 5pips and stop loss is the low of the previous barI had to correct it a few times by saying for eg –
– there is no when function, recode the dax strategy
– this code does not workI think we can make the prompt better by giving it most commonly used functions and a few simple examples.
Still testing
this is what it gave me initially –
1234567891011121314151617181920212223242526defparam cumulateOrders = falsedefparam flatafter = 235959 // prevent any overnight tradesTimeFrame = 5// define opening periodstartHour = 080000 // DAX opens at 8:00 local timeendHour = 110000 // ends at 11:00 local timepriorHour = 010000 // 1:00 am as per your request// variables for highest price and lowest price since 1 amhighestPrice = max[BarIndex](high) when time >= priorHour and time < startHourlowestPrice = min[BarIndex](low) when time >= priorHour and time < startHour// if current time is within the opening hours and price crosses over the highest price since 1am then buyif time >= startHour and time <= endHour and close crosses over highestPrice thenbuy at marketset stop ploss abs(low[1]-close) / pointsizeset target pprofit 5 * pointsizeendif// if current time is within the opening hours and price crosses under the lowest price since 1am then sellshortif time >= startHour and time <= endHour and close crosses under lowestPrice thensellshort at marketset stop ploss abs(high[1]-close) / pointsizeset target pprofit 5 * pointsizeendif06/02/2023 at 8:18 AM #215570I think we can make the prompt better by giving it most commonly used functions and a few simple examples.
Yes, that’s what I’m looking to improve, the intial prompt. That’s why we all should share our experience with wrong results and how we have resolved them with other specificitions given to ChatGPT.
06/04/2023 at 4:02 AM #215625I asked ChatGPT “I want sell when the price is 20% above the startpoint” and listed my code and got my result. I then asked “can I improve the macd” I was given a few improvements to my code and the end result. I then asked “show me code for divergence analysis” based on one of the end results. I cleaned up the code and listed below. I’ll back test and test on demo this week.
1234567891011121314151617181920212223242526272829303132333435363738394041424344// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Calculate MACD valuesMACDLinePeriods = 12SignalLinePeriods = 26MACDAveragePeriods = 9MLine = MACDline[MACDLinePeriods, SignalLinePeriods, MACDAveragePeriods](close)SignalLine = MACDSignal[MACDLinePeriods, SignalLinePeriods, MACDAveragePeriods](close)// Calculate price and MACD divergencePriceDivergence = close - MACDLine// Conditions to enter long positionsIndicator1 = SignalLineIndicator2 = MLineIndicator3 = (Indicator2 CROSSES OVER 0)DivergenceCondition = (PriceDivergence[1] < 0 AND PriceDivergence > 0)c1 = (Indicator1 < Indicator2)c2 = Indicator3StartPoint = TRADEPRICEIF c1 AND c2 AND DivergenceCondition THENBUY 1 CONTRACT AT MARKETset stop ploss abs(low[1]-close) / pointsizeset target pprofit 50 * pointsizeENDIF// Conditions to exit long positionsIndicator4 = MACD CROSSES UNDER 0[3]ExitCondition = (PriceDivergence[1] > 0 AND PriceDivergence < 0)c3 = (Indicator1 > Indicator2)c4 = Indicator4c5 = (close >= StartPoint * 1.2) // Price is 20% above the trade priceDivergenceExitCondition = (c4 OR c5) AND ExitConditionIF c3 AND DivergenceExitCondition THENSELL AT MARKETset stop ploss abs(high[1]-close) / pointsizeset target pprofit 50 * pointsizeENDIF2 users thanked author for this post.
06/09/2023 at 11:29 AM #21589906/10/2023 at 2:39 PM #215951indeed I.A allows to progress the personal coding, on the other hand I am surprised that the remarks which are made to him on the errors start again the next day. it doesn’t seem to save corrections or bad elements from languages outside of PRT.
06/10/2023 at 3:23 PM #215952it doesn’t seem to save corrections or bad elements
Let’s call your Chat – Chat No 1.
ChatGPT saves the corrections and bad elements you advised about and got sorted, but only remembers within Chat No 1.
If you start another Chat – Chat No 2, then there is no link across / memory from Chat No 1.
1 user thanked author for this post.
06/15/2023 at 3:02 PM #216285I made an algo today, approximately 6 months after making my first algo with ChatGPT. I used the prompts provided here in the forum thread, but it’s still not really making plug-and-playable code for ProRealTime.
The first issue with ChatGPT was that it insisted to use underscores in the variable names, which is not accepted by ProBuilder language. I think it’s an easy instruction to add – but I have also noticed that ChatGPT seems to have issue when providing too many instructions.Here’s the video of me making it and the full code it generated.
https://youtu.be/YciwTN4ZquUHere’s the full code
123456789101112131415161718192021222324252627282930313233343536defparam cumulateorders = false// Define RSI parametersRSIPeriod = 2RSIOversold = 15RSIOverbought = 20// Calculate RSIRSIValue = rsi[RSIPeriod]//Day-of-the-week filterDayOfWeekFilter = dayofweekFilterDay = 5 // Friday// Monthly filterif month = 0 or month = 1 or month = 2 or month = 3 or month = 4 or month = 10 or month = 11 or month = 12 thenLongMonths = 1elseLongMonths = 0endifif month = 5 or month = 6 or month = 7 or month = 8 or month = 9 thenAvoidMonths = 1elseAvoidMonths = 0endif// Entry conditionif RSIValue crosses under RSIOversold and DayOfWeekFilter = FilterDay and Longmonths thenbuy at marketendifif RSIValue crosses over RSIOverbought and DayOFweekFilter = Filterday and not AvoidMonths thensell at marketendif1 user thanked author for this post.
06/16/2023 at 7:07 PM #216365I actually see now that the initial prompt had instructions not to have underscores in the variable names. It really proves that ChatGPT still have issues handling too many instructions in the same prompt.
1 user thanked author for this post.
06/17/2023 at 12:01 PM #21638107/05/2023 at 12:04 PM #217304Hi all!
I would like to convert code for trailing stop, based on parameters, in code based on action price. To get that, I used de first prompt and then:
“trailing stop” is a stop loss that is moving near the price, based in rules included in the code, in order to exit the operation if the price turns back against the position. Answer “YES” if you can understand the meaning of “trailing stop”ChatGPTYES
I will paste “trailing stop” code and i will ask you to write probuilder code based in the minimum and maximum of prior candlesticks in timeframe 5 min. Answer “YES” if you are ready me to paste the “trailing stop” codeChatGPTYES, you can go ahead and paste the “trailing stop” code.
The result is different to the objetive, so i would like to ask you if you suggest a better prompt.
Trailing stop Code is the next one for 2 min TF:
// — 0. Variables
pp = (positionperf*100)
// — 1. Trailing stop
once enablets = 1 // activar trailing stop
// trailing stopif shortonmarket then
ts1= 0.5 // es mayor que este porcentaje, entonces utiliza trailingstop ts1
switch= 0.55 // es mayor que este porcentaje, entonces utiliza trailingstop ts2
ts2= 0.35
switch2= 0.7 // es mayor que este porcentaje, entonces utiliza trailingstop ts3
ts3= 0.3
endifif longonmarket then
ts1= 0.48//0.55//0.48 // es mayor que este porcentaje, entonces utiliza trailingstop ts1
switch=1.03//1.05//0.4 // es mayor que este porcentaje, entonces utiliza trailingstop ts2
ts2=0.35//0.85
switch2= 1.3//1.75 // es mayor que este porcentaje, entonces utiliza trailingstop ts3
ts3=0.25//0.2
endifpp = (positionperf*100)
if enablets thentrailingstop1 = (tradeprice(1)/100)*ts1
trailingstop2 = (tradeprice(1)/100)*ts2
trailingstop3 = (tradeprice(1)/100)*ts3if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
maxprice1=0
minprice1=close
priceexit1=0maxprice2=0
minprice2=close
priceexit2=0maxprice3=0
minprice3=close
priceexit3=0a1 = 0
a2 = 0
a3 = 0pp=0
endif
if onmarket then
if pp >= ts1 then
a1=1
endif
if pp >= switch then
a2=1
endif
if pp >= switch2 then
a3=1
endif
endif// setup long
if longonmarket then
maxprice1=max(maxprice1,close)
maxprice2=max(maxprice2,high)
maxprice3=max(maxprice3,high)
if a1 then
if maxprice1-tradeprice(1)>=(trailingstop1)*pointsize then
priceexit1=maxprice1-(trailingstop1)*pointsize
endif
endif
if a2 then
if maxprice2-tradeprice(1)>=(trailingstop2)*pointsize then
priceexit2=maxprice2-(trailingstop2)*pointsize
endif
endif
if a3 then
if maxprice3-tradeprice(1)>=(trailingstop3)*pointsize then
priceexit3=maxprice3-(trailingstop3)*pointsize
endif
endif
endif// setup short
if shortonmarket then
minprice1=min(minprice1,close)
minprice2=min(minprice2,low)
minprice3=min(minprice3,low)
if a1 then
if tradeprice(1)-minprice1>=(trailingstop1)*pointsize then
priceexit1=minprice1+(trailingstop1)*pointsize
endif
endif
if a2 then
if tradeprice(1)-minprice2>=(trailingstop2)*pointsize then
priceexit2=minprice2+(trailingstop2)*pointsize
endif
endif
if a3 then
if tradeprice(1)-minprice3>=(trailingstop3)*pointsize then
priceexit3=minprice3+(trailingstop3)*pointsize
endif
endif
endif// exit long
if longonmarket and priceexit1>0 then
sell at priceexit1 stop
endif
if longonmarket and priceexit2>0 then
sell at priceexit2 stop
endif
if longonmarket and priceexit3>0 then
sell at priceexit3 stop
endif// exit short
if shortonmarket and priceexit1>0 then
exitshort at priceexit1 stop
endif
if shortonmarket and priceexit2>0 then
exitshort at priceexit2 stop
endif
if shortonmarket and priceexit3>0 then
exitshort at priceexit3 stop
endif
endifMany thanks.
Alfonso
07/05/2023 at 2:30 PM #217326What part of the above code (if any?) was provided by ChatGPT?
If you use the Insert PRT Code button (far right top line above each new message – blue button) then Line Numbers will show in posted code … makes it easier for us all. 🙂
07/05/2023 at 3:32 PM #217328Ok, thanks and sorry: Next post I Will use It as said.
This code works in Backtest and real systems.
What I would need is Code for trailing stop based on price action instead of optimizable variables, so I asked GPT to write Code for that. I am afraid that the prompt used is not working well, so I need more ideas to write the Code based on Price Action.
Thanks a lot.
-
AuthorPosts
Find exclusive trading pro-tools on