Moving Average Slope 1Hr Strategy

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #50649 quote
    juanj
    Participant
    Master

    I coded the below indicator provided by @MAZ into a strategy for EURUSD 1Hr

    Moving Average Slope

    Defparam cumulateorders = False
    
    possize = 1
    
    LMA = Average[200](close)
    MA = Average[26](Close)
    slope = MA - MA[1]
    
    If slope > 0 then
    once GS = slope
    AGS = (GS + slope)/2
    ga = 0
    gb = 0
    For a = 0 to 29 Do
    If slope[a] > slope[a+1] Then
    ga = ga + 1
    ElsIf slope[a] < slope[a+1] then
    gb = gb + 1
    Endif
    Next
    GS = AGS
    ElsIf slope < 0 then
    once RS = slope
    ARS = (RS + slope)/2
    ra = 0
    rb = 0
    For b = 0 to 29 Do
    If slope[b] < slope[b+1] Then
    ra = ra + 1
    ElsIf slope[b] > slope[b+1] then
    rb = rb + 1
    endif
    Next
    RS = ARS
    Endif
    
    If countofposition = 0 and close > LMA and slope > (AGS+(AGS*0.618)) Then
    Buy possize contract at market
    ElsIf countofposition = 0 and close < LMA and slope < (ARS+(ARS*0.618)) Then
    Sellshort possize contract at market
    EndIf
    
    If longonmarket and (slope < (AGS+(AGS*0.618)) or gb >= ga) Then
    Sell at market
    ElsIf shortonmarket and (slope > (ARS+(ARS*0.618)) or rb >= ra) Then
    Exitshort at market
    EndIf
    
    Henrik, Berra, Nicolas and soad41 thanked this post
    #50659 quote
    BC
    Participant
    Master

    Thanks for share, will try it tonight.

    Berra and soad41 thanked this post
    #51736 quote
    Yannick
    Participant
    Veteran

    Hello Juanj

    Thanks for sharing.

    Could you explain the concept of this ? ( I don’t understand the 0.618 value)

    slope > (AGS+(AGS*0.618))

     

    Regards

    #51751 quote
    BC
    Participant
    Master

    0.618 is  a important number of Fibonnacci number sequence.

    https://en.m.wikipedia.org/wiki/Golden_ratio

    #51756 quote
    Yannick
    Participant
    Veteran

    Hi

    I Know that 0.618 is the golden number and the ratio of infinite convergence of Fibonnaci serie.

    it is used in trading for retracement of waves but why is it used in slopes of moving average ?

    regards

    #51761 quote
    juanj
    Participant
    Master

    @Yannick simple answer it works well. I use an optimization algorithm during backtesting that I graph to track optimal values during different points in the backtested period and found that ~0.6 is frequently the optimal value. I then just decided to make it 0.618 for the heck of it.

    #51976 quote
    JR1976
    Participant
    Veteran

    HI JuanJ,

    good work for the code , seems interest

    Just a question ,  Did you test it on 200k  bar  ?

    Thanks

    #104800 quote
    nfulcher
    Participant
    Average

    Hi, very interesting post. Can somebody please help with my understanding as I’m new to the site.

    In the code above, it includes a For/Next Loop in which the ‘user variable’ slope is incremented through each pass of the loop.

    For a = 0 to 29 Do
    If slope[a] > slope[a+1] Then
    ga = ga + 1
    ElsIf slope[a] < slope[a+1] then
    gb = gb + 1
    Endif
    Next

    Is this piece of code testing the change in the Moving Average (MA) of each of the last 30 (0 to 29) bars and incrementing ga and gb accordingly?

    If so, does it somehow pass the bar reference number (a) to the slope calculation at the start of the code further up (slope = MA – MA[1]) to calculate the step – or have I got this completely wrong?

    I appreciate any help to understand this better.

    Thanks.

    #104801 quote
    robertogozzi
    Moderator
    Master

    It is used to eventually exit LONG trades at line 43.

    nfulcher thanked this post
    #104808 quote
    nfulcher
    Participant
    Average

    Thanks Roberto.

    I’m still a little confused with the coding – doesn’t the ‘slope = MA MA[1]’ need to be nested within the For-Next loops – or does PRC know to look back up the code to find ‘slope’ calculation and recalculate it for each change in [a] and [b] (‘slope [a] > slope[a+1]’) ?

    #104813 quote
    robertogozzi
    Moderator
    Master

    Line 7 is the base to start with. It changes each new candle.

    The code later scans the past 30 (0 – 29) MA slopes to accomplish its goal.

    slope [a] > slope[a+1]

    will be translated, at run time, with:

    (MA[a] - MA[a+1]) > (MA[a+1] - MA[a+2])
    #104815 quote
    nfulcher
    Participant
    Average

    Thanks Roberto, makes perfect sense.

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

Moving Average Slope 1Hr Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
juanj @juanj Participant
Summary

This topic contains 11 replies,
has 6 voices, and was last updated by nfulcher
6 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/26/2017
Status: Active
Attachments: No files
Logo Logo
Loading...