Announcement

Collapse
No announcement yet.

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.

    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.


        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:	282
Size:	23.4 KB
ID:	1100289

            I look forward to being of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            23 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            120 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            63 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            45 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X