TradingView
MA_PT
18 Jul 2021 pukul 18.56

DAYOFWEEK performance 

Invesco QQQ Trust, Series 1NASDAQ

Huraian

1 -Objective
"What is the ''best'' day to trade .. Monday, Tuesday...."
This script aims to determine if there are different results depending on the day of the week.
The way it works is by dividing data by day of the week (Monday, Tuesday, Wednesday ... ) and perform calculations for each day of the week.


1 - Objective
2 - Features
3 - How to use (Examples)
4 - Inputs
5 - Limitations
6 - Notes
7 - Final Tooughs

2 - Features

  • AVG OPEN-CLOSE

  • Calculate de Percentage change from day open to close

  • Green % (O-C)

  • Percentage of days green (open to close)

  • Average Change

  • Absolute day change (O-C)


  • AVG PrevD. Close-Close

  • Percentage change from the previous day close to the day of the week close
    (Example: Monday (C-C) = Friday Close to Monday close
    Tuesday (C-C) = Monday C. to Tuesday C.

  • Green % (C1-C)

  • Percentage of days green (open to close)


  • AVG Volume

  • Day of the week Average Volume


Notes:
*Mon(Nº) - Nº = Number days is currently calculated
Example: Monday (12) calculation based on the last 12 Mondays. Note: Discrepancies in numbers example Monday (12) - Friday (11) depend on the initial/end date or the market was closed (Holidays).


3 - How to use (Examples)

For the following example, NASDAQ:AAPL from 1 Jan 21 to 1 Jul 21 the results are following.
The highest probability of a Close being higher than the Open is Monday with 52.17 % and the Lowest Tuesday with 38.46 %. Meaning that there's a higher chance (for NASDAQ:AAPL ) of closing at a higher value on Monday while the highest chance of closing is lower is Tuesday. With an average gain on Tuesday of 0.21%
  • Long - The best day to buy (long) at open (on average) is Monday with a 52.2% probability of closing higher

  • Short- The best day to sell (short) at open (on average) is Tuesday with a 38.5% probability of closing higher (better chance of closing lower)



Since the values change from ticker to ticker, there is a substantial change in the percentages and days of the week. For example let's compare the previous example ( NASDAQ:AAPL ) to NYSE:GM (same settings)
For the same period, there is a substantial difference where there is a 62.5% probability Friday to close higher than the open, while Tuesday there is only a 28% probability.
With an average gain of 0.59% on Friday and an average loss of -0.34%


Also, the size of the table (number of days ) depends if the ticker is traded or not on that day as an example COINBASE:BTCUSD



4 - Inputs
  • DATE RANGE
    Initial Date - Date from which the script will start the calculation.
    End Date - Date to which the script will calculate.


  • TABLE SETTINGS
    Text Color - Color of the displayed text
    Cell Color - Background color of table cells
    Header Color - Color of the column and row names
    Table Location - Change the position where the table is located.
    Table Size - Changes text size and by consequence the size of the table



5 - LIMITATIONS
The code determines average values based on the stored data, therefore, the range (Initial data) is limited to the first bar time.
As a consequence the lower the timeframe the shorter the initial date can be and fewer weeks can be calculated. To warn about this limitation there's a warning text that appears in case the initial date exceeds the bar limit.

Example with initial date 1 Jan 2021 and end date 18 Jul 2021 in 5m and 10 m timeframe:



6 - Notes and Disclosers
The script can be moved around to a new pane if need. -> Object Tree > Right Click Script > Move To > New pane

The code has not been tested in higher subscriptions tiers that allow for more bars and as a consequence more data, but as far I can tell, it should work without problems and should be in fact better at lower timeframes since it allows more weeks.

The values displayed represent previous data and at no point is guaranteed future values


7 - Final Tooughs
This script was quite fun to work on since it analysis behavioral patterns (since from an abstract point a Tuesday is no different than a Thursday), but after analyzing multiple tickers there are some days that tend to close higher than the open.

PS: If you find any mistake ex: code/misspelling please comment.

Nota Keluaran

█ Update script to the new pine script version 5
  • (New Features) - Now allows selecting times directly on the chart
  • (New Feature) - Warn users of valid setting instead of crashing
  • (Fix/Improvements) - Improved performance, removed unnecessary code
Komen
Shannon508
I love this indicator so much!! I am using it on so many charts and the results are very striking. Thank you so much for your creation. Table disappears if end date is before 31/1/22. Any ideas to get it working?
MA_PT
@Shannon508, Thanks for the love and support, I have tried and can't seem to replicate the problem can you send me a screenshot of where this problem happens.

Here's my result:
Shannon508
@MA_PT, Hi thanks for your response, I have started exporting data to spreadsheet to continue my quest to learn about days of the week patterns. But FYI it is still happening with the indicator. If I have the end date on 31st Jan 2022, the table is there, and then, even while the settings window is still up, when I change the date back one day to 30th Jan 2022, the table disappears. I don't know how to insert the screen shots I took.
MA_PT
@Shannon508, Hi to insert a screen shoot just go to your chart, click on the camera symbol (take screenshot), click on “copy link to the chart image”, then paste the link directly to the comment. Then when you post the comment it should show the image.
PS: By the way, did you change the “End date” parameter because the initial date needs to be before end date.
Orph5781
Wonderful! Could it be possible to enhance the script so for example see within each day (for example to split the trading day into 4 blocks of the correspondent length )
Roul_Charts
Great Indicator.

Just had this idea to see which day is often green (like mondays) and found your one. Better then coding a new one ;-)

Thanks!
maxncf
Hi MA_PT great job!
I found just a small problem with ES1 symbol: I got Sunday as last column instead of Friday...



I plotted the dayofweek and _f_Correct_day(dayofweek) values and there is a difference of 1 between them.
So I tried to remove the _f_Correct_day function and the table now look right:



I didn't understand what the real goal of that function would be :-(

In case someone is interested this is my code:

// plot the difference
plot(_D_dayweek, "DoW", color.blue)
plot(_f_Correct_day(_D_dayweek), "DoW Correct", color.red)

if barstate.islastconfirmedhistory // Note: Removing this may execced 200 ms limit
for i = 0 to COL_SIZE - 1 by 1

// substitute original dayoftheweek value
//day = _f_Correct_day(i) // Get dayoftheweek corrected
day = i
apmbh8
@maxncf, I have the same issue with ES1. Can you please post the updated script with your changes ? Thanks
maxncf
@apmbh8, I tried to post the whole script but don't know why I got this error:
"Invalid date"
Is there some other way to show you the script?
apmbh8
@maxncf, I sent you a DM.
Lebih