Create indicators codes with ChatGPT for ProRealTime

Forums ProRealTime English forum General trading discussions Create indicators codes with ChatGPT for ProRealTime

Viewing 8 posts - 1 through 8 (of 8 total)
  • #218593

    This topic will focus on the programming assistance that ChatGPT IA can give us to create new indicators for ProRealTime.

    Here is an interesting first prompt that give good results:

    Act as a pro software developer for the stock markets, crypto and forex.
    You are used to create indicators and scanner to help people analyzing the behavior of the market, through a mathematical approach.
    Currently, you are in research of a new indicator that could probably gives a better edge and new approach in term of analysis for traders.
    You have different ideas in mind and like to share them with me. I will ask you idea from time to time, when I say “new idea”.

    These ideas should use only price, volume and time, and never external datas.
    You an also create arrays of values you can use later in your idea.
    They should be new indicators only, with a high degree of complexity and not already known indicators.

    Of course, you can also use familiar mathematical concepts, such as digital filters, optical filters, etc., to build the new indicator.

    After explanation, you will give a mathematical or logical formula that synthesis the idea, accompanied by an idea of its visual representation on a graph.

    Don’t numbering the idea you share.

    In addition, you’ll code a version of the indicator in ProRealTime language (prorealcode).

    For reference, here are some examples of different indicators codes for ProRealTime:
    (variables names do not contain any underscore).

    RSI :
    “””
    up = MAX(0, CLOSE – CLOSE[1])
    down = MAX(0, CLOSE[1] – CLOSE)
    mmUp = WILDERAVERAGE[p](up)
    mmDown = WILDERAVERAGE[p](down)
    RS = mmUp / mmDown
    myRSI = 100 – 100 / (1 + RS)
    RETURN myRSI AS “Relative Strength Index”, 30, 70, 0
    “””

    ATR TRAILINGSTOP:
    “””
    multiplier=3
    period=10
    moy=averagetruerange[period](close)
    price=medianprice
    up=price+multiplier*moy
    dn=price-multiplier*moy
    once trend=1
    if close>up[1] then
    trend=1
    elsif close<dn[1] then
    trend=-1
    endif
    if trend<0 and trend[1]>0 then
    flag=1
    else
    flag=0
    endif
    if trend>0 and trend[1]<0 then flagh=1 else flagh=0 endif if trend>0 and dn<dn[1] then
    dn=dn[1]
    endif
    if trend<0 and up>up[1] then
    up=up[1]
    endif
    if flag=1 then
    up=price+multiplier*moy
    endif
    if flagh=1 then
    dn=price-multiplier*moy
    endif
    if trend=1 then
    mysupertrend=dn
    else
    mysupertrend=up
    endif
    if mysupertrend > mysupertrend[1] then
    color1=0
    color2=255
    color3=0
    elsif mysupertrend < mysupertrend[1] then
    color1=255
    color2=0
    color3=0
    endif
    return mysupertrend coloured (color1,color2,color3) as “SuperTrend”
    “””

    HULL MOVING AVERAGE:
    “””
    Period=16
    inner = 2*weightedaverage[ round( Period/2 ) ](close)-weightedaverage[Period](close)
    MMHULL=weightedaverage[ round( sqrt(Period) ) ]( inner )
    return MMHULL COLOURED(255,0,0) as”Hull Average”
    “””

    If you are ready say “YES” and nothing else.

    With more hindsight and experience, I know today that to make him realize codes for ProRealTime is possible, if you use the right keywords, the right instructions, what we call a “prompt”.
    With a lot of trial and error, I managed to create a “specification” (the initial prompt above) that allows to fix some programming errors that it could commit after a request (see more explanation in the following post).

    PREREQUISITE: Subscription to ChatGPT PLUS (v4) to get relevant results (currently 20$/month). This version being much more powerful, results obtained with an earlier version will not be integrated in our prompts searches.

    If you want, let’s all try to create a coherent set of commands and prompts to allow the community to benefit from it, and then to collaborate as well, creating a virtuous circle of knowledge for this new fabulous subject that is generative AI, and associated with our favorite trading platform! 🙂

    PLEASE RESPECT THE LANGUAGE OF THE TOPIC: all discussions should be written in English, posts in other languages will be deleted.

    1 user thanked author for this post.
    #218598

    Prompt:

    1 idea 

    ChatGPT replied:

    Sure, let’s explore a new idea for an indicator, which I will refer to as the “Weighted Price Momentum Oscillator” (WPMO). This indicator would analyze the rate of change in the market, giving more weight to significant changes that occur over shorter periods. It will be helpful in understanding the price volatility and identifying potential trend reversals in the market.

    Conceptually, the WPMO would function as follows:

    1. First, it would calculate the rate of change of the price over a certain period (let’s say n periods). This is just the change in price over that period, divided by the price n periods ago. We multiply this value by the volume of the current period to get a volume-weighted rate of change.

    2. This volume-weighted rate of change would then be smoothed using a digital filter (e.g., an exponential moving average), to reduce the noise and focus on the underlying trend.

    3. The indicator would oscillate around a zero line. Positive values indicate upward momentum, while negative values indicate downward momentum. The strength of the momentum is determined by how far the WPMO deviates from the zero line.

    Mathematically, this could be represented as follows:

    WPMO = EMA(Volume * (Close – Close[n]) / Close[n], m)

    Where:
    – EMA refers to an exponential moving average.
    – Volume refers to the trading volume of the current period.
    – Close refers to the closing price of the current period.
    – Close[n] refers to the closing price n periods ago.
    – m is the smoothing factor for the EMA.

    On a graph, the WPMO would be represented as an oscillator that moves above and below a zero line, with positive and negative regions. A crossing of the zero line could be used as a trading signal.

    Now let’s convert this into ProRealTime code:

    This ProRealTime code is built to calculate the WPMO. As it stands, it will draw the WPMO on the chart as an oscillator around the zero line. Please remember, this is a novel indicator and might require further testing and validation.

    2 users thanked author for this post.
    #221829

    Hi Nicolas, no replies I see, to what I thought might be a fascinating subject?

    So…. just before I have to go out, so apologies for the formatting, this is raw ascii text copied from the site so the code and the math symbols need to be configured – I may have time to come back and edit over the weekend, IF there is any glimmer of interest of course 🙂 So here is something to hopefully start the ball rolling!


     

    User
    new idea
    ChatGPT
    Certainly, let’s discuss a novel indicator that I’ve been contemplating recently: the “Volatility-Weighted Moving Time” (VWMT) indicator.

    Concept
    The idea behind the VWMT is to capture changes in market volatility and to weigh them against time intervals in which they occur. Instead of considering all time intervals as equal, the VWMT assigns more weight to time periods where there are significant price and volume movements.

    Mathematical Formulation
    The VWMT is calculated as follows:

    Compute Volatility Score (VS) for each time interval

    ​Calculate Time-Weight for each time interval

    Finally, compute the VWMT for each time interval

    Where

    N is the number of periods you want to consider for the moving time window.

    Visual Representation
    On a graph, the VWMT would look like a moving average line but with varying smoothness and responsiveness depending on the underlying volatility and volume. High volatility would make the VWMT more sensitive, and low volatility would make it smoother.

    ProRealTime Code
    Here’s how you could implement this in ProRealTime:

    pascal
    Copy code
    // Volatility-Weighted Moving Time (VWMT)
    periods = 14
    VS = SQRT((CLOSE – CLOSE[1])^2 + VOLUME)
    TotalVS = SUM[periods](VS)

    // Calculate the Time-Weight
    TimeWeight = VS / TotalVS

    // Calculate the VWMT
    VWMT = SUM[periods](TimeWeight * CLOSE)

    RETURN VWMT COLOURED(0, 255, 0) AS “Volatility-Weighted Moving Time”
    Would you like to explore more about this idea, or shall we move on to another?

     

    User
    explore more
    ChatGPT
    Certainly, let’s delve deeper into the nuances of the Volatility-Weighted Moving Time (VWMT) indicator.

    Interpretation
    The VWMT’s value, much like a traditional moving average, provides a smoothed representation of price action. However, it also factors in both the volatility in price and trading volume. Because it gives more weight to periods of higher volatility and volume, this makes it potentially more responsive to significant market events.

    Breakouts: A sudden and sharp deviation from the VWMT line could be indicative of a market breakout. The more significant the divergence, the stronger the breakout signal.

    Convergence-Divergence: When the VWMT starts converging towards the price, it may suggest a potential period of lower volatility ahead. On the other hand, divergence could signify an upcoming volatile phase.

    Cross-Over Strategies: VWMT could also be used in cross-over strategies with other moving averages. When VWMT crosses above another slower moving average, it might indicate a bullish trend, and vice versa.

    Advantages and Limitations
    Advantages:

    Takes into account both volume and price volatility, potentially making it more responsive to market changes.
    Can be adjusted for different time frames to suit various trading styles.
    Limitations:

    Like all indicators, it is not foolproof and should be used in conjunction with other tools and analyses.
    Because it’s more sensitive during high volatility, it might generate false signals in extremely volatile markets.
    Fine-Tuning
    Parameter Optimization: The periods variable is flexible, and one could conduct back-testing to find the optimal setting for their specific trading style.

    Smoothing: To reduce the impact of extreme values, one might consider applying a secondary smoothing algorithm to the VWMT, like a simple moving average or an exponential moving average of the VWMT line.

    Would you like to discuss potential improvements, modifications, or have any specific queries on this topic?

     

    User
    can you suggest a good mathematical formula to use to smooth this, and add the Prorealcode to your reply
    ChatGPT
    Certainly, a common technique for smoothing data is to use an Exponential Moving Average (EMA). The EMA provides a balanced way to give more weight to recent data while still incorporating older data to a certain extent.

    Mathematical Formulation for EMA
    The formula for calculating the EMA of the VWMT would be:

    Updated ProRealTime Code with EMA
    Here’s the ProRealTime code incorporating the EMA for smoothing the VWMT:

    pascal
    Copy code
    // Volatility-Weighted Moving Time (VWMT) with EMA smoothing
    periods = 14
    EMAPeriods = 10 // Number of periods for EMA smoothing
    alpha = 2 / (EMAPeriods + 1) // Smoothing factor for EMA

    VS = SQRT((CLOSE – CLOSE[1])^2 + VOLUME)
    TotalVS = SUM[periods](VS)

    // Calculate the Time-Weight
    TimeWeight = VS / TotalVS

    // Calculate the VWMT
    VWMT = SUM[periods](TimeWeight * CLOSE)

    // Calculate the EMA of VWMT
    if barindex > 1 then
    EMA_VWMT = alpha * VWMT + (1 – alpha) * EMA_VWMT[1]
    else
    EMA_VWMT = VWMT
    endif

    RETURN EMA_VWMT COLOURED(0, 0, 255) AS “Smoothed VWMT”
    In this code snippet, EMAPeriods sets the number of periods for the EMA. You may adjust this parameter according to your preference or based on back-testing results.

    The smoothed VWMT should display on your graph as a curve that is less sensitive to individual spikes, making it easier to identify general trends and patterns.

    Would you like to know more about this smoothed version or another aspect of VWMT?

     

    1 user thanked author for this post.
    #221840

    Well, its a useful tool to learn from – I’m already learning! I didn’t understand the ^ symbol, so I asked, and ended up learning a little more of useful maths:

    in the line: ‘VS = SQRT((CLOSE – CLOSE[1])^2 + VOLUME)’, what does the ‘^’ mean in simple terms
    ChatGPT

    In mathematical notation and in many programming languages, the caret symbol “^” is used to denote exponentiation. In the context of the line VS = SQRT((CLOSE - CLOSE[1])^2 + VOLUME), the expression (CLOSE - CLOSE[1])^2 means the square of the difference between the current closing price (CLOSE) and the closing price of the previous time interval (CLOSE[1]).

    In simple terms, you’re taking the difference between the current and previous closing prices, and then raising that difference to the power of 2. This is equivalent to multiplying the difference by itself. The purpose is to ensure that the value is non-negative, as squaring any real number eliminates its sign.

    1 user thanked author for this post.
    #221927

    Yes it is very cool to develop idea this way! 🙂

    Squaring a value is also a good method to mark differences between low and high ones. A high value being squared results in a bigger value than a low value being squared.

    #221990

    Hi Nicolas, my last couple of posts may have been overly verbose given the subject heading – perhaps these should be edited down so this thread stays on topic?

    I have removed the coding below to show how useful ChatGPT can be with simple prompts with regard to advancing the usefulness of ProRealCode (which it appears to recognise)…

    (Happy to post code if requested – but maybe tested versions of old code, and tested versions of new ideas, should be on other threads? – advice please).

     

    GPT-4
    Custom instructions details

    User
    Using prorealcode language, can you improve the following:
    (code removed)

    ChatGPT
    Certainly. The ProRealCode you’ve written aims to identify and draw trend lines based on the RSI and closing prices. I’ve made some refinements to the code for better clarity, structure, and consistency. Here’s an improved version:
    (code removed)

    Here are some notes on the changes:
    Renamed variables for better understanding of their purpose.
    Removed redundant variables where possible.
    Added comments for code readability.
    I trust that these revisions will meet your requirements for UK English and technical clarity. Would you like any further explanation on the code?

    User
    Higher and lower close levels are used in the above code. Add higher highs and lower lows as additional levels to calculate divergence.

    ChatGPT
    Certainly. To identify divergences, we’ll include both higher highs and lower lows alongside higher and lower closes. We will compare these levels to the RSI to pinpoint divergences. Here’s the modified code:
    (code removed)

    Key updates:
    Introduced highPrice and lowPrice to store previous high and low prices. highPriceCurrent and lowPriceCurrent store the highest and lowest prices within the past N bars, respectively.
    Updated the condition to draw lines for divergences by considering both close prices and high/low prices.
    These modifications should better capture divergences by considering both closing prices and extreme values (highs and lows).

    #221992

    Also, another thought, where do we stand with regard to rewriting other people’s code?

    Do we just credit them for the original code, or should we try to get their permission first, and what if we can’t – can we claim this is for the ‘greater good’ of sharing code?

    If it’s private, probably will go unnoticed, but if put into the public domain, there may be issues not yet thought about…

    #221993

    You can use this thread to post codes written or modified by ChatGPT. No worries about codes from other users being modified, it’s fair game. Just, please try to format the copy/paste from the chatGPT text window, so that it appears clearly on the forum for everyone to benefit.

    Thanks again for your input on that subject, I mean, I think we are just at the beginning of great adventure with generative AI! 🙂

Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login