Historic value of indicator (not at the close of the Bar).

Created at 24 Jan 2019, 18: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!
KO

kontodospamu5

Joined 13.03.2017

Historic value of indicator (not at the close of the Bar).
24 Jan 2019, 18:21


Hello,

I know how to calculate RSI indicator in cBot.

I use the following code to achieve rsi:

Symbol symbol = MarketData.GetSymbol(“EURUSD”);
TimeFrame TF = TimeFrame.Hour;
MarketSeries ts = MarketData.GetSeries(symbol, TF);
RelativeStrengthIndex rsi = Indicators.RelativeStrengthIndex(ts.Close, 14);

 

I opened a trade at say t=09:16:00. The trigger for opening the trade was value of rsi calculated on HOURly MarketSeries at “t”.

Now the problem I face is: suppose that now ie several hours later (say: 15:35:00) my aim is to find out what was the value of rsi when I entered the trade at “t”.

Is I possible to calculate it?

Best Regards,

Piotr


@kontodospamu5
Replies

PanagiotisCharalampous
25 Jan 2019, 09:56

Hi Piotr,

You can use GetIndexByTime to find values of the indicator for specific time. See below an example for getting the RSI value for 5 hours before

rsi.Result[ts.OpenTime.GetIndexByTime(Server.Time.AddHours(-5))

Best Regards,

Panagiotis


@PanagiotisCharalampous

kontodospamu5
25 Jan 2019, 17:04

Hello Panagiotis,
Thank you for a quick response, I appresiate that.

 

rsi.Result[ts.OpenTime.GetIndexByTime(Server.Time.AddHours(-5))

is able to take us 5 hours back on already calculated rsi time series.

 

Therefore all three aa0, aa1, aa2 are equal

double aa0 = rsi.Result.LastValue;
double aa1 = rsi.Result[ts.OpenTime.GetIndexByTime(Server.Time.AddMinutes(-1))];
double aa2 = rsi.Result[ts.OpenTime.GetIndexByTime(Server.Time.AddMinutes(-5))];

 

I am afraid that to achieve my goal we would need to recalculate rsi because some modifications to time series “ts.Close” are required.
Why modifications are required? Because assuming that now is 15:35 (so we are in the middle of Hour Bar), we have to move back to 9:16 in the morning (another “broken” bar 16 minutes after opening of Hour bar).


I suppose that such modifications would be of the form of combining Hour and Minute MarketData.GetSeries().
I mean: let us take Hour till 9:00 and append to it a one bar constructed from 16 bars of Minute MarketData.GetSeries(). As a result we would have now 15:35 the Hour time series as it was at 9:16 that morning.

Do you think it is possible?

Best regards,
Piotr


@kontodospamu5

PanagiotisCharalampous
25 Jan 2019, 17:18

Hi Piotr,

It is not impossible but there is no easy way to do it using the API. The API will return you the final RSI value calculated for that bar at the end of the bar. Intermediary values are not available. Therefore you will need to manually calculate the RSI by getting estimated bid and ask prices from the minutes timeframe.

Best Regards,

Panagiotis


@PanagiotisCharalampous