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
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.
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
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
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
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
// 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
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
What use is NOT in this line:
IF (OpenDay >= EntryDay) AND AboveFlag AND Not and day<28 and day>24 THEN
?
Good Morning Roberto, thanks for answering. I am on SP500 Daily, so i have backtesting since 1950.
// 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
there was missing not on market… i put the code here.