Category Trend  Published on 17/02/2012

Stochastic RSI

Description

From 'Cybernetic Analysis for Stocks and Futures' by John Ehlers.

StochasticRSI




qualitiedx2's avatar
qualitiedx2

Joined on 30.09.2011

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Stochastic RSI.algo
  • Rating: 5
  • Installs: 14083
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
PE
pedrofloreneesplago · 1 year ago

Error CS0246: The type or namespace name 'StochasticOscillator' could not be found (are you missing a using directive or an assembly reference?) (C:\Users\RENREN CLEOFE\Documents\cAlgo\Source\Robots\Sto\Sto\Sto.cs, line: 15, column: 17)

Error CS1501: No overload for method 'StochasticOscillator takes 3 arguments (C:\Users\RENREN CLEOFE\Documents\cAlgo\Source\Robots\Sto\to\Sto.cs, line: 20, column: 33)

Warning CS0612: 'Algo.MarketSeries' is obsolete (C:\Users\RENREN CLEOFE\Documents\cAlgo\Source\Robots\Sto\Sto\Sto.cs, line: 20, column: 54)

Warning CS0618: 'Robot.ExecuteMarketOrder(TradeType, Symbol, double, string)' is obsolete: 'Parameter 'Symbol symbol was replaced with 'string symbolName'. More details here https://ctrader.com/forum/announcements/15847' (C:\Users\RENREN CLEOFE\Documents\cAlgo\Source\Robots\Sto\Sto\Sto.cs, line: 37, column: 17)

PE
pedrofloreneesplago · 1 year ago

Can some fix the error and warning pleaseeee

PE
pedrofloreneesplago · 1 year ago

using System;
using cAlgo.API;

namespace StochasticStrategy
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class StochasticStrategy : Robot
    {
        [Parameter("Instrument")]
        public string Instrument { get; set; }

        [Parameter("Trade Volume (Lots)", DefaultValue = 0.1)]
        public double TradeVolume { get; set; }

        private StochasticOscillator _stoch;

        protected override void OnStart()
        {
            // Create the Stochastic oscillator with period of 14 and smoothing of 3
            _stoch = Indicators.StochasticOscillator(MarketSeries, 14, 3);

            // Subscribe to the Stochastic oscillator's Updated event
            _stoch.Updated += OnStochUpdated;
        }

        protected override void OnStop()
        {
            // Unsubscribe from the Stochastic oscillator's Updated event
            _stoch.Updated -= OnStochUpdated;
        }

        private void OnStochUpdated()
        {
            // Check if the %K and %D lines cross below 20, and execute a buy order if they do
            if (_stoch.PercentK.LastValue < 20 && _stoch.PercentD.LastValue < 20 && Positions.Count == 0)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, TradeVolume, "Stochastic Buy");
            }

            // Check if the %K and %D lines cross above 20, and close the position if they do
            if (_stoch.PercentK.LastValue > 20 && _stoch.PercentD.LastValue > 20 && Positions.Count > 0 && Positions[0].TradeType == TradeType.Buy)
            {
                ClosePosition(Positions[0]);
            }
        }
    }
}