Trend continuation strategy

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

    Hi all,

    A little help/advice required please. I have a breakout FX strategy that involves buying/selling under certain trending conditions (using MAs and close above/below)

    What I would like to do is only buy/sell above the most recent swing low/high to the left of the chart. Ie the previous high or low visible on the chart. It’s easy to see with the eye manually, but less so to code.

    I have been using the code below:

    ema = exponentialaverage[50](close)
    ema2 = exponentialaverage[12](close)
    //set trend using highs and lows
    trend1= highest[1](high)
    trend2= highest[7](high)
    Trend3 = (trend1-trend2)
    ///
    trend4= lowest[1](low)
    trend5= lowest[7](low)
    Trend6 = (trend4-trend5)
    
    EMAabove = ema2>ema
    EMAbelow = ema2<ema
    atr = averagetruerange[24]
    hh = highest[2](high)+2
    ll = lowest[2](low)-2
    //Filter = ema2-ema2[16]
    Filter2 = ema2-ema2[2]
    Long = (emaabove and trend3<0 and filter2>0 )
    Short = (emabelow and trend6>-1 and filter2<0 )

    ..but wondered if our community had spotted a better definition of ‘trend’ that would be more applicable? Maybe Donchain channel?

    The issue with the above code is that, in this case, highest[1] and highest[7] seems to produce the best results for pair in question on backtest, but I want it to be more dynamic, that is spotting the previous H1 swing high or low, not a calculation of the past [n] bars?

    Any help appreciated!

    #76725 quote
    robertogozzi
    Moderator
    Master

    Line 4 can be written

    trend1= high

    since the highest price within the most recent bar (just 1 bar)  is the current one refernced by [0] or by null.

    Line 5 should reference, if I understood what you want to achieve, HIGH[1], rather than HIGH, since you already found a high in line 4 and you want to find another higher previously form, so it should be:

    trend2= highest[7](high[1])

    otherwise you would have a chance that both HIGHs are the same, if they happen in the last of 7 bars.

    A BULLish trend is defined as HIGHER highs and HIGHER lows.

    A BEARish trend is defines as LOWER   highs and LOWER   lows.

    You may search this forum to find examples.

    #76844 quote
    grimweasel47
    Participant
    Senior

    Thanks for that Robert, yes I was trying to check the trend using the definition of high highs/lower lows for a given chart using the candle at activation time – ie if I want the strategy to start at 0800 and go long then only if price goes higher than the highest high over the last [n] bars.

    #76943 quote
    robertogozzi
    Moderator
    Master
    ONCE n = 10
    IF OpenTime = 080000 AND close > highest[n](high) THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF

    Is that what you mean?

    #76994 quote
    grimweasel47
    Participant
    Senior

    Thanks Robert – I think so yes. I just want to ensure that at pixel time the trade only opens subject to method other rules and final check is that order long/short is only placed above/below the most recent swing high. Is there a more dynamic way of getting PRT to recognise the major swings or do we have to rely on highest [n] bars?
    Thanks

    #77066 quote
    robertogozzi
    Moderator
    Master

    There’s no workaround. Automated strategies cannot do anything different from manual ones, just faster.

    When you sit in front of your PC watching charts you happen very often to spot higher highs (or lower lows), but they are not always swing points. You can tell good swing points from bad ones, when they you see some empty space to their left. In an automated strategy you can estimate empty space with the number of bars to look back. The more they are the more accurate is the swing point.

    The attached pic shows some swing points, one of which is maked with a red cross since it is NOT a swing point, the empty space on the left side is too small!

    So, to go back to your question:

    • n
    • highest[n]/lowest[n]

    are the best way to identify a swing point.

    x-12.jpg x-12.jpg
    #77074 quote
    grimweasel47
    Participant
    Senior

    Super  -thanks for the reply Robert. As I thought! It seems with backtesting that some FX pairs that [n] can be 6 hours and others 24. Would you hypothesise this as being individual characteristics of each pair (zone, liquidity, interest rates etc) or data mining?

    #77083 quote
    robertogozzi
    Moderator
    Master

    The number of LookBack bars, as the periods for MA’s and so on… for DAX is different from those for EUR/USD or SP500.

    Also, those same numbers for EUR/USD h1 are different from those for EUR/USD daily,….

    It’s a matter of spending (hopefully not wasting) many hours testing different settings!

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

Trend continuation strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by robertogozzi
7 years, 7 months ago.

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