using candles to define stops

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #84654 quote
    chris
    Participant
    Junior

    hi

    I’m trying to figure out how to use candles to define the initial stop as well as the exit.  I have attached what I have coded so far, which runs though doesn’t quite capture what I am trying to do.

    For long positions, the initial stop would be the low of the opening candle or previous candle and for short positions the stop would be the high of the opening candle or previous candle.

    For long positions, the exit is a stop order below a bull candle with a body > 50% ATR and for short positions, the exit is a stop order above a bear candle with a body >50% ATR.  The obvious problem is the stop order expires after the close of the following candle – is there some way to keep the stop at that level? I have done the video training on loops though am not yet experienced or smart enough to figure it out 🙂

    Any tips or suggestions greatly appreciated,

    cheers

    Chris

    // Definition of code parameters
    DEFPARAM CumulateOrders = false // Cumulating positions
    Position = 1
    ma = triangularAverage[10](close)
    myatr = factor*AverageTrueRange[period](close)
    longcross = close crosses over ma
    shortcross = close crosses under ma
    bullcandle = close - open > myatr
    bearcandle = open - close > myatr
    
    // Conditions to enter long positions
    IF longcross and bullcandle then
    BUY Position CONTRACT AT high + 0.0001 stop
    set stop loss low[0]
    endif
    
    // Conditions to exit long positions
    if longonmarket and bullcandle then
    stopsignal = low
    sell at highest[5](stopsignal) -0.0001 stop
    else
    stopsignal = 0
    endif
    
    // Conditions to enter short positions
    IF shortcross and bearcandle THEN
    SELLSHORT Position CONTRACT AT low - 0.0001 stop
    set stop loss high[0]
    ENDIF
    
    // Conditions to exit short positions
    if shortonmarket and bearcandle then
    stopsignal = high
    exitshort at stopsignal +0.0001 stop
    else
    stopsignal =0
    endif
    
    // Stops and targets
    
    #84656 quote
    Leo
    Participant
    Veteran

    Hi. when the condition, make a variable than save the barindex of the crossing. Like CrossingPosition=barindex

    Then make another condition for decide how many bars after crossing you still wanted tho open trades. Like: lowest[5](conditionToTrade)=1

    Then set the set stoploss at low[barindex-CrossingPosition]

    Keep learning! That’s the most important thing.

    chris thanked this post
    #84681 quote
    robertogozzi
    Moderator
    Master

    One suggestion, try to avoid using +-0.0001, since it is instrument dependent, use

    + 1 * pipsize  //or -1 * pipsize

    instead and let ProOrder do the math.

    Between lines 13 and 14 insert the following

    SL = low[0]

    then replace line 14 with

    set stop loss SL
    do the same at line 28 with high[0].
    This will save your SL values, they will only be overwritten when conditions at line 12 and 26 will be true again.
    chris thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

using candles to define stops


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
chris @oceanchris Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by robertogozzi
7 years, 3 months ago.

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