Identifying intraday trading setups

Some of the best setups during the day happen after a period of consolidation over a longer period of time. We are going to look at how to divide the trading day up into 4 hour segments. We will then dive down into those segments to identify patterns that we can use for trading setups. We will discuss how to setup an indicator in to highlight the 4 hour periods on the price chart as this will help us easily visualize the price action we are interested in.

Writing the indicator

For this indicator we are going to be using the TradingView platform. The indicator will be scripted using the Pinescript language. For further reference on Pinescript you can visit for excellent documentation.

The futures markets trade 24 hours a day so there are six 4 hour periods in a single day. We can define those periods as variables in our script;

segment1 = "0200-0600" // 2am to 6am
segment2 = "0600-1000" // 6am to 10am
segment3 = "1000-1400" // 10am to 2pm
segment4 = "1400-1800" // 2pm to 6pm
segment5 = "1800-2200" // 6pm to 10pm
segment6 = "2200-0200" // 10pm to 2am

Now that we have our time periods setup we need to determine if a price bar is inside a given time period. This will allow us to color the background of the price chart to easily identify the 4 hour periods. To do this we will define the following function;

barInSegment(segment) => na(time(period, segment)) == false

This line returns true if a price bar is inside a 4 hour time period segment. We then use this function to alter the background color of each price bar. For example we can set the background color to blue if a price bar is within our first segment with a call like this;

// Color the background for a price bar in the first segment
bgcolor(color=BarInSegment(segment1)[1] ? #0000FF10 : na )

The value #0000FF10 defines the color we will use. The value is in a format called RGBA (red, green, blue, alpha) In this case we are setting the blue value to FF which is the maximum value for the blue component and the alpha component is set to 10 which will make the blue transparent. We can define a couple of variables for a couple of shades of blue to make it easier to read;

blue1 = #0000FF10
blue2 = #0000FF08

To highlight all of the segments in the 24 hour period we repeat the same idea for the six time segments. We alternate the color to a different shade of blue for every different segment to make them easily identifiable;

bgcolor(color=BarInSegment(segment1)[1] ? blue1 : na )
bgcolor(color=BarInSegment(segment2)[1] ? blue2 : na )
bgcolor(color=BarInSegment(segment3)[1] ? blue1 : na )
bgcolor(color=BarInSegment(segment4)[1] ? blue2 : na )
bgcolor(color=BarInSegment(segment5)[1] ? blue1 : na )
bgcolor(color=BarInSegment(segment6)[1] ? blue2 : na )

Once the indicator is applied to the chart we see the 4 hour segmets highlighted. This chart shows the indicator on a 15 minute chart of WTI crude oil

Crude oil futures chart

Finding patterns within segments

Now if we dive into each segment from left to right we can extract the patterns that setup within each segment. We are planning our next trades based on the previous segment.

Crude oil futures chart

Now that we have the price action broken down into segments let’s break it down. In the first segment (1) we see a triangle pattern. When price contracts like this we usually get a break out which happens in this case at (2). Those events both happened in the first segment. Now we watch to see what happens in the next segment. Often after a upwards thrust we will see consolidation or sideways movement and this is exactly what happens at (3). A rectangle is formed with a well defined range . A trader seeing such a range occur will be looking for a breakout of that range which happens in the next segment at (4) and ends in a flag pattern. For the next segment we will be looking to see if price breaks out higher above the flag pattern high or breaks down. In this case price moves lower at (5). Within this segment we have a break down from a flag pattern, a down thrust move and another consolidation pattern all within that segment. At (6) the break out above the previous segments range is bought. The strong upwards thrust move (7) again ends in a sideways consolidation pattern. In the next segment at (8) price runs into some resistance and forms a nice topping pattern (8) & (9). We can easily see the ascending triangle pattern and this time it breaks down.

As you can see just from this short period of time there are many trade setups available to the trained eye. Breaking up the trading session into these 4 hour segments helps give structure to the price action.

The complete script for highlighting the 4 hour segments is available for download at our GitHub site;

If you would like to be notified of new articles from ScalpTrader please subscribe to our mailing list or follow us on Twitter