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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    155 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    307 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    244 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    345 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    176 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X