Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

need help. indicator not printing crossover.

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

    need help. indicator not printing crossover.

    i have a simple moving average crossover. its showing the moving average indicator but not showing the crossover.
    I dont know why. I need some help.
    Code:
        if(!(CurrentBar> Faster     && CurrentBar> Slower     && CurrentBar> ReallySlow))
                    return;
    
                FasterMA[1]=EMA(Faster)[1];
                SlowerMA[1]=EMA(Slower)[1];
                ReallySlowMA[1]=SMA(ReallySlow)[1];
                CrossedUP[0]=CrossAbove(FasterMA,SlowerMA,1);
                if(CrossedUP[0])
                {
                    Print( "crossed up") ;
                    Draw.TriangleUp(this,CurrentBar + "Drawup" ,true, 0, SlowerMA[1], Brushes.Red);
                }
    
                CrossedDown[0]=CrossBelow(FasterMA,SlowerMA,1);
                if(CrossedDown[0])
                {
                    Draw.TriangleDown(this,CurrentBar + "DrawDown" ,true, 0, SlowerMA[1], Brushes.Red);
                        Print( "crossed down") ;
                }​
    MovingAverageCrossOver.cs

    #2
    Hello junkone,

    Typically, indicator instances are assigned to variables in State.DataLoaded.

    In the scope of the class:
    Code:
    private EMA fastEMA;
    private EMA slowEMA;
    In State.DataLoaded:
    Code:
    fastEMA  = EMA(FastPeriod);
    slowEMA  = EMA(SlowPeriod);
    In OnBarUpdate():
    Code:
    if (CurrentBar < 1 || CurrentBar < FastPeriod || CurrentBar < SlowPeriod)
    return;
    
    Print(string.Format("{0} | , fastEMA[1]: {1} < slowEMA[1]: {2} && fastEMA[0]: {3} > slowEMA[0]: {4}", Time[0], fastEMA[1], slowEMA[1], fastEMA[0], slowEMA[0]));
    
    if ( CrossAbove(fastEMA, slowEMA, 1) )
    {
    Print(string.Format("{0} | CrossedAbove"));
    Draw.TriangleUp(this,CurrentBar + "Drawup" ,true, 0, slowEMA[1], Brushes.Red);
    }
    Use Print() to understand the behavior.

    If the print in the action block of the condition is not true to understand why, print all values used in the condition along with the time of the bar. If a variable has an unexpected value print all values used to calculate the value.

    Below is a link to a forum post that demonstrates using Print() to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X