no trade in non trending market

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #63478 quote
    George65
    Participant
    Senior

    Hi,

    Anyone has any experiences how to code if we do not want automatic trading running if the market moves sideways?

    Thanks

    George

    #63501 quote
    robertogozzi
    Moderator
    Master

    There are several ways, a pair of Moving Averages with small (you have to tell what small is for you) differences, Bollinger Bands narrowing for, say, two consecutive bars, no price movement over “n” pips for at least “x” bars….It’s up tou you to tell when a range is starting.

    It’s a lot easier to spot it on a chart, especially when it ends!

    #63503 quote
    George65
    Participant
    Senior

    Thanks Roberto, would you post a short example if you have time!? Thanks again

    #63506 quote
    robertogozzi
    Moderator
    Master

    This Nicolas‘post when, as a novice, I needed some help https://www.prorealcode.com/topic/detecting-a-range/#post-10338.

    The following example uses narrowing Bollinger Bands for just 1 (or whatever number you want to set) bar.

    First you have to define a BB:

    // Set up a Bollinger Band
    ONCE BBavg = 20                                        //20-period BB
    ONCE BBdev = 2.0                                       //2.0 BB Deviation
    BBmean = average[BBavg,0](close)                       //BB mean (middle line)
    BollUP = BBmean + ((std[BBavg](close)) * BBdev)        //BB Upper Band
    BollDN = BBmean - ((std[BBavg](close)) * BBdev)        //BB Lower Band

    Then you have to determine when the BB starts narrowing,  because the price is likely to enter a range:

    // Determine current status of BB (Narrowing)
    ONCE NarrowingBars = 1     //You may want to change this to suit your needs
    Narrow = (summation[NarrowingBars]((BollUP < BollUP[1]) AND (BollDN > BollDN[1])) = NarrowingBars)

    Now you can use the variable NARROW to check whenever you want:

    IF Your_Conditions AND not Narrow THEN....
    Nicolas thanked this post
    #63508 quote
    George65
    Participant
    Senior

    Thank you!!

    #63516 quote
    grimweasel47
    Participant
    Senior

    I find the best practise is using highs and lows. By definition a trend can only exist (up) if prices are making higher highs and higher lows.

    #63519 quote
    grimweasel47
    Participant
    Senior
    ema = exponentialaverage[48](close)
    ema2 = exponentialaverage[24](close)
    
    //set trend using highs and lows
    Trend1= highest[2](high)
    Trend2= highest[5](high)
    Trend3 = trend1-trend2
    ///
    Trend4= lowest[2](low)
    Trend5= lowest[5](low)
    Trend6 = trend4-trend5
    
    ////add trend3 and trend6 commands to code
    Long = (emaabove and trend3 <0) 
    Short = (emabelow and trend6 >-1)

    I use the above code. I have found it does well at keeping you out of sideways markets but is not perfect so any edits that people might have would be useful. Different FX pairs behave differently for the second value [n] depending on what time or other variables control your entry criteria.

    Nicolas and robertogozzi thanked this post
    #63527 quote
    George65
    Participant
    Senior

    Thank you!

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

no trade in non trending market


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
George65 @george65 Participant
Summary

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

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