How to preset source in RSI indicator for a cBots, without manually setting?

Created at 01 Jul 2020, 23:52
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

How to preset source in RSI indicator for a cBots, without manually setting?
01 Jul 2020, 23:52


Hello,

I have below testing code, it will return last 1st bar's RSI values based on Open/Close/High/Low price. 

Now I want to preset sources for all the dataseries, but obviously I can't put string "Open" to replace Source_O, (in the highlighted area). What should I do to simplify the parameter setting area, to put all parameters preset in the coding stage rather than leave them for manually set?

Thank you again,

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 Open",  Group = "RSI")] public DataSeries Source_O { get; set; }
        [Parameter("Source Close", Group = "RSI")] public DataSeries Source_C { get; set; }
        [Parameter("Source High",  Group = "RSI")] public DataSeries Source_H { get; set; }
        [Parameter("Source Low",   Group = "RSI")] public DataSeries Source_L { get; set; }

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

        private RelativeStrengthIndex rsi_O;
        private RelativeStrengthIndex rsi_C;
        private RelativeStrengthIndex rsi_H;
        private RelativeStrengthIndex rsi_L;

        protected override void OnStart()
        {
            rsi_O = Indicators.RelativeStrengthIndex(Source_O, Periods);
            rsi_C = Indicators.RelativeStrengthIndex(Source_C, Periods);
            rsi_H = Indicators.RelativeStrengthIndex(Source_H, Periods);
            rsi_L = Indicators.RelativeStrengthIndex(Source_L, Periods);            
        }

        protected override void OnBar()
        {   
            Print("rsi_O.Result.Last(1) : {0}", rsi_O.Result.Last(1));
            Print("rsi_L.Result.Last(1) : {0}", rsi_L.Result.Last(1));
            Print("rsi_H.Result.Last(1) : {0}", rsi_H.Result.Last(1));
            Print("rsi_C.Result.Last(1) : {0}", rsi_C.Result.Last(1));
        }
    }
}

 


@Capt.Z-Partner
Replies

PanagiotisCharalampous
02 Jul 2020, 08:50

Hi Delphima,

Try the below

            rsi_O = Indicators.RelativeStrengthIndex(Bars.OpenPrices, Periods);
            rsi_C = Indicators.RelativeStrengthIndex(Bars.ClosePrices, Periods);
            rsi_H = Indicators.RelativeStrengthIndex(Bars.HighPrices, Periods);
            rsi_L = Indicators.RelativeStrengthIndex(Bars.LowPrices, Periods);

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

Capt.Z-Partner
02 Jul 2020, 12:31

RE:

PanagiotisCharalampous said:

Hi Delphima,

Try the below

            rsi_O = Indicators.RelativeStrengthIndex(Bars.OpenPrices, Periods);
            rsi_C = Indicators.RelativeStrengthIndex(Bars.ClosePrices, Periods);
            rsi_H = Indicators.RelativeStrengthIndex(Bars.HighPrices, Periods);
            rsi_L = Indicators.RelativeStrengthIndex(Bars.LowPrices, Periods);

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,

This works well. Thank you very much.:)

Lei


@Capt.Z-Partner