RSI Last method, what's the value exactly mean?

Created at 30 Jun 2020, 23:24
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!
Capt.Z-Partner's avatar

Capt.Z-Partner

Joined 09.05.2020

RSI Last method, what's the value exactly mean?
30 Jun 2020, 23:24


Hello,

I have the code below, which intent to get RSI value based on the previous bar's close price, or past 2nd's 3rd's etc.. I understand rsi.Result.LastValue return the current moment RSI value in the bar. So, I can set a double RsiPreviousBarOpen to record it each time when a new bar start.

But I want to test Last method, like rsi.Result.Last(1) or rsi.Result.Last(3)... to get all data I need in the first run of OnBar(). Amazingly, the rsi.Result.Last(1) didn't get the same value as RsiPreviousBarOpen recorded. 

My question is based on the close price of the last bar how can I get RSI value via Last method, if it is possible? And what exactly rsi.Result.Last(1) return means?

Thanks,

Lei

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestingRSI : Robot
    {
        [Parameter("Source", Group = "RSI")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", Group = "RSI", DefaultValue = 10)]
        public int Periods { get; set; }

        public double RsiPreviousBarOpen;

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            
            Print("rsi.Result.Last(0)    : {0}", rsi.Result.Last(0));
            Print("rsi.Result.LastValue: {0}", rsi.Result.LastValue);
            
            RsiPreviousBarOpen = rsi.Result.LastValue;
        }

        protected override void OnBar()
        {   
            Print("rsi.Result.Last(0)    : {0}", rsi.Result.Last(0));
            Print("rsi.Result.LastValue: {0}", rsi.Result.LastValue);

            Print("rsi.Result.Last(1)  : {0}", rsi.Result.Last(1));
            Print("RsiPreviousBarOpen  : {0}", RsiPreviousBarOpen);
            
            RsiPreviousBarOpen = rsi.Result.LastValue;
       }

    }
}


@Capt.Z-Partner
Replies

PanagiotisCharalampous
01 Jul 2020, 08:31

Hi Delphima,

Last(x) uses x as a backwards index counter.  Last(1) will return the value for the previous bar, Last(2) for two bars before etc.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

Capt.Z-Partner
01 Jul 2020, 14:29

RE:

PanagiotisCharalampous said:

Hi Delphima,

Last(x) uses x as a backwards index counter.  Last(1) will return the value for the previous bar, Last(2) for two bars before etc.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,

Thanks for replying. 

Yes, I know Last(x) method could be used to get bars' high/low/open/close value. I wonder if it can also be used to get indicator's history value, in my example to get RSI's history value?

And, I tested with above code, it can return some value, but it's not what I expected. Can you have a look again?

Thanks,

Lei


@Capt.Z-Partner

PanagiotisCharalampous
01 Jul 2020, 14:34

Hi Delphima,

The method has the same function for indicator data series as well. You code has a logical mistake though. It prints the last value when a bar is created but then compares this value with the value the indicator when the bar closed. The value of the indicator can change in the meanwhile.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Capt.Z-Partner
01 Jul 2020, 15:08

RE:

PanagiotisCharalampous said:

Hi Delphima,

The method has the same function for indicator data series as well. You code has a logical mistake though. It prints the last value when a bar is created but then compares this value with the value the indicator when the bar closed. The value of the indicator can change in the meanwhile.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

Yes, we are quite close to the focus of my concern.

As you said, below code 'It prints the last value when a bar is created' and 'The value of the indicator can change'. I want to know the code below return RSI value based on last bar, but depend on which moment in the bar. Is it open price or high/close/low? I didn't figure it out in the comparison. Please give more information.  Thanks.

Print("rsi.Result.Last(1) : {0}", rsi.Result.Last(1));


@Capt.Z-Partner

PanagiotisCharalampous
01 Jul 2020, 15:30

RE: RE:

Hi Delphima,

 I want to know the code below return RSI value based on last bar, but depend on which moment in the bar. Is it open price or high/close/low?

This value is calculated using the final bar values after the bar closes.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Capt.Z-Partner
01 Jul 2020, 16:05 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

PanagiotisCharalampous said:

Hi Delphima,

 I want to know the code below return RSI value based on last bar, but depend on which moment in the bar. Is it open price or high/close/low?

This value is calculated using the final bar values after the bar closes.

Best Regards,

Panagiotis 

Join us on Telegram

Thank you Panagiotis,

I got the reason, I need to set RSI parameter to open/close/high/low to get what I want from: rsi.Result.Last(1) 

Happy to learn new details from you.

Cheers,

Lei


@Capt.Z-Partner