Adding StochasticRSI Level 20 and 80 testing conditions

Created at 14 Aug 2021, 10:30
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!
SP

Space153

Joined 14.08.2021

Adding StochasticRSI Level 20 and 80 testing conditions
14 Aug 2021, 10:30


Good morning all. I want to add the condition that buying/selling should only happen if the crossover of the  Trigger and StochRSI happened above or below the 20 and 80 levels. Another thing is that the robot runs on a 1Hour timeframe, but uses a higher timeframe StochasticRSI. If I use bars to access a higher timeframe, the robot compiles successfully but does not start after adding an instance. It only starts when I'm using MarketSeries to access a higher timeframe. Please help me, I'm new to coding, still trying to find my way.

Below is the code I've been trying out.

 

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class STOCHASTICRSI : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        //private Bars H8;
        private StochasticRSI2 sri;
        private MarketSeries H8;
        protected override void OnStart()
        {
            // Put your initialization logic here
            // H8 = MarketData.GetBars(TimeFrame.Hour8);
            H8 = MarketData.GetSeries(Symbol, TimeFrame.Hour8);
            sri = Indicators.GetIndicator<StochasticRSI2>(H8, 14);
        }

        protected override void OnBar()
        {
            // Put your core logic here
            var Trigger = sri.trigger;
            var StochRSI = sri.StochRSI;


            if (StochRSI.HasCrossedAbove(Trigger, 0))
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000, "MACD", 50, 100);
            }
            else if (StochRSI.HasCrossedBelow(Trigger, 0))
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000, "MACD", 50, 100);
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


cTrader Automate
@Space153
Replies

amusleh
16 Aug 2021, 15:39

Hi,

Can you give the StochasticRSI indicator link? as its not a built-in indicator of cTrader,


@amusleh