Coding Strategy to Stop

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

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

    #175747 quote
    NicolasNicolas
    Keymaster
    Legend

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

    #175753 quote
    efahmyefahmy
    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 efahmyefahmy
5 years, 1 month ago.

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