The end-of-month effect

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #239276 quote
    dubbzie
    Participant
    New

    Hi all,

    I want to  go long at the close on the fifth last trading day of the month, and exit at the close of the third trading day of the next month. Anyone able to make script for this strategy?

    justisan thanked this post
    #239296 quote
    Iván González
    Moderator
    Master

    Hi! here you have a code. It must be backtested in daily timeframe.

    myday=openday
    myDayOfWeek = opendayofweek
    MyMonth=openmonth
    MyYear=openyear
    businessdaysleft = 0
    //------------------------------------------//
    //-----Check leap year----------------------//
    //------------------------------------------//
    //input:YEAR
    LeapYear = 0
    If MyYear mod 4 = 0 then
    If MyYear mod 100 = 0 then
    If MyYear mod 400 = 0 then
    LeapYear = 1
    Endif
    Else
    LeapYear = 1
    Endif
    Endif
    //------------------------------------------//
    //-----Calculate max days in month----------//
    //------------------------------------------//
    MaxDay = 31
    If MyMonth = 4 or MyMonth = 6 or MyMonth = 9 or MyMonth = 11 Then
    MaxDay = 30
    Endif
    If MyMonth = 2 then
    x = LeapYear
    MaxDay = 28 + x
    Endif
    myDayMax=MaxDay
     
    FOR count = myday to myDayMax DO
    IF myDayOfWeek >= 1 and myDayOfWeek <= 5 THEN
    businessdaysleft = businessdaysleft + 1
    ENDIF
    myDayOfWeek = (myDayOfWeek + 1) MOD 7
    NEXT
    //------------------------------------------//
    //-----Open long position-------------------//
    //------------------------------------------//
    dayscheck=5
    if not longonmarket and businessdaysleft=(dayscheck+1) then
    buy 1 contract at market
    endif
    //------------------------------------------//
    //-----Close long position------------------//
    //------------------------------------------//
    newmonth=openmonth<>openmonth[1]
    if onmarket then
    n=n+1
    if n>=3+dayscheck then
    sell at market
    endif
    else
    n=0
    endif
    druby, robertogozzi, dubbzie and justisan thanked this post
    #239307 quote
    dubbzie
    Participant
    New

    Thanks, Ivan!😃

    #247562 quote
    justisan
    Participant
    Junior

    Hi,

    finally I came to test this day counting algo, and realized that it works perfectly for months which do not contain any exchange holidays, and so it does not count correctly for the months with exchange holidays. for this moment I assume there is no real posibility to consider in the algo correctly those months with exchange holidays: for that we would need to have “in the background” all exchange holidays of the past (for the backtesting)  and for the future (for live implementation), for specific exchange, right? I assume still one could do it manually: collect past exchange holidays manually (or let collect them by AI if one trusts AI :-D) and put them in the code…

    so I will probably collect exchange holidays for my exchange of interest, but anyway – I still don’t have an idea, how to consider them in the code, so counting runs correctly. do you have and idea, Ivan? or anybody else? I mean, if let’s say 1st of May is exchange holiday and this day in the year xyzw is not on weekend, how could I possibly tell it in the code, so counting is adjusted?

    thanks,

    justisan

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

The end-of-month effect


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
dubbzie @dubbzie Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by justisan
8 months, 3 weeks ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 10/20/2024
Status: Active
Attachments: No files
Logo Logo
Loading...