Need help in coding simple multiple stops. Cannot figure out what’s wrong

Forums ProRealTime English forum ProOrder support Need help in coding simple multiple stops. Cannot figure out what’s wrong

Viewing 13 posts - 1 through 13 (of 13 total)
  • #175429

    Hi all,

    I tried to write a simple and straight forward code, but somehow it does not work as expected and look very off.  Its relatively simple code, and I cannot quite figure out which part is the mistake.  Can anyone pls help with some advise and put me out of my misery?  Thanks.

    #175435

    Hello phanz – What I would do make If/Else situations of all the Buy’s and Sell’s, so that you can automatically be sure that nothing happens twice (unless you explicitly want it to happen twice, of course).

    Something else I see is the several StopLoss commands occurring. Maybe some insider can tell whether this is allowed. Thus in your case you might change a StopLoss (value) at each bar because of e.g. the SMA changes each bar. I envision that some broker may not be happy with that (because these commands go to the broker for real (when live of course) and for that reason PRT may not allow it. For example, possibly it sets the StopLoss only once after the order is filled.

    1 user thanked author for this post.
    #175462

    Hi PeterSt,

    Thank you for your suggestion.  The Elsif function defnitely help.  At least the entry and take profit code works as expected.

    i purposely set the TP3 target to be unreachable to check if the Stop Loss order works.  Unfortunately the SL order does not work.  More investigations needed.  If anyone can give a helping hand will be greatly appreciated.  Thank you.

     

     

    #175463

    Hi sorry Line 30 shud read:

    TP3Condition = close > BBUp3SD

    #175472

    the SL order does not work

    Which one does not work … you have several in the code?

    SL within ElsIf would only work if the conditions within respective ElsIf are met.

    Just a few thoughts.

    1 user thanked author for this post.
    #175475

    Hi,

    Line 43 we see the condition for the system to sell 5 contracts at TP1.

    Line 48 we see the condition for the system to sell 3 contracts at TP2.  So after the sale of the 3 contracts, we have balance of 2 contracts left (10-5-3=2).

    Pls see the attached screenshot.

    And also in Line 51 we Set Stop Loss BBUp1SD.  So from the screenshot, the balance 2 contracts should have been taken out at point X by the virtue of the Set Stop Loss BBUp1SD.  Since TP2 is executed, the Set Stop Loss BBUp1SD shud be read by the algo right?

     

    #175492

    Hi guy, will really appreciate if anyone can give some advice on this.  Thank you for your time.  Cheers

    #175494

    Have you tried using GRAPH on all of your conditions to make sure all conditions are being met when you are expecting them to be?

    1 user thanked author for this post.
    #175678

    You are using SET STOP LOSS incorrectly, as it doesn’t require a price (CLOSE, SMA55, HIGH, BollingerUP, etc…) but a price difference such as RANGE, (close – low[1]),  (close – BollingerUP), (SMA55 – close), AverageTrueRange, etc…).

    SET STOP pLOSS is the sane as above but it requires that the difference be expressed in pips, usually PIPSIZE, such as (Sma55 – close ) * PipSize.

    The same rules apply to SET TARGET PROFIT.

     

    1 user thanked author for this post.
    #175722

    Hi Roberto,

    Thank you for taking your time to reply and correcting my mistakes.  I have few qns about the nature of multiple stops.

    Looking at the code below, when the code open a long trade, it sends the StopLoss (SL) order as SL1.  Then after the first partial profit taking, it sends the SL orders as SL2.  My question is, is the SL1 order cancelled and a new SL oda SL2 is sent?  Likewise after 2nd profit taking, the algo set SL as SL3.  So at any point in time, there is only one SL order, which in this case the latest one SL3 right (no more SL1 and SL2 oda).  Is my understanding correct?

    Also  “Set Stop Loss 0 ” before exiting the endif ?

    Thanks!

     

     

    #175727

    How does the complete code look like?

    How does the backtest look like?

    #175754

    The code is in #175475.  Its not really a trading strategy as I am just experimenting with stop loss and limit orders.

    #175761

    I never tried setting  different SLs that way, as I use pending STOP orders, but they seem correct. If they work, then they are! 🙂

    simply removes any active SL.

    1 user thanked author for this post.
Viewing 13 posts - 1 through 13 (of 13 total)

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