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

Three Bar Simple Moving Average Cross Over

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

    Three Bar Simple Moving Average Cross Over

    Hi, I am trying to get a purchase signal off of a Price Close three periods after a cross over of a 10 period Simple Moving Average (SMA).

    How would you construct this using the Strategy Builder Conditions Wizard ensuring that each of the past three periods have closed green after the cross over.

    Please see the images attached to this thread.

    Thank you.

    #2
    Hello stock_wizard_49,

    Thanks for your post and welcome to the NinjaTrader forums!

    One way to accomplish your goal would be to save the bar number where the cross condition occurs in one set and in another set check to see if the cross occurred 3 bars ago and check that the 3 previous bars Close[] is greater then the Open[] for each of the 3 bars.

    I've created an educational example that you can test with. It will show a gold vertical bar on each cross condition and then a blue vertical bar when there are 3 green bars after the cross.

    To accomplish the math of the current bars check, a custom int series is used called CrossUpEvent.
    In set 1 (the sequence of sets is important), there are no conditions so that on every bar update the previous bar of the CrossUpEvent series is updated to the current bar value.
    In set 2 is the cross condition and the actions are to save the CurrentBar (the bar where the cross occurred) into the custom series and to color the backpanel a yellow color.
    In set 3, the condition is checked to see if the CrossUpEvent + 3 is equal to the CurrentBar value (meaning 3 bars have passed since the last cross. Also that the Close is greater than the open for the last 3 bars. The action is to then color the backplane a blue.

    Here is a screenshot example:

    Click image for larger version

Name:	ExampleCrossThen3upbars.PNG
Views:	389
Size:	31.2 KB
ID:	1109184


    I've attached the educational example here: ExampleCrossthen3Upbars.zip


    Here is a basic guideline of how to Import NinjaScripts.

    To import NinjaScripts you will need the original .zip file.

    To Import
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu File> Utilities> Import NinjaScript
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.

    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'


    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,607 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    9 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    19 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    6 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    15 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X