Create strategies codes with ChatGPT for ProRealTime

Viewing 15 posts - 31 through 45 (of 88 total)
  • Author
    Posts
  • #215486 quote
    TraderGlyn
    Participant
    Senior

    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.

    GraHal thanked this post
    #215517 quote
    Monochrome
    Participant
    Senior

    Hi 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

    defparam cumulateOrders = false
    defparam flatafter = 235959  // Prevent any overnight trades
    
    // Define opening period
    startHour = 80000  // DAX opens at 8:00 local time
    endHour = 110000  // Ends at 11:00 local time
    
    // Variable to keep track of the high and low since 1am
    once highestSince1am = high
    once lowestSince1am = low
    
    // Update the high and low since 1am every bar
    if time >= 10000 and time < startHour then
    highestSince1am = 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 buy
    if time >= startHour and time <= endHour and close > highestSince1am then
    buy at market
    set stop ploss abs(low[1]-close) / pointsize
    set target pprofit 50 * pointsize
    endif
    
    // If current time is within the opening hours and price crosses under the lowest price since 1am, then sellshort
    if time >= startHour and time <= endHour and close < lowestSince1am then
    sellshort at market
    set stop ploss abs(high[1]-close) / pointsize
    set target pprofit 50 * pointsize
    endif
    
    // Reset the highest and lowest variables for the next day
    if time >= 235959 then
    highestSince1am = high
    lowestSince1am = low
    endif
    #215526 quote
    Nicolas
    Keymaster
    Master

    Thank you @monochrome

    and what was your prompt to get a so nicely coded strategy please?

    #215562 quote
    Monochrome
    Participant
    Senior

    This 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 bar

    I had to correct it a few times by saying for eg –
    – there is no when function, recode the dax strategy
    – this code does not work

    I 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 –

    defparam cumulateOrders = false
    defparam flatafter = 235959  // prevent any overnight trades
    TimeFrame = 5
    
    // define opening period
    startHour = 080000  // DAX opens at 8:00 local time
    endHour = 110000  // ends at 11:00 local time
    priorHour = 010000 // 1:00 am as per your request
    
    // variables for highest price and lowest price since 1 am
    highestPrice = max[BarIndex](high) when time >= priorHour and time < startHour
    lowestPrice = 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 buy
    if time >= startHour and time <= endHour and close crosses over highestPrice then
        buy at market
        set stop ploss abs(low[1]-close) / pointsize
        set target pprofit 5 * pointsize
    endif
    
    // if current time is within the opening hours and price crosses under the lowest price since 1am then sellshort
    if time >= startHour and time <= endHour and close crosses under lowestPrice then
        sellshort at market
        set stop ploss abs(high[1]-close) / pointsize
        set target pprofit 5 * pointsize
    endif
    
    #215570 quote
    Nicolas
    Keymaster
    Master

    I 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.

    #215625 quote
    crankbuddy
    Participant
    New

    I 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.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Calculate MACD values
    MACDLinePeriods = 12
    SignalLinePeriods = 26
    MACDAveragePeriods = 9
    
    MLine = MACDline[MACDLinePeriods, SignalLinePeriods, MACDAveragePeriods](close)
    SignalLine = MACDSignal[MACDLinePeriods, SignalLinePeriods, MACDAveragePeriods](close)
    
    // Calculate price and MACD divergence
    PriceDivergence = close - MACDLine
    
    // Conditions to enter long positions
    Indicator1 = SignalLine
    Indicator2 = MLine
    Indicator3 = (Indicator2 CROSSES OVER 0)
    DivergenceCondition = (PriceDivergence[1] < 0 AND PriceDivergence > 0)
    
    c1 = (Indicator1 < Indicator2)
    c2 = Indicator3
    StartPoint = TRADEPRICE
    
    IF c1 AND c2 AND DivergenceCondition THEN
    BUY 1 CONTRACT AT MARKET
    set stop ploss abs(low[1]-close) / pointsize
    set target pprofit 50 * pointsize
    ENDIF
    
    // Conditions to exit long positions
    Indicator4 = MACD CROSSES UNDER 0[3]
    ExitCondition = (PriceDivergence[1] > 0 AND PriceDivergence < 0)
    
    c3 = (Indicator1 > Indicator2)
    c4 = Indicator4
    c5 = (close >= StartPoint * 1.2) // Price is 20% above the trade price
    DivergenceExitCondition = (c4 OR c5) AND ExitCondition
    
    IF c3 AND DivergenceExitCondition THEN
    SELL AT MARKET
    set stop ploss abs(high[1]-close) / pointsize
    set target pprofit 50 * pointsize
    ENDIF

     

    Nicolas and Meta Signals Pro thanked this post
    #215899 quote
    GraHal
    Participant
    Master

    Anybody tried to get ChatGPT to create a Machine Learning Algo.

    #215951 quote
    bertrandpinoy
    Participant
    Veteran

    indeed 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.

    #215952 quote
    GraHal
    Participant
    Master

    it 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.

    bertrandpinoy thanked this post
    #216285 quote
    ProRealAlgos
    Participant
    Junior

    I 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/YciwTN4ZquU

    Here’s the full code

    defparam cumulateorders = false
    
    // Define RSI parameters
    RSIPeriod = 2
    RSIOversold = 15
    RSIOverbought = 20
    
    // Calculate RSI
    RSIValue = rsi[RSIPeriod]
    
    //Day-of-the-week filter
    DayOfWeekFilter = dayofweek
    FilterDay = 5 // Friday
    
    // Monthly filter
    
    if month = 0 or month = 1 or month = 2 or month = 3 or month = 4 or month = 10 or month = 11 or month = 12 then
    LongMonths = 1
    else
    LongMonths = 0
    endif
    
    if month = 5 or month = 6 or month = 7 or month = 8 or month = 9 then
    AvoidMonths = 1
    else
    AvoidMonths = 0
    endif
    
    // Entry condition
    if RSIValue crosses under RSIOversold and DayOfWeekFilter = FilterDay and Longmonths then
    buy at market
    endif
    
    if RSIValue crosses over RSIOverbought and DayOFweekFilter = Filterday and not AvoidMonths then
    sell at market
    endif
    GraHal thanked this post
    #216365 quote
    ProRealAlgos
    Participant
    Junior

    I 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.

    GraHal thanked this post
    #216381 quote
    gonzocorp
    Participant
    New

    Thank you Nicholas for this post, it’s just incredible and all informations shared here are just real gold mine. I’m starting my own test to improve my own PRC strategies ! I will probably share my feedback in future.

    GraHal and Nicolas thanked this post
    #217304 quote
    AMQ
    Participant
    Average

    Hi 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”
    ChatGPT

    YES

     

    User
    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” code
    ChatGPT

    YES, 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 stop

    if 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
    endif

    if 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
    endif

    pp = (positionperf*100)
    if enablets then

    trailingstop1 = (tradeprice(1)/100)*ts1
    trailingstop2 = (tradeprice(1)/100)*ts2
    trailingstop3 = (tradeprice(1)/100)*ts3

    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    maxprice1=0
    minprice1=close
    priceexit1=0

    maxprice2=0
    minprice2=close
    priceexit2=0

    maxprice3=0
    minprice3=close
    priceexit3=0

    a1 = 0
    a2 = 0
    a3 = 0

    pp=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
    endif

    Many thanks.

    Alfonso

    #217326 quote
    GraHal
    Participant
    Master

    What 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. 🙂

    #217328 quote
    AMQ
    Participant
    Average

    Ok, 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.

Viewing 15 posts - 31 through 45 (of 88 total)
  • You must be logged in to reply to this topic.

Create strategies codes with ChatGPT for ProRealTime


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
Nicolas @nicolas Keymaster
Summary

This topic contains 87 replies,
has 22 voices, and was last updated by crankbuddy
5 months, 3 weeks ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 05/12/2023
Status: Active
Attachments: 17 files
Logo Logo
Loading...