Entry counters within the MACD

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #194607 quote
    phoentzs
    Participant
    Master

    I have one more little job for a coder. There is a code snippet 1 trade per day… is it possible to write a similar function on an indicator? I need this function for the MACD:

    Long: MACD crosses over 0, if MACDLINE > 0 Short vice versa

    But only for the 1st cross of the MACD, ideally the following crosses can be counted/optimized. The counter is then reset as soon as the MACDLINE generates a new signal/new swing. Is this doable?

    Explanation in the picture (sorry smartphone) green bar: counter start,

    1-4: possible entries,

    5: reset the counter.

    CBD3FB6A-DB10-4D4B-95D7-52AA59AE0A44.jpeg CBD3FB6A-DB10-4D4B-95D7-52AA59AE0A44.jpeg
    #194753 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM DrawOnLastBarOnly = true
    ONCE Count = 0
    IF IntraDayBarIndex = 0 THEN
       Count = 0
    ENDIF
    IF Macd[12,26,9] CROSSES OVER 0 THEN
       Count = Count + 1
    ENDIF
    x = Count
    IF Count = Count[1] THEN
       x = 0
    ENDIF
    RETURN x AS "Crossover Count"
    #194795 quote
    phoentzs
    Participant
    Master

    Thanks, but I meant it as coding for a strategy. Counting condition Long/Counting start is Cross MACDLINE above 0. Counter reset is Cross MACDLINE below 0 and at the same time counting start for Short. The crosses of the MACD itself are counted, each long and short. I want to find out how many MACD crosses can be lucrative within a swing of the MACDLINE.

    #194828 quote
    robertogozzi
    Moderator
    Master

    Bob’s your uncle:

    ONCE ShortTallyMACD     = 0
    ONCE LongTallyMACD      = 0
    ONCE ShortTallyMACDline = 0
    ONCE LongTallyMACDline  = 0
    //
    MyHISTO    = MACD[12,26,9](close)
    //MySIGNAL = MACDSignal[12,26,9](close)
    MyLINE     = MACDline[12,26,9](close)
    //
    IF MyHisto CROSSES OVER  0 THEN
    LongTallyMACD  = LongTallyMACD + 1
    ShortTallyMACD = 0
    ENDIF
    IF MyHisto CROSSES UNDER 0 THEN
    LongTallyMACD  = 0
    ShortTallyMACD = ShortTallyMACD + 1
    ENDIF
    //
    IF MyLINE CROSSES OVER  0 THEN
    LongTallyMACDline  = LongTallyMACDline + 1
    ShortTallyMACDline = 0
    ENDIF
    IF MyLINE CROSSES UNDER 0 THEN
    LongTallyMACDline  = 0
    ShortTallyMACDline = ShortTallyMACDline + 1
    ENDIF
    //
    buy at -close limit
    //
    Graph ShortTallyMACD
    Graph LongTallyMACD
    Graph ShortTallyMACDline
    Graph LongTallyMACDline
    Midlanddave thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Entry counters within the MACD


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
phoentzs @phoentzs Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/04/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...