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

Displaced MA in strategy builder

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

    Displaced MA in strategy builder

    How do you displace a MA to the left in strategy builder? I use it on an indicator and it would be a signal line. When it crosses above/below the other MA it paints the bar a specific color. I've got that part but am not successful in the first.

    Thanks

    #2
    Hello dedouglas,

    Thank you for the question.

    In NinjaScript there is no concept of "displacement" you would instead use the BarsAgo concept to reference data from other bars. For example, if you wanted to compare an MA against its self for a different bar value, you would use a BarsAgo of 1 or the number of bars you wanted ago.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Does this work on the cross above/below? I couldn't get my bars to paint until I switch condition to greater then. It was coloring them a bar or two late also and a few in a row until filtered out by other conditions. My goal is to paint the one bar a certain color when the signal line crosses above/below the other. Its an sma of the same period, but I want one offset to the left 1 bar. The input series isn't price but another indicator value if that makes a difference.

      Thanks

      Comment


        #4
        Hello dedouglas,

        The Cross above and below use a Lookback period which is how they would compare crossings. I see you noted you wanted to compare the same SMA of the same period, just offset by 1 bar. In a chart you can do this manually using the Displacement property of the indicator, however, in NinjaSript there is no concept of simply moving the values over. Displacement is just a visual change which moves the existing values in the direction you specified by that number of bars, the values are still all identical and still apply to the same bars they originally did. In NinjaScript you could instead use 1 BarsAgo in this situation, you could compare the SMA against the SMA of 1 bar ago to see fi there was a crossing.

        When configuring the condition, you would enter 1 BarsAgo when configuring the first or second indicator to get the value of 1 bars ago for comparison.



        I look forward to being of further assistance.


        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          Can you please show a screenshot of how this comparison can be made in strategy builder?

          I want to be able to compare SMA (14)[0] against SMA (14)[1] either using a Greater Than or a cross over comparison check.

          Thanks.
          Attached Files

          Comment


            #6
            Hello NTbrass,

            You can use the BarsAgo field to denote what data is used for each indicator, the left and right sides control properties for each indicator.

            For the SMA of the same period you would likely need to use greater/lesser here to see any change in condition, the crossabove/below would be better used in a situation where you have some spans of time between crossings such as two different period SMA's or a fast/slow. You can see an example of this in the SampleMACrossOver strategy that comes with the platform however that is manually coded. You can do a View Code from the builder and then compare that against the sample to see if you are doing a similar condition or logic though.

            As a side note here is a link to our public strategy builder webinar that goes over the condition builder: https://youtu.be/HCyt90GAs9k

            Here is an image of a cross above condition between two smas, as noted you would likely need to use two different periods instead of bars ago here to see something similar to the SampleMACrossOver.

            Click image for larger version

Name:	NinjaTrader_2020-05-18_07-43-10.png
Views:	221
Size:	23.4 KB
ID:	1100289

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by gravdigaz6, Today, 11:40 PM
            0 responses
            4 views
            0 likes
            Last Post gravdigaz6  
            Started by MarianApalaghiei, Today, 10:49 PM
            3 responses
            9 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by XXtrader, Today, 11:30 PM
            0 responses
            3 views
            0 likes
            Last Post XXtrader  
            Started by love2code2trade, Yesterday, 01:45 PM
            4 responses
            28 views
            0 likes
            Last Post love2code2trade  
            Started by funk10101, Today, 09:43 PM
            0 responses
            9 views
            0 likes
            Last Post funk10101  
            Working...
            X