Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need suggestion on a strategy

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

    Need suggestion on a strategy

    Hello all,
    I'm want to develop a simple strategy to help me understand NinjaTrader better. In this strategy I want to do the following check:
    1. The trend for a stock goes up for the past 150 days, if not, do nothing;
    2. If the curve of Moving Average 20 goes across the curve of Moving Average 50, indicate this event.

    My questions are:
    1. Is there a practical algorithm to find the going-up trend for a stock? I did something by myself, but I don't feel it is a very good way. In my way, I checked Close[150] and Close[0], if Close[150] < Close[0], then this interval is a candidate for the going-up trend; then I checked for individual days in this interval, if the close price keeps going down for consecutive 15 days, I don't think this 150 days interval has a going-up trend.
    Please give me some hint or suggestions. I'm new to the stock business, so please be specific.

    2. How can I find the cross point between the MA20 and MA50 curve? Which function should I use for the existing library?

    Thank you very much for your time.

    #2
    Hello cniesa71,

    Welcome to the NinjaTrader Support Forums!

    1. Yes, there is a method call "CountIf()" that you may use that will test the number of occurcences over a look back period so that you can tell if a stock has been trending. So for example you can set this up on a daily chart and use CountIf() to see if the Close has been greater than the open for the past 150 days.

    Example;
    Code:
    // If in the last 150 bars we have had 150 up bars then go long
    if (CountIf(delegate {return Close[0] > Open[0];}, 150) >= 150)
        EnterLong();



    2. As to find the Cross you may use the CrossAbove() method built into NinjaTrader:

    Code:
    if (CrossAbove(SMA(20), EMA(50), 1))
        //Do Something



    Our Help Guide has many different examples and descriptions that you may want to view to help get use to the software.



    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    646 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X