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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    36 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    14 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    19 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    22 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X