Each market`s day session can be divided into a pre market, opening or the closing session and so on. It can be also broken down into single hours which enables us to find out about the intraday seasonality of a market. In other words: Does the market show a bullish or bearish pattern during specific hours? This post will show you how to code a simple dummy strategy which allows you to measure the performance of every single hour. At the same time it is a good example for how to use functions in Equilla.
The Advantage of Using Functions
But what is a function? It is a defined set of instructions that can be referenced by its name in indicators or strategies to return a value. This way you can save a lot of time and use the function instead of writing out the whole code again and again. Here is the code for the function we will need later. Als you can see, each if.. then.. statement stands for one of 24 hours and sets the variable “AllowTrading” to true or false. It serves as a flag which will be needed to control the hours in the strategy back-test later on.
I have shortened the screenshot, because the structure is the same for all remaining hours. One important point is: You have to define a name for this function at the end of the code. As you can see in line 82, I called this function “SessionTest24”. It contains the value for the variable “allowTrading”, true or false.
Dummy “Strategy” can detect Intraday Seasonality Patterns
Having finished the function, now we can write a short dummy strategy which only has one single task: It buys a position at the start of the chosen hour and closes it at the end of the hour.
- In line 2 I created an input called “SessionToTest” – this allows to select which hour should be back-tested
- In line 5, the variable “TradingAllowed” refers to the function “SessionTest24” which we created before
- The if.. then.. statement in line 9-10 controls the buy and sell orders
Practical Example: Which hours are bullish for Bitcoin, which are bearish?
To give you a practical example, I did an optimization which shows the results of each hour in a nice histogram.
Below you can see the performance of BTC/USD for every single hour since start of the year. Although there is a brutal bear market, hours 13 and 14 (GMT+1) brought gains of around 0,1% on average. Not enough to be traded, of course. But a good example which information you can derive from a back-test.
Tradesignal® is a registered trademark of Tradesignal GmbH. Unauthorized use or misuse is strictly prohibited. Data by Thomson Reuters Eikon.