How to create trading session and support/resistance indicators
Initializing search
How to create trading session and support/resistance indicators¶
The cTrader Algo API provides the types required to create indicators that draw rectangles, lines, triangles, clouds and other objects on trading charts. Rectangles, in particular, are widely used to highlight important periods, consolidation zones and support/resistance levels.
In this article and the corresponding video, you will learn how to draw rectangles that represent trading sessions and support/resistance levels on a symbol chart.
There are four major trading sessions: Sydney, Tokyo, London and New York. Each session is unique in terms of volatility and activity levels. By monitoring the sessions and overlaps between them, traders know when specific assets are traded and can capitalise on opportunities.
In this example, we want to create an indicator that draws trading sessions on a chart.
In cTrader Algo, navigate to the Indicators tab and click the New button. Enter a name in the text field and then click Create.
Start modifying the indicator in the code editor. First, make it an overlay indicator.
Write the code to draw a rectangle that indicates the London session on a chart.
1234567
TimeSpanlondonOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;TimeSpanlondonClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;Chart.DrawRectangle("London Session ",Server.Time.Date.Add(londonOpen),Chart.TopY,Server.Time.Date.Add(londonClose),Chart.BottomY,Color.FromArgb(50,0,50,255)).IsFilled=true;
Press Ctrl+B or click Build, then add the indicator to a chart by clicking Add instance.
The London session rectangle can be seen on the chart.
Return to the code editor and add code for the remaining three trading sessions.
1 2 3 4 5 6 7 8 91011121314151617181920212223
TimeSpannyOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;TimeSpannyClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;Chart.DrawRectangle("NY Session ",Server.Time.Date.Add(nyOpen),Chart.TopY,Server.Time.Date.Add(nyClose),Chart.BottomY,Color.FromArgb(50,255,50,0)).IsFilled=true;TimeSpansydneyOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;TimeSpansydneyClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;Chart.DrawRectangle("Sydney Session ",Server.Time.Date.Add(sydneyOpen).AddDays(-1),Chart.TopY,Server.Time.Date.Add(sydneyClose),Chart.BottomY,Color.FromArgb(50,50,255,0)).IsFilled=true;TimeSpantokyoOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;TimeSpantokyoClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;Chart.DrawRectangle("Tokio Session ",Server.Time.Date.Add(tokyoOpen),Chart.TopY,Server.Time.Date.Add(tokyoClose),Chart.BottomY,Color.FromArgb(50,0,50,255)).IsFilled=true;
usingSystem;usingcAlgo.API;usingcAlgo.API.Collections;usingcAlgo.API.Indicators;usingcAlgo.API.Internals;namespacecAlgo{[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]publicclassTradingSessions:Indicator{protectedoverridevoidInitialize(){}publicoverridevoidCalculate(intindex){TimeSpanlondonOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;TimeSpanlondonClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time")).TimeOfDay;Chart.DrawRectangle("London Session ",Server.Time.Date.Add(londonOpen),Chart.TopY,Server.Time.Date.Add(londonClose),Chart.BottomY,Color.FromArgb(50,0,50,255)).IsFilled=true;TimeSpannyOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;TimeSpannyClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).TimeOfDay;Chart.DrawRectangle("NY Session ",Server.Time.Date.Add(nyOpen),Chart.TopY,Server.Time.Date.Add(nyClose),Chart.BottomY,Color.FromArgb(50,255,50,0)).IsFilled=true;TimeSpansydneyOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;TimeSpansydneyClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).TimeOfDay;Chart.DrawRectangle("Sydney Session ",Server.Time.Date.Add(sydneyOpen).AddDays(-1),Chart.TopY,Server.Time.Date.Add(sydneyClose),Chart.BottomY,Color.FromArgb(50,50,255,0)).IsFilled=true;TimeSpantokyoOpen=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,9,0,0),TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;TimeSpantokyoClose=TimeZoneInfo.ConvertTimeToUtc(newDateTime(Server.Time.Year,Server.Time.Month,Server.Time.Day,18,0,0),TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")).TimeOfDay;Chart.DrawRectangle("Tokyo Session ",Server.Time.Date.Add(tokyoOpen),Chart.TopY,Server.Time.Date.Add(tokyoClose),Chart.BottomY,Color.FromArgb(50,0,50,255)).IsFilled=true;}}}
Rebuild the indicator and then check the chart to see all the trading sessions represented there.
A fractal resistance zone is drawn where the high value is higher than the two adjacent bars on each side. The zone is the area between the high and close prices of a fractal candle. Resistance zones help to identify areas where a bullish trend might stop and reverse, which results in trading opportunities.
Build the indicator and add an instance to a chart. You should see the support and resistance zones on the chart.
This article has demonstrated how to create indicators with useful objects, such as rectangles, which can be used to represent trading sessions and support/resistance levels on charts.