Do once a day in specific time
Do once a day in specific time
19 Jan 2019, 03:25
Hi, I need to draw a rectangle each day at 7 am (London Time) that its width is 1 hour and its width is high and low on that 1 hour. But firstly it doesn't repeat every day and secondly I have no idea how can draw a rectangle with 1hour width
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewIndicator : Indicator
{
[Parameter("ATR Period", DefaultValue = 7)]
public int ATRPeriod { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
private AverageTrueRange _ATR;
private MarketSeries seriesHour;
private MarketSeries seriesCurrent;
private AverageTrueRange _ATRHour;
private AverageTrueRange _ATRCurrent;
protected override void Initialize()
{
// Initialize and create nested indicators
_ATR = Indicators.AverageTrueRange(ATRPeriod, MovingAverageType.Exponential);
seriesHour = MarketData.GetSeries(TimeFrame.Hour);
seriesCurrent = MarketData.GetSeries(MarketSeries.TimeFrame);
}
public override void Calculate(int index)
{
if (MarketSeries.TimeFrame <= TimeFrame.Hour)
{
var currentHour = int.Parse(Server.Time.ToString("%H"));
if (currentHour == 7)
{
DrawRectangle(index);
}
}
}
public void DrawRectangle(int index)
{
Chart.DrawRectangle("Rectangel" + index, ???);
}
}
}
pozhy
19 Jan 2019, 06:40
I have done it but it is weird
if (MarketSeries.OpenTime[index].Hour == StartHour)
{
DrawRectangle(index);
}
-------------------------------------
public void DrawRectangle(int index)
{
int idx1 = tf.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
int idx2 = MarketSeries.OpenTime.GetIndexByTime(tf.OpenTime[idx1]);
double open = tf.Open[idx1];
high = tf.High[idx1];
low = tf.Low[idx1];
double close = tf.Close[idx1];
Chart.DrawRectangle("Rectangel" + index, index, high, idx2, low, open < close ? Color.Yellow : Color.Pink);
}
@pozhy