Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 MSerag, 05-06-2024, 11:52 PM
    4 responses
    25 views
    0 likes
    Last Post MSerag
    by MSerag
     
    Started by TraderCro, Today, 12:13 AM
    0 responses
    2 views
    0 likes
    Last Post TraderCro  
    Started by Skifree, Yesterday, 11:47 PM
    0 responses
    7 views
    0 likes
    Last Post Skifree
    by Skifree
     
    Started by Skifree, Yesterday, 11:41 PM
    0 responses
    6 views
    0 likes
    Last Post Skifree
    by Skifree
     
    Started by Skifree, Yesterday, 11:38 PM
    0 responses
    4 views
    0 likes
    Last Post Skifree
    by Skifree
     
    Working...
    X