Put Moving Average on RSI Indicator in code

Created at 24 Aug 2015, 16:48
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!
usynn's avatar

usynn

Joined 13.02.2015

Put Moving Average on RSI Indicator in code
24 Aug 2015, 16:48


Hi, it is possible to set the source of a simple moving average on a chart to the source of an rsi indicator. This then shows the moving average in the RSI window. However, the problem i'm having is being able to do this in code.

The SimpleMovingAverage requires a DataSeries source and I can't seem to be able to get the dataseries of the RSI.


@usynn
Replies

Spotware
25 Aug 2015, 09:06

RE:

usynn said:

Hi, it is possible to set the source of a simple moving average on a chart to the source of an rsi indicator. This then shows the moving average in the RSI window. However, the problem i'm having is being able to do this in code.

The SimpleMovingAverage requires a DataSeries source and I can't seem to be able to get the dataseries of the RSI.

Dear Trader,

Could you please explain your issue in more detail? 

In the following code snippet the SMA and the RSI indicator will be initialized with the same DataSeries.

        RelativeStrengthIndex rsi;
        SimpleMovingAverage sma;

        protected override void Initialize()
        {
            rsi = Indicators.RelativeStrengthIndex(DataSource, Period);
            sma = Indicators.SimpleMovingAverage(DataSource, Period);
        }

 


@Spotware

usynn
26 Aug 2015, 13:31

I want the simple moving average to be an average of the RSI values, not a SMA on the chart finding an average of the candlesticks. I want the SMA in the RSI window finding an average of the RSI values.


@usynn

usynn
26 Aug 2015, 13:38 ( Updated at: 21 Dec 2023, 09:20 )

Like this. can you see the RSI (green) and the SMA (red). This can be done in the GUI but i wish to achieve the same thing but in code


@usynn

Spotware
26 Aug 2015, 13:47

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware

usynn
26 Aug 2015, 18:29

what's the point of this forum if you can't help with coding?


@usynn

paul.williams125
26 Jan 2020, 12:24

RE:
            rsi = Indicators.RelativeStrengthIndex(MarketData.Close, Period, MAType);
            sma = Indicators.SimpleMovingAverage(rsi, Period);

or

               public IndicatorDataSeries dataSeries;

--------------------------------------------------------------------------

               dataSeries = CreateDataSeries();

             rsi = Indicators.RelativeStrengthIndex(MarketData.Close, Period, MAType);

             sma = Indicators.SimpleMovingAverage(dataSeries, Period);

-----------------------------------------------------------------------

          dataSeries[index] = rsi.Result[index];

-------------------------------------------------------------------------

-------------------------------------------------------------------------

This is 5% better.

   public IndicatorDataSeries dataSeries_Ma;

   public IndicatorDataSeries dataSeries_Rsi;

   public MovingAverage  _ma;

   public RelativeStrengthIndex _rsi;

-----------------------------------------------------------------------

               dataSeries_Ma = CreateDataSeries();

               dataSeries_Rsi = CreateDataSeries();

             _rsi = Indicators.RelativeStrengthIndex(dataSeries_Rsi, Period, MAType);

             _ma = Indicators.MovingAverage(dataSeries_Ma, Period, MAType);

-----------------------------------------------------------------------

              dataSeries_Rsi[index] = (MarketSeries.Close + MarketSeries.Open) / 2

              dataSeries_Ma[index] = rsi.Result[index];

 

(close + open /2 ) is better because close, swings about a lot,  high and low is noise

I want to write an algo that smooths the price, using price action patterns ,  lots of moves stored - just like a computer that plays chess. nearly there...


@paul.williams125