Automatically place a reverse trade

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #67138 quote
    Lisa Beaney
    Participant
    Junior

    I wonder if anyone can help… I’m trying to write code so that a new order is placed automatically if our stop is hit. For example we go long on the DAX with a stop of 14. The DAX falls and hits our stop. I then want to automatically open a new order to go short with a stop and limit in place for the new trade….

    #67139 quote
    Despair
    Blocked
    Master

    Show us how far you got with this.

    I assume your stop is a pending stop order? In that case the new order can be triggered at the open of the next bar. More instantly I think it is not possible with PRT.

    #67141 quote
    GraHal
    Participant
    Master

    An entry Buy limit order at same price level as the exit sell stop order or vice versa?

    #67143 quote
    Despair
    Blocked
    Master

    Good idea Grahal! Might end up in some case that not both orders are filled simultaneously though.

    Ah how stupid. Just place a stop order of double size so you end up with a switched position and don’t risk that only one side was filled. Jesus I better go to bed again. 🙂

    GraHal thanked this post
    #67147 quote
    Lisa Beaney
    Participant
    Junior

    The stop is coded as :

    SET STOP pLOSS vSLoss

    It is when this stop is triggered I want to enter the new trade. If the original trade moves in to profit I then start trailing the stop up…..

    This is the code to trail the stop :

    // Check if the short is in profit. If so put our locked in limit in place
    IF SHORTONMARKET THEN
    vProfit = tradeprice(1) - close
    vTarget = iATR * vATR
    IF vProfit > 0 THEN //check if we are in profit
    IF (iSuperTrend1 + vSLvar ) < (tradeprice(1) + vSLoss) THEN //Check that the SuperTrend is above our stop
    newSL = (iSuperTrend1 + vSLvar)
    ENDIF
    IF vProfit > vTarget AND newSL > (tradeprice(1) - vLock) THEN
    newSL = tradeprice(1) - vLock
    ENDIF
    ELSE
    IF (iSuperTrend1 + vSLvar ) < (tradeprice(1) + vSLoss) THEN //Check that the SuperTrend is above our stop
    newSL = (iSuperTrend1 + vSLvar)
    ENDIF
    ENDIF
    ENDIF

     

    I have the reverse of this code for Buy trades.

    #67148 quote
    Despair
    Blocked
    Master

    Like I wrote above. Don’t use SET STOP PLOSS. Just place a normal stop order at the desired level but double the positionsize. Then you will end up with an reversed position.

    BTW your code is much easier to read if you use the “insert code” function and not simply copy/paste it in the text.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Automatically place a reverse trade


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Despair
7 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/04/2018
Status: Active
Attachments: No files
Logo Logo
Loading...