Coding Strategy to Stop

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #175742 quote
    efahmy
    Participant
    Average

    Could you help in coding the strategy to stop after the position is triggered

    #175747 quote
    Nicolas
    Keymaster
    Master

    You can use the QUIT instruction in order to stop a ProOrder strategy.

    #175753 quote
    efahmy
    Participant
    Average

    I added Quit below is that correct ??

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    // VARIABLES
    timeframe(default)
    stepfactor1 = 0.5
    stepfactor2 = 0.25
    myPRCDynamicRSI, myPRCDynamicRSI2, myPRCDynamicRSI3, myPRCDynamicRSI4 = CALL "PRC_DynamicRSI"[0.1, 0.1, 14, 60]
    DM = DEMA[14](close)
    PST = Supertrend[2,10]
    SL = PST - 0.25
    PT = SL * 1.5
    // Conditions to enter long positions
    IF DM < PST AND myPRCDynamicRSI < myPRCDynamicRSI2 THEN
    SELLSHORT 10 CONTRACTS AT MARKET
    ENDIF
    SET STOP pTRAILING SL
    SET TARGET pPROFIT PT
    QUIT
    //====== Trailing Stop mechanism - start =====
    trailingstart = (stepfactor1 * SL )
    trailingstep = (stepfactor2 * SL )
    //resetting variables when no trades are on market
    if not onmarket then
    priceexit = 0
    endif
    //case LONG order
    if longonmarket then
    //first move (breakeven)
    IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN
    priceexit = tradeprice(1) + trailingstep*pointsize
    ENDIF
    //next moves
    IF priceexit>0 THEN
    P2 = close-priceexit >= trailingstart*pointsize
    IF P2 THEN
    priceexit = priceexit + trailingstep*pointsize
    ENDIF
    ENDIF
    ENDIF
    //case SHORT order
    if shortonmarket then
    //first move (breakeven)
    IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN
    priceexit = tradeprice(1) - trailingstep*pointsize
    ENDIF
    //next moves
    IF priceexit>0 THEN
    P2 = priceexit-close >= trailingstart*pointsize
    IF P2 THEN
    priceexit = priceexit - trailingstep*pointsize
    ENDIF
    ENDIF
    ENDIF
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    ENDIF
    //====== Trailing Stop mechanism - end =====
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Coding Strategy to Stop


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
efahmy @efahmy Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by efahmy
4 years, 6 months ago.

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