Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help me with erro cs0115 script

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

    Help me with erro cs0115 script


    I'm creating the following strategy with EMA indicator, but there's an error that I can't fix and I don't know what it is, can anyone help me? Here's the 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.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.Custom
    {
    [Description("Indicador de Médias Móveis com Sinais de Compra e Venda")]
    public class MediasMoveisCruzamento : Indicator
    {
    private EMA ema7;
    private EMA ema20;
    private EMA ema34;
    private EMA ema72;

    protected override void Initialize()
    {
    // Configurações das médias móveis
    ema7 = EMA(7);
    ema20 = EMA(20);
    ema34 = EMA(34);
    ema72 = EMA(72);

    // Configurações dos plots das médias móveis
    AddPlot(Brushes.Red, "EMA7");
    AddPlot(Brushes.Green, "EMA20");
    AddPlot(Brushes.Blue, "EMA34");
    AddPlot(Brushes.Orange, "EMA72");
    Overlay = true;
    }

    protected override void OnBarUpdate()
    {
    // Atualiza os valores das médias móveis
    double ema7Value = ema7[0];
    double ema20Value = ema20[0];
    double ema34Value = ema34[0];
    double ema72Value = ema72[0];

    // Plota os valores das médias móveis
    Plot1.Set(ema7Value);
    Plot2.Set(ema20Value);
    Plot3.Set(ema34Value);
    Plot4.Set(ema72Value);

    // Verifica os cruzamentos das médias móveis
    if (CrossAbove(ema7, ema20, 1))
    {
    Print("Sinal de Compra: EMA7 cruzou acima da EMA20");
    // Execute ação de compra aqui
    }
    else if (CrossBelow(ema7, ema20, 1))
    {
    Print("Sinal de Venda: EMA7 cruzou abaixo da EMA20");
    // Execute ação de venda aqui
    }
    else if (CrossAbove(ema20, ema34, 1))
    {
    Print("Sinal de Compra: EMA20 cruzou acima da EMA34");
    // Execute ação de compra aqui
    }
    else if (CrossBelow(ema20, ema34, 1))
    {
    Print("Sinal de Venda: EMA20 cruzou abaixo da EMA34");
    // Execute ação de venda aqui
    }
    else if (CrossAbove(ema34, ema72, 1))
    {
    Print("Sinal de Compra: EMA34 cruzou acima da EMA72");
    // Execute ação de compra aqui
    }
    else if (CrossBelow(ema34, ema72, 1))
    {
    Print("Sinal de Venda: EMA34 cruzou abaixo da EMA72");
    // Execute ação de venda aqui
    }
    }
    }
    }
    ​​

    #2
    Hello andersja,

    Thanks for your post.

    It seems that this is a custom Indicator script created for NinjaTrader 7 so I have moved your forum thread from NinjaTrader 8 - Strategy Development to the NinjaTrader 7 - Indicator Development section of the forums.

    That said, To clarify, did you program the script yourself? Or, was the indicator you shared programmed by a third-party developer?

    What NinjaTrader version are you using? (NinjaTrader 7 or NinjaTrader 8) This could be found by going to Help > About on the Control Center.

    Is the error message related to using AddPlot() in your custom NinjaTrader 7 indicator?

    AddPlot() can only be used in NinjaScript strategies in NinjaTrader 7.

    To add a plot to a NinjaScript indicator in NinjaTrader 7, the Add() method must be used.

    Further, Brushes is only used in NinjaTrader 8, not NinjaTrader 7. Color would need to be used in the Add() method to set the color of a plot in NinjaTrader 7.

    See this help guide page for more information about using Add() to add a new plot to an indicator in NinjaTrader 7: https://ninjatrader.com/support/helpGuides/nt7/add.htm

    If this is not the error you are referring to, please send me a screenshot of the error message you are referring to so I may accurately assist you.
    • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
    • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I'm using ninjatrader in version 8.0.28.0. I made the script myself

      Comment


        #4
        Even update the code, its an erro CS0103

        Code Update:

        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.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Gui;
        using NinjaTrader.Gui.Chart;
        using NinjaTrader.Gui.SuperDom;
        using NinjaTrader.Data;
        using NinjaTrader.NinjaScript;
        using NinjaTrader.Core.FloatingPoint;
        using NinjaTrader.NinjaScript.Indicators;
        using NinjaTrader.NinjaScript.DrawingTools;
        #endregion

        //This namespace holds strategies in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Strategies
        {
        public class EMACrossOver : Strategy
        {
        private EMA emaFast;
        private EMA emaMedium;
        private EMA emaSlow;

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = "Estratégia de cruzamento de Médias Exponenciais";
        Name = "EMACrossOver";
        Fast = 7;
        Medium = 20;
        Slow = 34;
        IsInstantiatedOnEachOptimizationIteration = true;
        }
        else if (State == State.Configure)
        {
        emaFast = EMA(Fast);
        emaMedium = EMA(Medium);
        emaSlow = EMA(Slow);

        AddChartIndicator(emaFast);
        AddChartIndicator(emaMedium);
        AddChartIndicator(emaSlow);
        }
        }

        protected override void OnBarUpdate()
        {
        if (CurrentBar < BarsRequiredToTrade)
        return;

        if (CrossAbove(emaFast, emaMedium, 1))
        EnterLong();
        else if (CrossBelow(emaFast, emaMedium, 1))
        EnterShort();
        else if (CrossAbove(emaMedium, emaSlow, 1))
        EnterLong();
        else if (CrossBelow(emaMedium, emaSlow, 1))
        EnterShort();
        else if (CrossAbove(emaSlow, emaSlow[1], 1))
        EnterLong();
        else if (CrossBelow(emaSlow, emaSlow[1], 1))
        EnterShort();
        }
        }
        }

        Comment


          #5
          Hello andersja,

          Thanks for your notes.

          In the code you shared in post # 1 I see you are using protected override void Initialize() which is only used in NinjaTrader 7, not NinjaTrader 8, which is what led me to believe this was a NinjaTrader 7 script.

          Note that NinjaTrader 8 uses OnStateChange() instead of Initialize().

          In the code you shared on post # 4, I see you are instantiating variables and calling AddChartIndicator() in State.Configure. The script should be modified so that the indicators are instantiated in State.DataLoaded and AddChartIndicator() should be called in State.DataLoaded.

          AddChartIndicator(): https://ninjatrader.com/support/help...tindicator.htm

          See the SampleMACrossover strategy which demonstrates this. To view the script, open a New > NinjaScript Editor window, open the Strategies folder, and double-click on the SampleMACrossover file.

          That said, what exactly does the error message state so I may accurately assist (not to be confused with the error code number)?

          Also, if you double-click on the compile error, what is the line of code that the error is on?

          Please send me a screenshot of the error message you are referring to as requested in my previous post.
          • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
          • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.



          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          43 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          65 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X