Closing Price January Higher than December Close

Viewing 13 posts - 16 through 28 (of 28 total)
  • Author
    Posts
  • #232606 quote
    Lambo
    Participant
    New

    Thank you very much Roberto.

    It Works.

    Do you have an idea how i can integrate the Idea buy “day>24”, because with the code you buy this year on 30.1 , 29.2. and 28.3, right would be 25.1, 26.2 and 25.3.

    Thanks a lot

    #232686 quote
    Lambo
    Participant
    New

    Hello Roberto,

    i Failed to change the code for another January Strategie. Perhaps you can help me:

    If Close of January is higher than Open of January than it is allowed to buy

    on First Trading day of February and on every 25 th of every month until the end of the year

    Close trade is the same a new 200 Day High

    and SL SMA200 *0,97

     

    Thanks a lot

    It is very difficult with the tally for me.

    #236419 quote
    robertogozzi
    Moderator
    Master

    Thank you very much Roberto.

    It Works.

    Do you have an idea how i can integrate the Idea buy “day>24”, because with the code you buy this year on 30.1 , 29.2. and 28.3, right would be 25.1, 26.2 and 25.3.

    Thanks a lot

    Sorry for the Delay!

    ONCE EntryDay  = 24
    ONCE MonthDay1 = 5
    ONCE MonthDay2 = 10
    ONCE Tally     = 0
    ONCE AboveFlag = 0
    
    // ate the beginning of each year save the closing price of the previous year
    IF OpenYear <> OpenYear[1] THEN
    YearClose = close[1]
    AboveFlag = 0
    ENDIF
    
    // at the beginning of each Month reset the tally of trading days to zero
    IF (OpenMonth <> OpenMonth[1]) THEN
    Tally     = 0
    ENDIF
    
    // each new day updates the tally
    IF (OpenDay <> OpenDay[1]) THEN
    Tally     = Tally + 1
    ENDIF
    
    // between day 5 and day 10 check if the price is above the previous Year's closing price
    IF (Tally >= MonthDay1) AND (Tally <= MonthDay2) AND (OpenMonth = 1) THEN
    AboveFlag = max(AboveFlag,close > YearClose)
    ENDIF
    
    // enter after trading day 24 if conditions are met
    IF (OpenDay >= EntryDay) AND AboveFlag AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // TAKE PROFIT: exit when the price closes below DONCHIAN UP
    ONCE p = 20
    Upper  = HIGHEST[p](HIGH[1])
    TPflag = close > Upper
    IF LongOnMarket AND TPflag THEN
    SELL AT MARKET
    ENDIF
    
    // STOP LOSS: exit when the price closes below (Sma200 - 3%)
    Sma200 = average[200,0](close) * 0.97
    SLflag = close < Sma200
    IF LongOnMarket AND SLflag THEN
    SELL AT MARKET
    ENDIF
    // debugging section
    //graphonprice YearClose coloured("Blue")
    //graphonprice Sma200    coloured("Fuchsia")
    //graph        Tally
    //graph        AboveFlag
    #236420 quote
    robertogozzi
    Moderator
    Master

    Hello Roberto,

    i Failed to change the code for another January Strategie. Perhaps you can help me:

    If Close of January is higher than Open of January than it is allowed to buy

    on First Trading day of February and on every 25 th of every month until the end of the year

    Close trade is the same a new 200 Day High

    and SL SMA200 *0,97

    Thanks a lot

    It is very difficult with the tally for me.

    There you go:

    DEFPARAM CumulateOrders = true
    // check if JANUARY is a bullish month
    Timeframe(Monthly)
    ONCE TradeOK = 0
    If OpenMonth = 1 THEN
       TradeOK = 0
       IF close > open THEN
          TradeOK = 1
       ENDIF
    ENDIF
    //
    Timeframe(Daily,UpdateOnClose)
    //
    IF (OpenMonth > 1) AND TradeOK AND ((OpenMonth <> OpenMonth[1]) AND Not OnMarket) OR ((OpenMonth > 1) AND (OpenDay >= 25) AND (abs(CountOfPosition) < 2))  THEN
       SL = average[200,0](close) * 0.97
       BUY 1 CONTRACT AT MARKET
       SET STOP LOSS SL
    ENDIF
    //
    HH = highest[200](high[1])
    IF LongOnMarket AND (high >= HH) THEN
       SELL AT MARKET
    ENDIF
    graphonprice HH AS "new 200-day High" coloured("Blue")
    graphonprice SL AS "Srop Loss"        coloured("Red")
    graphonprice TradePrice
    #245998 quote
    Lambo
    Participant
    New

    Hello Roberto,

    the code doesn’t work as estimated

    TimeFrame(Yearly)
    ClosePreviousYear = Close[1]

    with this parameter i get the information for the hole year.

    How can I get a yes for a if /else  when I prove the condition in january but I am actually in april?

    // Prüfen, ob mindestens ein Schlusskurs zwischen dem 6. und 12. Januar höher ist als der Schlusskurs des Vorjahres
    IF (Month = 1 AND (Day >= 6 AND Day <= 12) AND Close > ClosePreviousYear) THEN
    Januarbarometer = 1 // Speichert die Bedingung für das ganze Jahr

    else

    Januarbarometer = 0
    ENDIF

    // Kauforder am 25. jedes Monats, wenn Bedingung erfüllt ist
    IF NOT LongOnMarket AND Day = 25 AND Januarbarometer = 1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF

    I didn’t get it with this one

    #246001 quote
    Lambo
    Participant
    New
    TimeFrame(Yearly)
    ClosePreviousYear = Close[1]
    
    // Zurück zur täglichen Zeitebene
    TimeFrame(Daily)
    
    // Prüfen, ob mindestens ein Schlusskurs zwischen dem 6. und 12. Januar höher ist als der Schlusskurs des Vorjahres
    IF (Month = 1 AND (Day >= 6 AND Day <= 12) AND Close > ClosePreviousYear) THEN
    Januarbarometer = 1  // Speichert die Bedingung für das ganze Jahr
    ELSE
    Januarbarometer = 0
    ENDIF
    
    
    
    // Kauforder am 25. jedes Monats, wenn Bedingung erfüllt ist
    IF NOT LongOnMarket AND Day = 25 AND Januarbarometer = 1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF

     

    #246002 quote
    Lambo
    Participant
    New

    I found the mistake. I changed something in your origine code which worked. sorry

    but one thing doesn’t worked

    if the code get stopped out it buys again. The code only have to buy on the first trading day =24

    #246004 quote
    Lambo
    Participant
    New

    // Setze den TimeFrame auf jährlich, um den Schlusskurs des Vorjahres zu speichern
    TimeFrame(Yearly)
    ClosePreviousYear = Close[1]

    // Zurück zur täglichen Zeitebene
    TimeFrame(Daily)

    ONCE EntryDay = 24
    ONCE MonthDay1 = 9
    ONCE MonthDay2 = 11
    ONCE Tally = 0
    ONCE AboveFlag = 0

    // ate the beginning of each year save the closing price of the previous year
    IF OpenYear <> OpenYear[1] THEN
    YearClose = close[1]
    AboveFlag = 0
    ENDIF

    // at the beginning of each Month reset the tally of trading days to zero
    IF (OpenMonth <> OpenMonth[1]) THEN
    Tally = 0
    ENDIF

    // each new day updates the tally
    IF (OpenDay <> OpenDay[1]) THEN
    Tally = Tally + 1
    ENDIF

    // between day 5 and day 10 check if the price is above the previous Year’s closing price
    IF (Tally >= MonthDay1) AND (Tally <= MonthDay2) AND (OpenMonth = 1) THEN AboveFlag = max(AboveFlag,close > YearClose)
    ENDIF

    // enter after trading day 24 if conditions are met
    IF (OpenDay >= EntryDay) AND AboveFlag AND Not OnMarket and day<28 and day>24 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF

    if longonmarket and day>4 then
    sell at market
    endif

    #246005 quote
    Lambo
    Participant
    New

    I use this code

    in SUP Index  i have this situation:

    ON 10 January the close is under the close of 2024. But the code buy on 27.1

    Januarbarometer_wrong.png Januarbarometer_wrong.png
    #246235 quote
    robertogozzi
    Moderator
    Master

    What use is NOT in this line:

    IF (OpenDay >= EntryDay) AND AboveFlag AND Not and day<28 and day>24 THEN

    ?

    #246255 quote
    Lambo
    Participant
    New

    Good Morning Roberto, thanks for answering. I am on SP500 Daily, so i have backtesting since 1950.

    #246256 quote
    Lambo
    Participant
    New
    // Setze den TimeFrame auf jährlich, um den Schlusskurs des Vorjahres zu speichern
    TimeFrame(Yearly)
    ClosePreviousYear = Close[1]
    
    // Zurück zur täglichen Zeitebene
    TimeFrame(Daily)
    
    ONCE EntryDay  = 24
    ONCE MonthDay1 = 9
    ONCE MonthDay2 = 11
    ONCE Tally     = 0
    ONCE AboveFlag = 0
     
    // ate the beginning of each year save the closing price of the previous year
    IF OpenYear <> OpenYear[1] THEN
    YearClose = close[1]
    AboveFlag = 0
    ENDIF
     
    // at the beginning of each Month reset the tally of trading days to zero
    IF (OpenMonth <> OpenMonth[1]) THEN
    Tally     = 0
    ENDIF
     
    // each new day updates the tally
    IF (OpenDay <> OpenDay[1]) THEN
    Tally     = Tally + 1
    ENDIF
     
    // between day 5 and day 10 check if the price is above the previous Year's closing price. If it is correct you are allowed to buy every month on 25. th
    IF (Tally >= MonthDay1) AND (Tally <= MonthDay2) AND (OpenMonth = 1) THEN
    AboveFlag = max(AboveFlag,close > YearClose)
    ENDIF
     
    // enter after trading day 24 if conditions are met. but you only allowed to buy once in a month!!!
    IF day<28 and day>24 and (OpenDay >= EntryDay) AND AboveFlag AND not OnMarket  THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    
    //Exit after the month beginning
    if longonmarket and day>4 then
    sell at market
    endif
    #246257 quote
    Lambo
    Participant
    New

    there was missing not on market… i put the code here.

    robertogozzi thanked this post
Viewing 13 posts - 16 through 28 (of 28 total)
  • You must be logged in to reply to this topic.

Closing Price January Higher than December Close


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Lambo @lambo Participant
Summary

This topic contains 27 replies,
has 3 voices, and was last updated by Lambo
9 months, 4 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/08/2024
Status: Active
Attachments: 5 files
Logo Logo
Loading...