Prevent you from operating a specific month and week
Forums › ProRealTime English forum › ProOrder support › Prevent you from operating a specific month and week
- This topic has 5 replies, 2 voices, and was last updated 3 years ago by Paolo.B.
Tagged: dayofweek, month, OpenDayOfWeek, prevent operating, tradeon, week
-
-
07/07/2021 at 3:43 PM #17330007/07/2021 at 5:19 PM #173308
DATE & TIME data typee are not supported, so MATH (eXcel-like) functions are not available.
There’s a workaround… just wait for the desired month and start counting weeks. The one that contains day 1 is the first week if that day is on Thursday or earlier (4+ out of 7 days must belong to the new month), otherwise it’s the last week of the prior month despite having day 1.
You start enabling trading and will disable it when the required weeks show.
This is an indicator you can add to your chart to tell week number for October:12345678910111213141516171819202122232425262728ONCE Wcount = 0// only check OctoberIF OpenMonth = 10 THEN// check if it's the first weekIF Wcount = 0 THEN// check if it's the first trading day of OctoberIF OpenMonth <> OpenMonth[1] THEN// it's the first week of October of the firtst day is Thursday or earlierIF OpenDayOfWeek <= 4 THENWcount = 1ENDIFELSE// if the first day was later than Thursday, then we have to wait for the next MondayIF (OpenDayOfWeek >= 1) AND (OpenDayOfWeek <> OpenDayOfWeek[1]) AND ((OpenDayOfWeek < OpenDayOfWeek[1]) OR (OpenDayOfWeek[1] = 0)) THENWcount = 1ENDIFENDIFELSE// or any other day in October (if it's Monday or it's the first day of the week, then it's a new week)IF (OpenDayOfWeek >= 1) AND (OpenDayOfWeek <> OpenDayOfWeek[1]) AND ((OpenDayOfWeek < OpenDayOfWeek[1]) OR (OpenDayOfWeek[1] = 0)) THENWcount = Wcount + 1ENDIFENDIF// not OctoberELSEWcount = 0ENDIFRETURN Wcount AS "Week"and this is the strategy:
1234567891011121314151617181920212223242526272829303132333435363738DEFPARAM CumulateOrders = falseONCE Wcount = 0TradeON = 1// only check OctoberIF OpenMonth = 10 THEN// check if it's the first weekIF Wcount = 0 THEN// check if it's the first trading day of OctoberIF OpenMonth <> OpenMonth[1] THEN// it's the first week of October of the firtst day is Thursday or earlierIF OpenDayOfWeek <= 4 THENWcount = 1ENDIFELSE// if the first day was later than Thursday, then we have to wait for the next MondayIF (OpenDayOfWeek >= 1) AND (OpenDayOfWeek <> OpenDayOfWeek[1]) AND ((OpenDayOfWeek < OpenDayOfWeek[1]) OR (OpenDayOfWeek[1] = 0)) THENWcount = 1ENDIFENDIFELSE// or any other day in October (if it's Monday or it's the first day of the week, then it's a new week)IF (OpenDayOfWeek >= 1) AND (OpenDayOfWeek <> OpenDayOfWeek[1]) AND ((OpenDayOfWeek < OpenDayOfWeek[1]) OR (OpenDayOfWeek[1] = 0)) THENWcount = Wcount + 1ENDIFENDIF// not OctoberELSEWcount = 0ENDIF// disable trading in weeks 1 and 3 of OctoberIF Wcount = 1 OR Wcount = 3 THENTradeON = 0ENDIFIF close CROSSES OVER average[20,0](close) AND Not LongOnMarket AND TradeON THENBUY 1 CONTRACT AT MARKETELSIF close CROSSES UNDER average[20,0](close) AND Not ShortOnMarket AND TradeON THENSELLSHORT 1 CONTRACT AT MARKETENDIF2 users thanked author for this post.
07/07/2021 at 5:58 PM #17331207/07/2021 at 6:13 PM #17331507/08/2021 at 1:07 PM #173335I modified it so that you can either:
- choose any month (and any week in it)
- choose any week of the year based solely on its year week ID
- choose any whole month
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869DEFPARAM CumulateOrders = false////////////////////////////////////////////////////////////////////////////////// Week Count////returned data://// - Wcount Week num of the month// - LastMM Month to which the week belongs (can be different from that on chart)// - Wyear Week num of the year//ONCE Wcount = 0ONCE Wyear = 0ONCE LastMM = 06mm = OpenMonthwd = OpenDayOfWeekyy = OpenYeardd = OpenDayDayMax = 31 //each month has 31 days by default// (below, exceptions will be dealt with)// check for any month with less than 31 daysIF mm = 4 OR mm = 6 OR mm = 9 OR mm = 11 THEN //Apr, Jun, Sep and Nov have 30 daysDayMax = 30ELSIF mm = 2 THEN //Feb has 28 days (29 on Leap Years, which occur on almost all 4-year boundaries)// check whether it's a Leap Year for FebruaryDayMax = 28 //let's default to 28IF yy MOD 4 = 0 THENIF yy MOD 100 = 0 THEN //NOT a Leap if it, as it can be divided by 100, but not by 400IF yy MOD 400 = 0 THENDayMax = 29 //it's a Leap Year, since it can be divded by both 100 and 400ENDIFELSEDayMax = 29 //can be divided by 4 and is not a century start, so it's a Leap YearENDIFENDIFENDIF// check & count every Monday (or later, if Monday is not a trading day)IF (wd >= 1) AND (wd <> wd[1]) AND ((wd < wd[1]) OR (wd[1] = 0)) THENWyear = Wyear + 1Diff = (DayMax - dd) + 1LastMM = mmIF LastMM <> LastMM[1] THENWcount = 1 //restart from 1 each new month when Monday os the 1st dayELSEIF Diff >= 4 THEN //if not a full week, then it belongs to the prior month if at least 4Wcount = Wcount + 1 // days belong to the prior monthELSEWcount = 1 // otherwise it's the 1st week of the new monthLastMM = LastMM + 1IF LastMM > 12 THENLastMM = LastMM - 12 //when computing the new month, make sure it's not greater than 12, ifENDIF // it is, then it's JanuaryENDIFENDIFENDIF// restart year count on Jan. 1stIF (LastMM = 1) AND (LastMM <> LastMM[1]) THENWyear = 1ENDIF////////////////////////////////////////////////////////////////////////////////TradeON = 1// disable trading in weeks 1 and 3 of OctoberIF (LastMM = 10) AND (Wcount = 1 OR Wcount = 3) THENTradeON = 0ENDIFIF close CROSSES OVER average[20,0](close) AND Not LongOnMarket AND TradeON THENBUY 1 CONTRACT AT MARKETELSIF close CROSSES UNDER average[20,0](close) AND Not ShortOnMarket AND TradeON THENSELLSHORT 1 CONTRACT AT MARKETENDIFyou change line 62 to use more months:
123IF ((LastMM = 10) AND (Wcount = 1 OR Wcount = 3)) OR (LastMM = 1 AND Wcount < 3) THENTradeON = 0ENDIFor use it for yearly week ID (1 to max 53):
123IF Wyear < 3 OR Wyear > 50 THENTradeON = 0ENDIFor use any other combination of the three values:
123IF (LastMM = 10 AND Wcount = 1) OR (Wyear > 51) OR (LastMM = 8) THENTradeON = 0ENDIF07/08/2021 at 2:09 PM #173340 -
AuthorPosts
Find exclusive trading pro-tools on