Cumulative Pyramiding help!!!

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #209177 quote
    teenytinye
    Participant
    New

    Hi all,

    Grateful for any help. I am trying to put together a code that lets me add more positions (up to a maximum of 4 positions) in an automatic trade.

    I’m looking to enter long / short when current price is greater  that 0.5% in my favour.

    I am also looking to exit the position when the current position moves 3% against me. So far, I have the following but I am not sure this is right. For some reason, it also doesn’t add the additional positions:

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions activated
    
    // Conditions to enter long positions
    c1 = (close > close[21])
    c2 = longonmarket AND Close => (1.005 * TradePrice)
    
    IF c1 OR c2 THEN
    BUY 0.5 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator1 = ExponentialAverage[30](close)
    c3 = (DClose(0) CROSSES UNDER indicator1[9])
    indicator2 = RSI[10](RSI[21](close))
    c4 = (indicator2 CROSSES OVER 70)
    indicator3 = DonchianChannelCenter[30]
    c5 = (DClose(0) CROSSES UNDER indicator3)
    c6 = PositionPerf[0] <= -3
    
    IF c3 AND c4 AND c5 OR (c6) THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    c6 = (DClose(0) < close[21])
    c7 = shortonmarket AND Close <= (TradePrice / 1.005)
    
    IF c6 OR c7 THEN
    SELLSHORT 0.5 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    c8 = (DClose(0) > close[13])
    indicator4 = DonchianChannelCenter[30]
    c9 = (DClose(0) CROSSES OVER indicator4[11])
    indicator5 = RSI[10](RSI[21](close))
    c10 = (indicator5 CROSSES UNDER 30)
    c11 = PositionPerf[0] <= -3
    
    IF c8 AND c9 AND c10 or (c11) THEN
    EXITSHORT AT MARKET
    ENDIF
    #209179 quote
    JS
    Participant
    Senior

    I tried your system but it does open cumulative positions…?

    More than 4 positions but this limit is not (yet) in your code…

    #209196 quote
    teenytinye
    Participant
    New
    Thanks! Also looking for help on inserting this limit. Also does anyone know why you can backtest the stop loss and trailing stop together and as a percentage, but ProOrder won’t let you do both or add percentages?
    #209205 quote
    JS
    Participant
    Senior

    Hi,

    To add a limit to the number of contracts, you can use:

    If c1 or c2 and CountOfLongShares<=4 then

    If c6 and c7 and CountOfShortShares<=4 then

    teenytinye thanked this post
    #209206 quote
    JS
    Participant
    Senior

    Here is a link to a trailing stop function that can be used as an alternative to the standard TS in ProBackTest…

    https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

    teenytinye thanked this post
    #209515 quote
    teenytinye
    Participant
    New
    Do you know if this works in an automatic trade. Doesn’t seem to be working for me
    #209596 quote
    Nicolas
    Keymaster
    Master
    Yes, it works, it has been used many times since years for traders in their strategies 🙂 For a specific trailing stop in percentage, you can look at these snippets:
    Cannot Set Trailing Stop as % through IG
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Cumulative Pyramiding help!!!


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
teenytinye @teenytinye Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Nicolas
2 years, 12 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/06/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...