Custom Timeframe index in indicator (Multi timeframe indicators)

Created at 29 Aug 2020, 17:21
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
VO

voldemort

Joined 10.07.2020

Custom Timeframe index in indicator (Multi timeframe indicators)
29 Aug 2020, 17:21


Is there any foolproof way of calculating index of custom time frame?

I tried below code:

int customIndex = CustomBar.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index]);

I also tried GetIndexByTime - which also does not work.

Any quick tips on this?


@voldemort
Replies

firemyst
30 Aug 2020, 12:43

Example code for quick tip:

 public override void Calculate(int index)
        {
            int altIndex = index;

            altIndex = Bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            //Reference any values from a different timeframe with the altIndex
            double median = (Bars.HighPrices[altIndex] + Bars.LowPrices[altIndex]) / 2;

	   Result[index] = median;
	}

 

Hope this helps :-)

 

 


@firemyst

voldemort
30 Aug 2020, 14:36

RE: Example code for quick tip:

firemyst said:

Example code for quick tip:

 public override void Calculate(int index)
        {
            int altIndex = index;

            altIndex = _marketSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            //Reference any values from a different timeframe with the altIndex
            double median = (Bars.HighPrices[altIndex] + Bars.LowPrices[altIndex]) / 2;

	   Result[index] = median;
	}

 

Hope this helps :-)

 

 

Only difference is I used Bars instead of MarketSeries. Will give this a go. Thanks :)


@voldemort

firemyst
30 Aug 2020, 14:55

RE: RE: Example code for quick tip:

voldemort said:

Only difference is I used Bars instead of MarketSeries. Will give this a go. Thanks :)

that should have been "Bars" and not MarketSeries.

I've updated the code in the example.

If it's still not working, it's something else with your code or what you're doing, so you'll need to post some sample code.


@firemyst

voldemort
30 Aug 2020, 15:23

RE: RE: RE: Example code for quick tip:

firemyst said:

voldemort said:

Only difference is I used Bars instead of MarketSeries. Will give this a go. Thanks :)

that should have been "Bars" and not MarketSeries.

I've updated the code in the example.

If it's still not working, it's something else with your code or what you're doing, so you'll need to post some sample code.

Hey, Thanks very much. I had used index instead of customindex at some locations which was the issue I believe. That solved problem for recent data. But, still it does not match completely. I have uploaded indicator in the scripts:

Btw, are you the same fireMyst from whirlpool?

 


@voldemort

firemyst
30 Aug 2020, 16:06

RE: RE: RE: RE: Example code for quick tip:

.

 


@firemyst

ctid482544
01 May 2023, 13:58

Custom timeframe in window/not only indicator

Hi,

years ago I put something about custom timeframe. My post has been deleted by moderator - very bad bad habit. Let me repeat: there are several timeframes critically necessary. I cannot imagine - why this is a problem to add custom option i.e. 11 minutes 17 minutes or 27 minutes ? I desperately need an 18 minutes, 27 minutes.


@ctid482544