Coding for first pullback after price crossed MA50

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #100441 quote
    RiaanvN
    Participant
    Average

    Hi guys,

    I would appreciate some assistance. My favorite trade setup is pulback to MA50 after price crossed MA50 and MA50 is sloping up. Thus an established new trend.

    Any ideas how to code this?

    Thanks!

    #100450 quote
    AlgoAlex
    Participant
    Master

    Could you post some images to clarify?

    #100465 quote
    RiaanvN
    Participant
    Average

    Hi Alex, see attached example of retrace.

    example.png example.png
    #100487 quote
    GraHal
    Participant
    Master

    RiaanvN you will need to state a % closeness to MA50 (after retrace) for your entry  condition.

    Also I guess an exit condition would be if Close carries on through the MA50 … as it did on the last retrace / black MA50?

    #100524 quote
    RiaanvN
    Participant
    Average

    Hello Grahal,

    I would appreciated coding help for following criterias to be met.

    • SMA50 upward sloping for the past 10 bars.
    • SMA50 was downward sloping for at least 10 bars, 50 bars ago. (Range thus between [60] and [50].)
    • Highest pivot low (swing low) for past 50 bars.

    Thanks. Hope to hear from you soon.

    #100525 quote
    GraHal
    Participant
    Master

    I’ll leave the coding to  @AlexF so much better than me! (I struggle with my own coding! 🙂 )

    I was only getting you to specify when exactly the entry trigger should occur when I asked … < % closeness to MA50.

    I doubt you would want a specific entry point, e.g. MA50 + 5 points or = MA50 as it might not get to that point and then turn around zoom upwards while waving goodbye to you waiting there to enter … just like you predicted but you didn’t pull the trigger soon enough!? 🙂

    #100543 quote
    AlgoAlex
    Participant
    Master

    The issue is I don’t see a clear definition of retracement.

    In the picture posted it is clear to human eyes, but an algo need some more specific rules… Like “bitening” of Ma or a new lowest after x bars f. e.

    #100544 quote
    jebus89
    Participant
    Master

    Yea thats the hard part of coding those types of systems. Price might cross over 50MA 3 candles ago and retrace, or 10 candles or 50 candles then retrace.

     

    You need to define that price

    • WAS under ma50
    • WAS “high” above ma50
    • is currently not very high above ma50/retracing back to ma50, without it crossing under it(?)

    edit: just a thought: multiple MA’s?

    #100602 quote
    robertogozzi
    Moderator
    Master

    This is very basic:

    DEFPARAM CumulateOrders = false
    MinLookBack =  2           //2  crossing must have occured at least these bars before PullBack
    MaxLookBack =  17          //17 crossing must have occured at most  these bars before PullBack
    MA50 = average[50,1](close)//50,1
    x = close crosses over ma50
    IF x OR (close > MA50 AND low < MA50) THEN //when a pullback occurs...
       IF summation[MinLookBack](x[1]) = 0 THEN
          IF summation[MaxLookBack](x[MinLookBack + 1]) AND Not OnMarket AND close > open THEN
             BUY 1 CONTRACT AT MARKET
             SET STOP   pLOSS   50    //50
             SET TARGET pPROFIT 300   //300
          ENDIF
       ENDIF
    ENDIF

    When it detects a crossover it is interpreted as a crossover due to pullback if there has been a previous crossover AT LEAST min candles before and AT MOST max candles before.

    #100674 quote
    RiaanvN
    Participant
    Average

    Thanks Roberto! I’m definitely going to try this.

     

    #100718 quote
    GraHal
    Participant
    Master

    This is very basic:

    Sheeesh!!!! 🙂 🙂

    #100719 quote
    robertogozzi
    Moderator
    Master

    Pretty expressive GraHal!

    #100725 quote
    GraHal
    Participant
    Master

    @RobertoGozzi … You knew I was just making some humour for a Saturday morning, right??

    Perhaps I should have added … You ain’t seen my basic! 🙂

    #100731 quote
    robertogozzi
    Moderator
    Master

    I knew that, I was on the same line of humor.

    I wrote BASIC because it lacks trailing stop/break even, money/position management and other amenities!

    GraHal thanked this post
    #100732 quote
    GraHal
    Participant
    Master

    Good results on 10k bars on 1 min TF!  Spread = 4

    Optimise weekly and / or when Gain / Loss ratio drops much below 2.

    The variable settings I chose are well down from the top Gain and are out of sight on attached.  Variable name is Line No (or should be!?).

    I’ll set it going on Demo Fwd Test on Monday.

    Roberto any chance you could do the same on the Short side please pretty please?  Then the whole code will be yours! 

    Pullback.jpg Pullback.jpg Pullback1.jpg Pullback1.jpg Pullback2.jpg Pullback2.jpg
Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.

Coding for first pullback after price crossed MA50


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
RiaanvN @riaanvn Participant
Summary

This topic contains 19 replies,
has 5 voices, and was last updated by robertogozzi
6 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/11/2019
Status: Active
Attachments: 5 files
Logo Logo
Loading...