Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

error code CS0103

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

    error code CS0103

    Please tell me what I am doing wrong with this code.

    Thanks,


    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class EMAColorBar : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "EMAColorBar";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    IsSuspendedWhileInactive = true;
    int FastPeriod = 5;
    int SlowPeriod = 7;


    }
    }

    protected override void OnBarUpdate()
    {
    if(EMA(FastPeriod)[0] > EMA(SlowPeriod)[0])
    BarBrush = Brushes.White;
    if(EMA(FastPeriod)[0] < EMA(SlowPeriod)[0])
    BarBrush = Brushes.Red;
    }
    }
    }

    #2
    Hello john3344,

    Welcome to the support forum.

    Just as a heads up for future posts it is always good to include what problem you are seeing. I can take a guess here and say that you are likely seeing a compile error, is that correct?


    The FastPeriod and SlowPeriod variables are declared in State.SetDefaults:
    Code:
    int FastPeriod = 5;
    int SlowPeriod = 7;
    Because they are defined there they can only be used there. If you were trying to make user inputs or even just variables they need to be put out of that scope into the class scope:


    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class EMAColorBar : Indicator
    {
    [B]int FastPeriod;
    int SlowPeriod;[/B]
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "EMAColorBar";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    IsSuspendedWhileInactive = true;
    [B]FastPeriod = 5;
    SlowPeriod = 7;[/B]
    
    
    }
    }
    
    protected override void OnBarUpdate()
    {
    if(EMA(FastPeriod)[0] > EMA(SlowPeriod)[0])
    BarBrush = Brushes.White;
    if(EMA(FastPeriod)[0] < EMA(SlowPeriod)[0])
    BarBrush = Brushes.Red;
    }
    }
    }

    You can take a look at the SampleMACrossOver strategy for a sample that is essentially the same as what you provided but has properties for User Input.


    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    55 views
    0 likes
    Last Post CarlTrading  
    Working...
    X