Pyramiding for S&P500 doesn’t work

Forums ProRealTime English forum ProOrder support Pyramiding for S&P500 doesn’t work

Viewing 11 posts - 1 through 11 (of 11 total)
  • #185631

    Hi,

    I would like to pyramid to an existing position, but I can’t make it work. Clearly I am making a mistake and I need some advice. I am trading the S&P500 on a 3 min chart.

    Below is a code that doesn’t create a second position with Setup “SEMA8d”. The setup by itself works when I delete the other setup “SEMA21g” from the code.

    Setup “SEMA8d” has a setup on 13.01.2022  at 21:06. The other setup “SEMA21g” is short and has an exit signal at the moment (21:06) when “SEMA8d” creates a short signal.

    Cumulate order is set to True.

    What do I need to change to be able to enter a new trade while another is just exiting?

     

    Thanks.

    Sascha

     

    #185636

    I can’t see right now why  cumulation of orders does not work in your code, but all I can see is that you are using several times a code like “and not xxxx”. This is not the right syntax, but you need to write “and (not xxx)”, with brackets. This can make a huge difference, but it is probably not the reason why cumulation does not work.

    #185686

    Thanks XORANDNOT for your comment. However it didn’t solve the problem.

    But by accident I found out that it has something to do with the command “Exitshort at market”. When I delete the lines 60-62, the second trade at 21:06 is entered. But this is obviously not a solution as then the first trade wouldn’t exit when it’s supposed to (the exit is triggered at 21:06).  I don’t understand why. Maybe entering a new position while at the same time an Exitshort command is triggered somehow prevents the next trade to be taken.

    Anyone any idea?

    1 user thanked author for this post.
    #185687

    It could be that one position is closed by “exitshort” and another opened by a “sellshort” command at the same time. The net result is no change in position size and therefore nothing happens. Prorealtime adds up net position changes before placing any order. In this case, the old position with the old entry price will be kept.

    #185694

    Sacha, regarding what XORANDNOT just told, try to change all into something like this :

    You will be the first to understand what is happening (= what you are doing). 🙂 Next the PRT parser will understand it as well.

    Have fun !

    1 user thanked author for this post.
    #185702

    It could be that one position is closed by “exitshort” and another opened by a “sellshort” command at the same time. The net result is no change in position size and therefore nothing happens. Prorealtime adds up net position changes before placing any order. In this case, the old position with the old entry price will be kept.

    That is exactly what I was assuming. Is there any way to solve this?

    #185709

    Not in a direct way. You can however “remember” the new entry price of the new hypothetical position, and base all new exits (stop loss, take profit, trailing stop, etc.) on this price. Requires some coding work, however. Prorealtime will do all standard exit calculations with the old positionprice.

    1 user thanked author for this post.
    #185711

    Thanks PeterSt.

    However I am a little confused by your adjustment. As we set JustTraded=0 and then the next if condition asks for “if not 0” (line 3 and 18) that means only to take a trade if JustTraded is greater than 0, it should never take a trade at all as my conditions in line 4 and 19 will never be used and therefore JustTraded would never be set to 1.

    But in fact when I implement your suggestion nothing changes and the same trade is taken or not taken.

     

    #185714

    Not in a direct way. You can however “remember” the new entry price of the new hypothetical position, and base all new exits (stop loss, take profit, trailing stop, etc.) on this price. Requires some coding work, however. Prorealtime will do all standard exit calculations with the old positionprice.

    Thanks. I guess this is a little bit too complicated for me to code for now. I would need to improve my coding skills first.

    #185721

    Thanks XORANDNOT for your comment. However it didn’t solve the problem.

    But by accident I found out that it has something to do with the command “Exitshort at market”. When I delete the lines 60-62, the second trade at 21:06 is entered. But this is obviously not a solution as then the first trade wouldn’t exit when it’s supposed to (the exit is triggered at 21:06). I don’t understand why. Maybe entering a new position while at the same time an Exitshort command is triggered somehow prevents the next trade to be taken.

    Anyone any idea?

    Because you enter a trade and close it immediately, before it is even entered. So it will never be entered.

    I also want to point out that, in case of additional positions, TRADEDEPRICE(1) AND TRADEINDEX(1) will refer to the most recent position. To refer to the average price calculated by ProOrder, use POSTIONPRICE, instead.

     

     

    1 user thanked author for this post.
    #185753

    However I am a little confused by your adjustment. As we set JustTraded=0 and then the next if condition asks for “if not 0” (line 3 and 18) that means only to take a trade if JustTraded is greater than 0, it should never take a trade at all

    Haha, no … Look at this example :

    You are just not “digging” the reality about a variable name and assign it the correct value. And I must admit, the way you explain it I can’t even see where it is wrong, but it really is … wrong.

    Thus my code above makes no sense but it shows you that only when not 1, you enter that trade. So again :

    Just try it. And you need to because else orders will cancel each other indeed.

    And Sacha, you do know that your code is called at each candle occurring, right ?
    And that your code is executed from top to bottom, sequentially ? –> This is why you need to this. Also :

    If OnMarktet (etc.) only receives the proper status at the next bar(‘s calling). Thus

    Then your Time(frame) elapses and then the If ShortOnMarket will be true. Not because of any SellShort once “again”, but because of that happening in the *previous* bar(‘s-call).

    Lastly, looking at the Topic Title (pyramiding) … No offense meant (!), but I would advise not to attempt this when the basic principles are not 100% clear. Thus, please start out with

    with the notice that this time the comment matches the code (your’s really doesn’t but that will be an old comment, I’m sure).
    See what that brings you and how you will be able to buy and sell (Long and Short) with that. Covered that ? then some next steps. And my promise in advance : these aggregated orders are really not easy to do (I mean, track what’s going on when).

    And still and always : have fun !

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

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