Help Writing First ProBackTest Algo based on RSI conditions

Forums ProRealTime English forum ProOrder support Help Writing First ProBackTest Algo based on RSI conditions

Viewing 6 posts - 1 through 6 (of 6 total)
  • #95260

    Hi All,

    I am completely new to all of this and have been going through the manuals and trying to write my own code but really struggling with most of it.

     

    Firstly I can’t workout how sell partial open positions. E.g. SELL at market 50% of open long positions. I am also having trouble in working out how to add to a long if say the RSI is under 30 for X amount of consecutive days.

     

    Would really appreciate any help. I thought about a first algo which will include a number of variables that I can use going forward for other strategies. Have written the basis of it below if anyone has time to help code?

     

     

    Basic system which looks at RSI on stocks.

     

    Open BUY position if Not LongOnMarket AND RSI <=30.  $5,000 CASH AT MARKET.

    Add to position (or open/add new position) if RSI remains under 30 for 3 consecutive days. $3,000 trade size if a position already exists. (no idea how to code)

    Add to position if RSI goes above 30 and then goes back under 30. $3,000 trade size if a position already exists. (Presume the above buy when RSI <=30 will work but have IF LongOnMarket AND RSI <=30 THEN BUY 3000 CASH AT MARKET?)

    SELL AT MARKET 50% of total open position if RSI =>70. (no idea how to code)

    SELL remaining open position if RSI stays above 70 for 3 consecutive days. (no idea how to code)

    SELL remaining if RSI drops below 70 then goes above 70.(no idea how to code)

    OPEN SHORT positions if RSI goes above 85. $3,000 opening positions. (IF MyRSI =>85 THEN SELLSHORT 3000 CASH AT MARKET ENDIF?)

    Add to short if RSI goes above 90. $2,000 if position already open. (IF MyRSI =>90  THEN SELLSHORT 2000 CASH AT MARKET ENDIF?)

    Add to short position if RSI stays above 70 for 5 consecutive days. (dont know how to code)

    Close 50% of total short position if RSI goes below 55. (dont know how to code)

    Close remainder of short if RSI goes below 45.  (dont know how to code)

     

    Noticed need to have DEFPARAM CumulateOrders = True

    The variables that I would want to be able to change are the RSI levels, amount of trade size in $, day counts for adding to positions and percentage of the positions when closing out.

     

    Let me know if any questions and I apologise if what I have written is unclear.

     

    Thanks

    #95278

    Before someone tries to code this for you you should be aware that partial closure is not currently possible in PRT. You can write a strategy that does it and back test it but you cannot run it live in either demo or live platforms.

    1 user thanked author for this post.
    #95304

    Before someone tries to code this for you you should be aware that partial closure is not currently possible in PRT. You can write a strategy that does it and back test it but you cannot run it live in either demo or live platforms.

    OK thanks for the info. Happy to still look into it but am now aware cant use the strategy for Auto Trading.

     

     

    Thanks

    #95496

    Little bump, in case anyone kind enough wants to help me.

    If do whole thing would really appreciate part code for if long on market and RSI is <=30 for 3 consecutive days then BUY 3000 CASH AT MARKET.

     

    Then also any help on how to sell partial positions?

     

    Many thanks

    #95500

    RSI is <=30 for 3 consecutive days then BUY 3000 CASH AT MARKET

    Here is the code for that part:

    2 links with examples on how to partial close positions:

    https://www.prorealcode.com/topic/bollinger-band-coding-help-please/#post-80959

    https://www.prorealcode.com/blog/learning/partial-closure-positions-price-retracing-complete-function/

    1 user thanked author for this post.
    #95557

    RSI is <=30 for 3 consecutive days then BUY 3000 CASH AT MARKET

    Here is the code for that part:

    2 links with examples on how to partial close positions:

    https://www.prorealcode.com/topic/bollinger-band-coding-help-please/#post-80959

    https://www.prorealcode.com/blog/learning/partial-closure-positions-price-retracing-complete-function/

    Thank you very much Nicolas, that is really helpful!!

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

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