Triple moving average filter

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #229028 quote
    borderlineJim
    Participant
    Senior

    hey all!

    I have tried to add a triple moving average filter to one of my systems.  The system only takes short positions on the DAX40 and I want the filter to allow trades when the moving averages are all below each other.  The basic code I am trying to use is:

    timeframe(5 minute, updateonclose)
    ma1 = VolumeAdjustedAverage[m1](close)
    ma2 = VolumeAdjustedAverage[m2](close)
    ma3 = VolumeAdjustedAverage[m3](close)
    
    trendOK = ma1 < ma2 and ma2 < ma3

    The isssue is this.  When I backtest the system appears to be taking orders when the moving averages are not below each other and trending downwards, as specified in the code.  In fact it is placing orders when the averages are all above each other, trending upwards!

    Can anyone help an idiot? Is the code not suffiecent to act as a triple moving average filter, or is something else going wrong?  I can happily post the code and the backtest results if it helps.

    Thanks

    Jim

    #229030 quote
    GraHal
    Participant
    Master

    Is your backtest results showing this …

    trendOK = ma3 > ma2 and ma2 > ma1
    

    Put in a way different to what you say in your post … above is what your code is saying.

    borderlineJim thanked this post
    #229034 quote
    borderlineJim
    Participant
    Senior

    Hi Grahal

    Thanks for the prompt reply! 🙂

    The backtest results show that it takes trades anywhere, regardless of the filter.  The system just doesn’t respect the filter.

    Not sure what is going on.  Having a few issues with V12. Maybe its a software issue?  Sometimes it does strange things when backtesting… not recognising variables in the optimiser window, etc.

     

    Jim

    #229036 quote
    PeterSt
    Participant
    Master

    Jim, put this at the end of your code.

    graph ma1
    graph ma2
    graph ma3

    Then you will probably see what GraHal means. I have the same “feeling”, but it depends on your m1, m2 and m3 and which is the smallest and which is the largest.
    You will see …

    #229037 quote
    borderlineJim
    Participant
    Senior

    Hi Peter

    yes, of course.  These are the values, m1 the smallest always and m3 the largest always.

    m1 = 25, m2 = 45, m3 = 60

    #229038 quote
    GraHal
    Participant
    Master

    not recognising variables in the optimiser window, etc.

    I’ve experienced above also … well weird bug that is!
    Somehow though – and I can’t even say how – I’ve found a work-around as it hasd not happened to me for a few weeks, thankfully!

    #229056 quote
    borderlineJim
    Participant
    Senior

    strange for sure….

    I just can’t figure out why the filter isn’t working and thought maybe it was a similar problem like a bug….

    #229061 quote
    GraHal
    Participant
    Master

    why the filter isn’t working

    A screenshot showing the filter not working might help us to suss out why.

    A snippet of code including how / where you use trendok might also help us to help you. 🙂

    #229332 quote
    robertogozzi
    Moderator
    Master

    It works like a charm to me (as from attached pic), on both an indicator and a strategy.

    Strategy:

    timeframe(5 minute, updateonclose)
    ma1 = VolumeAdjustedAverage[25](close)
    ma2 = VolumeAdjustedAverage[45](close)
    ma3 = VolumeAdjustedAverage[60](close)
    trendOK = ma1 < ma2 and ma2 < ma3
    timeframe(default)
    buy at -close limit
    graph trendOK

    indicator:

    ma1 = VolumeAdjustedAverage[25](close)
    ma2 = VolumeAdjustedAverage[45](close)
    ma3 = VolumeAdjustedAverage[60](close)
    trendOK = ma1 < ma2 and ma2 < ma3
    RETURN trendOK as "trendOK"
    x-1.jpg x-1.jpg
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Triple moving average filter


General Trading: Market Analysis & Manual Trading

New Reply
Author
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by robertogozzi
1 year, 11 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 03/01/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...