Indicator not plotting within it's own TimeFrame
Indicator not plotting within it's own TimeFrame
26 Mar 2019, 11:45
This indicator calculates only the timeframes of the higher series instead of the current Timeserie. What am I missing here?
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Scalp : Indicator { [Output("Ema", LineColor = "white", Thickness =5)] public IndicatorDataSeries Ema { get; set; } private ExponentialMovingAverage _ema; TimeFrame _biggerTimeFrame; MarketSeries _biggerSeries; protected override void Initialize() { _biggerSeries = MarketData.GetSeries(TimeFrame.Minute15); _ema = Indicators.ExponentialMovingAverage(_biggerSeries.Close, 15); } public override void Calculate(int index) { int Bigindex = GetIndexByDate(_biggerSeries, MarketSeries.OpenTime[index]); if (Bigindex != -1) { Ema[index] = _ema.Result[Bigindex]; Print(MarketSeries.TimeFrame, " ", MarketSeries.OpenTime[index], " ", _biggerSeries.TimeFrame, " ", _biggerSeries.OpenTime[Bigindex], " ", index, " ", Bigindex, " ", _ema.Result[Bigindex]); } } private int GetIndexByDate(MarketSeries series, DateTime time) { for (int i = series.Close.Count - 1; i > 0; i--) { if (time == series.OpenTime[i]) return i; } return -1; } } }
Gives:
and the log is:
26/03/2019 09:36:24.580 | Minute 3/26/2019 9:30:00 AM Minute15 3/26/2019 9:30:00 AM 2753 8585 145.310173787739
26/03/2019 09:36:24.580 | Minute 3/26/2019 9:15:00 AM Minute15 3/26/2019 9:15:00 AM 2738 8584 145.317484328844
26/03/2019 09:36:24.580 | Minute 3/26/2019 9:00:00 AM Minute15 3/26/2019 9:00:00 AM 2723 8583 145.298410661536
26/03/2019 09:36:24.580 | Minute 3/26/2019 8:45:00 AM Minute15 3/26/2019 8:45:00 AM 2708 8582 145.302612184613
Replies
TonNcie
26 Mar 2019, 16:20
( Updated at: 21 Dec 2023, 09:21 )
RE:
Hi Panagiotis
26/03/2019 09:36:24.580 | Minute 3/26/2019 9:30:00 AM Minute15 3/26/2019 9:30:00 AM 2753 8585 145.310173787739
26/03/2019 09:36:24.580 | Minute 3/26/2019 9:15:00 AM Minute15 3/26/2019 9:15:00 AM 2738 8584 145.317484328844
26/03/2019 09:36:24.580 | Minute 3/26/2019 9:00:00 AM Minute15 3/26/2019 9:00:00 AM 2723 8583 145.298410661536
26/03/2019 09:36:24.580 | Minute 3/26/2019 8:45:00 AM Minute15 3/26/2019 8:45:00 AM 2708 8582 145.302612184613
The index parameter is taken from the 15m timeframe (see print log. minute & minute 15 both have the same opentime.)
The problem is that
public override void Calculate(int index)
is not firing on the minute timeframe as the printout and the chart show. it only fires in the m15 frame
Best Regards,
@TonNcie
PanagiotisCharalampous
26 Mar 2019, 17:30
Hi El Antonio,
I am not sure how you came to this conclusion
"is not firing on the minute timeframe as the printout and the chart show. itonly fires in the m15 frame"
If you are referring to the log print outs, this happens becaise you have programmed it to do so. You only print whenever the m15 adds a new bar. See below
int Bigindex = GetIndexByDate(_biggerSeries, MarketSeries.OpenTime[index]); if (Bigindex != -1) {
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
26 Mar 2019, 12:15
Hi El Antonio,
I tried both higher and lower timeframes but I do not understand what is the problem. The white line draws on all of them.
Best Regards,
Panagiotis
@PanagiotisCharalampous