Description
Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them.
This indicator colors the area between the selected hourspan.
Useful for scalpers and to highlight trading sessions or other parts of the day.
Comment and share your toughts about this algo, it would be much appreciated.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.CentralEuropeStandardTime, AccessRights = AccessRights.None)]
public class HourArea : Indicator
{
[Parameter("Start Hour", DefaultValue = 9)]
public int hour1 { get; set; }
[Parameter("Start Minute", DefaultValue = 0)]
public int min1 { get; set; }
[Parameter("End Hour", DefaultValue = 18)]
public int hour2 { get; set; }
[Parameter("End Minute", DefaultValue = 0)]
public int min2 { get; set; }
[Parameter("Color", DefaultValue = "Gray")]
public string col { get; set; }
[Parameter("Transparency %", DefaultValue = 25)]
public int trsp { get; set; }
private bool draw = false;
private int thc;
protected override void Initialize()
{
trsp = trsp > 100 ? 100 : trsp < 0 ? 0 : trsp;
hour1 = hour1 > 23 ? 23 : hour1 < 0 ? 0 : hour1;
hour2 = hour2 > 23 ? 23 : hour2 < 0 ? 0 : hour2;
min1 = min1 > 59 ? 59 : min1 < 0 ? 0 : min1;
min2 = min2 > 59 ? 59 : min2 < 0 ? 0 : min2;
Thickness();
Chart.ZoomChanged += OnChartZoomChanged;
}
void OnChartZoomChanged(ChartZoomEventArgs obj)
{
Thickness();
for (int i = 0; i < Chart.BarsTotal; i++)
{
Chart.RemoveObject("_hour" + i);
Calculate(i);
}
}
public override void Calculate(int index)
{
DateTime dt = MarketSeries.OpenTime[index];
if (dt.Hour == hour1 && dt.Minute == min1)
draw = true;
if (dt.Hour == hour2 && dt.Minute == min2)
draw = false;
Color color = Color.FromName(col);
Color alphaColor = Color.FromArgb((int)(trsp * 2.55), color.R, color.G, color.B);
if (draw)
Chart.DrawVerticalLine("_hour" + index, index, alphaColor, thc);
}
private void Thickness()
{
if (Chart.Zoom == 0)
{
thc = 1;
}
if (Chart.Zoom == 1)
{
thc = 2;
}
if (Chart.Zoom == 2)
{
thc = 4;
}
if (Chart.Zoom == 3)
{
thc = 8;
}
if (Chart.Zoom == 4)
{
thc = 16;
}
if (Chart.Zoom == 5)
{
thc = 32;
}
return;
}
}
}
CY
cysecsbin.01
Joined on 10.11.2018 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: HourArea.algo
- Rating: 0
- Installs: 1864
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
Such a good game get free vbucks now try to play this game.