Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Alert indicator for StochRSI and EMA not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Alert indicator for StochRSI and EMA not working

    Hello, I have this code for an indicator that should trigger an alert, if some conditions for StochRSI and EMA are met. But I am getting erro code CS0103 from the compiler, that StochRSI "does not exist in the current context". But Stoch RSI is a standard indicator in NinjaTrader, or is it not?
    Could you please check what could be the problem?
    Thanks a lot!

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Forms;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    using NinjaTrader.NinjaScript.Indicators;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class WAVEAlert1 : Indicator
    {
    private EMA ema20;
    private EMA ema50;
    private EMA ema200;
    
        [Range(1, int.MaxValue), NinjaScriptProperty]
        public int EMAPeriod1 { get; set; }
    
        [Range(1, int.MaxValue), NinjaScriptProperty]
        public int EMAPeriod2 { get; set; }
    
        [Range(1, int.MaxValue), NinjaScriptProperty]
        public int EMAPeriod3 { get; set; }
    
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Name = "Wave Alert 1";
                EMAPeriod1 = 20;
                EMAPeriod2 = 50;
                EMAPeriod3 = 200;
    
            }
            ema20 = EMA(EMAPeriod1);
            ema50 = EMA(EMAPeriod2);
            ema200 = EMA(EMAPeriod3);
            Add(StochRsi(8,3,3));
    
        }
    
    protected override void OnBarUpdate()
    {
    
        if(CurrentBar == Bars.Count -2 && ((ema20[0] < ema50[0] && stochRsi.Current[0] >= 0.8) || (ema20[0] > ema50[0] && stochRsi.Current[0] <= 0.2)))
    
        {
            Print("WAVE Alert on:  " + Instrument.FullName + "  at: " + Time[0]);
            Alert("WAVE Alert", Priority.High, "WAVE Alert", NinjaTrader.Core.Globals.InstallDir+@"\sounds\Alert3.wav", 20, Brushes.Khaki, Brushes.Black);
            System.Windows.Forms.MessageBox.Show("Get ready to make some MONEY! EMAs and Stoch RSI just did the WAVE!                 " + Instrument.FullName + "  at  " + Time[0].ToString("HH:mm"));
    
    
    
            }
          }
        }
      }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private WAVEAlert1[] cacheWAVEAlert1;
            public WAVEAlert1 WAVEAlert1(int eMAPeriod1, int eMAPeriod2, int eMAPeriod3)
            {
                return WAVEAlert1(Input, eMAPeriod1, eMAPeriod2, eMAPeriod3);
            }
    
            public WAVEAlert1 WAVEAlert1(ISeries<double> input, int eMAPeriod1, int eMAPeriod2, int eMAPeriod3)
            {
                if (cacheWAVEAlert1 != null)
                    for (int idx = 0; idx < cacheWAVEAlert1.Length; idx++)
                        if (cacheWAVEAlert1[idx] != null && cacheWAVEAlert1[idx].EMAPeriod1 == eMAPeriod1 && cacheWAVEAlert1[idx].EMAPeriod2 == eMAPeriod2 && cacheWAVEAlert1[idx].EMAPeriod3 == eMAPeriod3 && cacheWAVEAlert1[idx].EqualsInput(input))
                            return cacheWAVEAlert1[idx];
                return CacheIndicator<WAVEAlert1>(new WAVEAlert1(){ EMAPeriod1 = eMAPeriod1, EMAPeriod2 = eMAPeriod2, EMAPeriod3 = eMAPeriod3 }, input, ref cacheWAVEAlert1);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.WAVEAlert1 WAVEAlert1(int eMAPeriod1, int eMAPeriod2, int eMAPeriod3)
            {
                return indicator.WAVEAlert1(Input, eMAPeriod1, eMAPeriod2, eMAPeriod3);
            }
    
            public Indicators.WAVEAlert1 WAVEAlert1(ISeries<double> input , int eMAPeriod1, int eMAPeriod2, int eMAPeriod3)
            {
                return indicator.WAVEAlert1(input, eMAPeriod1, eMAPeriod2, eMAPeriod3);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.WAVEAlert1 WAVEAlert1(int eMAPeriod1, int eMAPeriod2, int eMAPeriod3)
            {
                return indicator.WAVEAlert1(Input, eMAPeriod1, eMAPeriod2, eMAPeriod3);
            }
    
            public Indicators.WAVEAlert1 WAVEAlert1(ISeries<double> input , int eMAPeriod1, int eMAPeriod2, int eMAPeriod3)
            {
                return indicator.WAVEAlert1(input, eMAPeriod1, eMAPeriod2, eMAPeriod3);
            }
        }
    }
    
    #endregion
    ​

    #2
    Hello cyberpete76,

    Alerts only appear in real-time.

    May I confirm State is State.Realtime when checking this condition?

    "if(CurrentBar == Bars.Count -2"

    This condition checks if current bar is count minus 2, which is typically how to find the last historical bar, and of course in historical Alerts cannot be triggered. In real-time this will always be true as both the Count and CurrentBar will always be increasing.

    "&& ((ema20[0] < ema50[0] && stochRsi.Current[0] >= 0.8) || (ema20[0] > ema50[0] && stochRsi.Current[0] <= 0.2))"

    How do you know this part of the condition is evaluating as true. In real-time the alert will only be sent if the condition evaluates as true.

    Please provide the output from prints showing that this condition is evaluating as true.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      yes I need this to work in realtime. I have other indicators already working exactly the same way. I just needed another one for a different strategy I want to test.
      The conditions should be correct. But as discribed in my first post, my problem is the error code CS0103 I am getting from the compiler, that StochRSI "does not exist in the current context".
      So there is something wrong with the stoch.RSI definition in my code.

      Thanks
      Peter

      Comment


        #4
        Hello Peter,

        There is no Add() method in NinjaTrader 8.

        Where you trying to use AddChartIndicator()?
        https://ninjatrader.com/support/help...tindicator.htm

        Yes, the StochRSI(int Period) is an indicator that is supplied with the installation of NinjaTrader.

        Note its a uppercase 'S', lowercase 'toch', uppercase 'RSI'. C# is case sensitive. You will need to match the help guide.

        Also, this has a Period input. The other 2 numbers you are putting in the method call are not valid.

        Below is a link to the help guide.
        https://ninjatrader.com/support/help...i_stochrsi.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I managed to get it working! Thanks a lot for the help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X