breakout buy code

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #120397 quote
    lauyintatjasonlauyintatjason
    Participant
    New

    Dear guys,

    I am hoping to write a code for trading.

    ema 50 x ema 200

    accumulate order buy/sell on price break above / below or the previous candle (time frame)

    stop at trailing.

    i try very hard to find it. i hope you guys can help.

    so many thanks

    #120399 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Please use the correct forum, I move the topic to the ProOrder support furum since you are talking about a strategy, while ProBuilder is devoted to indicators.

    Thank you šŸ™‚

    #120407 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    What do you mean by “or the previous candle (time frame)“?

    #120408 quote
    lauyintatjasonlauyintatjason
    Participant
    New

    Hi.

    Thank you for your reply.

    What I mean is break previous price then entry order.

     

    Thanks

    #120409 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    To recap, you want to enter whenever there’s been a crossover of the two MA’s AND price breaks the price of the candle where the croccover occurred or the previous one?

    #120410 quote
    lauyintatjasonlauyintatjason
    Participant
    New

    Yes. Enter after ma cross.

    Then accumulate order of contract after .

    Etc.Ā  Add contract following the trend .

    Condition is, price must break above or below. In order to enter . (Not the next bar)

    With a trailing stop.

    #120424 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go, I tested it on DAX, 4h TF and it seems to work. Let me know if it’s doing what you wanted.

    DEFPARAM CumulateOrders = true
    ONCE CrossOver  = 0
    ONCE CrossUnder = 0
    //---------------------------------------------------------------------
    ONCE AvgType = 1                      //1 = Ema
    Ema50  = average[50,AvgType](close)   //50
    Ema200 = average[200,AvgType](close)  //200
    //---------------------------------------------------------------------
    // check when faster EMA crosses over/under slower EMA
    //
    CrossUnder = Ema50 CROSSES UNDER Ema200
    CrossOver  = Ema50 CROSSES OVER  Ema200
    //---------------------------------------------------------------------
    // enter a LONG  trade
    //
    IF CrossOver  AND Not LongOnMarket THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    //---------------------------------------------------------------------
    // enter a SHORT trade
    //
    IF CrossUnder AND Not ShortOnMarket THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //---------------------------------------------------------------------
    // Accumulate LONG  positions
    //
    IF LongOnMarket  AND close > close[1] THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    //---------------------------------------------------------------------
    // Accumulate SHORT positions
    //
    IF ShortOnMarket AND close < close[1] THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //---------------------------------------------------------------------
    //              Trailing stop function
    //by Nicolas https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function
    //
    trailingstart = 20    //20   trailing will start @trailinstart points profit
    trailingstep  = 20    //20   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-positionprice>=trailingstart*pipsize THEN
          newSL = positionprice+trailingstep*pipsize
       ENDIF
       //next moves
       IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
          newSL = newSL+trailingstep*pipsize
       ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
       //first move (breakeven)
       IF newSL=0 AND positionprice-close>=trailingstart*pipsize THEN
          newSL = positionprice-trailingstep*pipsize
       ENDIF
       //next moves
       IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
          newSL = newSL-trailingstep*pipsize
       ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
       SELL      AT newSL STOP
       EXITSHORT AT newSL STOP
    ENDIF
    //---------------------------------------------------------------------
Viewing 7 posts - 1 through 7 (of 7 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

breakout buy code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/25/2020
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...