Trailing stop function – what are the STOP orders for?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #178651 quote
    sulimaster
    Participant
    Average
    //trailing stop function
    trailingstart = 10 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
    newSL = tradeprice(1)+trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND close>close[1] THEN
    newSL = newSL+trailingstep
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
    newSL = tradeprice(1)-trailingstep
    //newSL = close + (1 * trailingstep)
    ENDIF
    //next moves
    IF newSL>0 AND close<close[1] THEN
    newSL = newSL-trailingstep
    //newSL = close + (1 * trailingstep)
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF

    Hi

    In this trailing stop function, what is the purpose of STOP in the last commands SELL AT newSL STOP and EXITSHORT AT newSL STOP? Is it a stop loss command or does it stop the code from continuing to run the commands after STOP if the conditions are met?

    Thanks

    Sachin

    #178652 quote
    MauroPro
    Participant
    Veteran

    In this page of the blog  you will find the explanation of the code :

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

    sulimaster thanked this post
    #178653 quote
    Nicolas
    Keymaster
    Master

    It is a pending STOP order.

    sulimaster thanked this post
    order_types-2.jpg order_types-2.jpg
    #178831 quote
    sulimaster
    Participant
    Average

    Hi Nicholas

    Thanks for clarifying.

    Does the code in the below page of the blog incorporate a minimum stop distance required by the broker? e.g. a minimum stop distance of 10 points for any instrument?

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

    Thanks

    Sachin

    #178832 quote
    robertogozzi
    Moderator
    Master

    This is Nicolas’ code with the addition of distance and a delayed execution https://www.prorealcode.com/topic/problemi-con-broker-ig-riguardo-lutilizzo-di-algo-con-trailing-stop-e-trailing/#post-175071

    Distance is at line 9.

    Delayed execution is at line 6, just replace 0 with any number to delay execution for N bars from entry.

    sulimaster thanked this post
    #231845 quote
    Aragorna
    Participant
    Junior

    Dear Roberto,

    this code for trailing stop works also for Interactive broker?

    kind regards

     

    Alessio

    #231857 quote
    robertogozzi
    Moderator
    Master

    I don’t know, as I don’t use IB.

    If the ProRealTime language is wholly supported, it should, but that’s just speculation.

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

Trailing stop function – what are the STOP orders for?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
sulimaster @sulimaster Participant
Summary

This topic contains 6 replies,
has 5 voices, and was last updated by robertogozzi
1 year, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/28/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...