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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    586 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    341 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    555 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X