Suggestions on how to stop opening a trade against the trend

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #151255 quote
    CapnCrunch77
    Participant
    Junior

    Hello All,

    Has anyone got any recommendations as to what kind of code could be used to stop trades been automatically opened when it’s against the prevailing trend?  The attached and circled trade is the example whereby my programme still executed a BUY long which was stopped out due but I’m kind of stuck on what would be a good means of validation?  I keep thinking something along the lines of ‘if average of the last 2 MA periods is lower than the average of the prior 3, do not trade’…..but no idea how I put that into code.  Ideas welcome!

    Falling-Trend-Trade-Error.png Falling-Trend-Trade-Error.png
    #151262 quote
    Monochrome
    Participant
    Senior
    ma=Average[30](close)
    
    avg2period =Average[2](ma)
    
    avgprior3 = (ma[3]+ma[4]+ma[5])/3
    
    buycond = maofma>avgprior3 
    
    If buycond and (your conds) then 
    buy 1 contract at market
    endif
    

    Something like that? Not tested.

    You could just use- if ma[1]>ma[2]. This would be the simplest

    You could also experiment with Heikin ashi, macd and use of multi time frame. These might help you filter.

    #151275 quote
    Vonasi
    Moderator
    Master

    monochrome – Your code won’t work as you have not defined maofma.

    #151283 quote
    Monochrome
    Participant
    Senior

    Oops my bad. Meant  to be –

    buycond= Avg2period>avgprior3
    #151347 quote
    CapnCrunch77
    Participant
    Junior

    Interesting.  Thanks Monochrome!  Not sure how this works for multi time frame then?

    #151350 quote
    Vonasi
    Moderator
    Master

    Trend is pretty impossible to define. A trend in a 1 minute chart might be the opposite of a trend in a 5 minute chart which might be the opposite of a 1 hour chart which disagrees with a 4 hour chart which is opposite of a daily chart which goes the opposite direction to a weekly chart which disagrees with a monthly chart.

    Try to work out all these trends with a lagging moving average and you get lots of lagging opinions of direction of trend based on something that happened a while back – so isn’t actually current trend.

    Trying to define trend to use as a filter to avoid trades is a very difficult thing to do because one man’s monthly trend is the opposite to another man’s hourly trend and by the time you have decided it is a trend it is most likely reversing direction.

    #151351 quote
    XORANDNOT
    Participant
    Senior

    Trend direction is primarily given by (smoothed) moving averages.

    The upcoming end of a trend can be indicated early by the TRIX indicator : when TRIX changes color, a trend may weaken because momentum – as indicated by TRIX – decreases.

    The ADX indicator in combination with ADXR also shows whether a trend is still running or weakening. ADX > ADXR and ADX > ADX[1] means trend is still running and intact on a specific timescale. ADX < ADXR means no trend prevailing.

    Combination of all three indicators : MA, TRIX and ADX can give a good indication whether a trend is still intact. False signals included, as always.

    #151383 quote
    nonetheless
    Participant
    Master

    I’m a great believer in Charles Dow’s idea of Primary, Secondary and Minor trends. Your execution is usually on the minor trend, as that is where the action is. The Primary and Secondary trends would be defined in relation to that. So if you were working on a daily chart, you might be looking at Monthly and Weekly  for your primary and secondary trends.

    At the 5m level as your minor trend, I find that a Secondary trend at 15m and Primary at 2h often works well. For scalping it might be 1m, 5m, 15m. It all depends on how long a game you want to play.

    There are lots of ways to identify trends at different TFs – Wilder’s Smoothing MA, SuperTrend, SAR etc etc. You have to play around and see what works best.

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

Suggestions on how to stop opening a trade against the trend


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/23/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...