Moving averages clustering

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #75044 quote
    Bullets
    Participant
    Junior

    I posted this previously in the wrong section – see below if anyone can assist?

    Does anyone know how to program up a clustering of moving averages.

    I.e. I don’t want to take a trade if for example the following moving averages are within X pips together

    MA(5)

    MA(20)

    MA(50)

    MA(100)

    MA(200)

    Any assistance would be appreciated.

    Thanks

    #75053 quote
    Vonasi
    Moderator
    Master

    I have deleted your identical post in the Platform Support forum.

    #75056 quote
    robertogozzi
    Moderator
    Master

    Not tested

    x     = 10 * pipsize           //10-pip range
    ma5   = average[5,0](close)
    ma20  = average[20,0](close)
    ma50  = average[50,0](close)
    ma100 = average[100,0](close)
    ma200 = average[200,0](close)
    MaxMA = max(ma5,max(ma20,max(ma50,max(ma100,ma200))))
    MinMA = min(ma5,min(ma20,min(ma50,min(ma100,ma200))))
    IF (MaxMA - MinMA) <= x THEN
       //they are within X pips
    ENDIF
    Nicolas thanked this post
    #75065 quote
    GraHal
    Participant
    Master

    Added to here Snippet Link Library

    robertogozzi and Andre Vorster thanked this post
    #75083 quote
    Bullets
    Participant
    Junior

    Awesome, that works perfectly! thank you

    #84382 quote
    Leo
    Participant
    Veteran

    Hi.

    Have someone tried to implement this in a robot?

    Like entry if close > maxMA?

    Thanks in Advace

    #84397 quote
    robertogozzi
    Moderator
    Master

    I never tried, but it can be worth trying.

    #84399 quote
    robertogozzi
    Moderator
    Master

    This is some quick code (see attached pic):

    DEFPARAM CumulateOrders = false
    ONCE Sl         = 0
    ONCE Tp         = 0
    ONCE Multiplier = 2.0                        //2.0  multiplies SL to set TP
    ONCE LookBack   = 2                          //2    candles to set SL to low/high
    ONCE PipRange   = 10 * pipsize               //10-pip range
    ONCE AvgType    = 6                          //6 = time series
    ma5             = average[5,AvgType](close)
    ma20            = average[20,AvgType](close)
    ma50            = average[50,AvgType](close)
    ma100           = average[100,AvgType](close)
    ma200           = average[200,AvgType](close)
    MaxMA           = max(ma5,max(ma20,max(ma50,max(ma100,ma200))))
    MinMA           = min(ma5,min(ma20,min(ma50,min(ma100,ma200))))
    IF (MaxMA - MinMA) <= PipRange THEN
       IF close CROSSES OVER MaxMA THEN
          Sl = close - lowest[LookBack](low)
          BUY 1 CONTRACT AT MARKET
       ELSIF close CROSSES UNDER MinMa THEN
          Sl = highest[LookBack](high) - close
          SELLSHORT 1 CONTRACT AT MARKET
       ENDIF
       Tp = Sl * Multiplier
       SET TARGET PROFIT Tp
       SET STOP   LOSS   Sl
    ENDIF
    Nicolas thanked this post
    x-3.jpg x-3.jpg
    #84402 quote
    Leo
    Participant
    Veteran

    Looks awesome!

    Thanks!

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Moving averages clustering


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Bullets @bullets Participant
Summary

This topic contains 8 replies,
has 5 voices, and was last updated by Leo
7 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/02/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...