• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Divergence moving average indicator

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

    Divergence moving average indicator

    Hello,

    I have a custom indicator 20 period which I have saved as a separate 6 period indicator and plotted both to my chart. I am trying to change the bar color when they diverge, i.e one goes up while the other goes down, but this is not working.

    Code:
    	if ((myBsl[0]>myBsl[1]) && (myBslShortPeriod[0]<myBslShortPeriod[1]))					
    			{
    			BarColor = shortPeriodBsl;	
    			}
    If I just use:
    Code:
    (myBsl[0]>myBsl[1])
    OR
    Code:
    (myBslShortPeriod[0]<myBslShortPeriod[1])
    or have both plots going in the same direction for the if statement, the bar color does change, but I want them diverging. I have also tried:
    Code:
    if (Rising(myBsl))&& Falling(myBslShortPeriod)
    and
    Code:
    if (Rising(myBsl(20))&& Falling(myBsl(6)))
    But neither works. Is there a special way the code has to be written for divergences?

    Thank you!

    #2
    Hello GeorgeW,

    Thank you for your post.

    Are you using LineOnClose for the Chart Style on the chart? If so, BarColor and BarColorSeries would not change the color of the line on close. There is no exposed property to change the LineOnClose Chart Style for different bars.

    You should see your change on all other Chart Styles, such as CandleStick.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for responding PatrickH.
      I am not using LineOnClose. I am using OHLC bar styles. I know the BarColor works, because when I use
      Code:
      if (myBsl[0]>myBsl[1]) BarColor = shortPeriodBsl;
      it does change the color, and I have other code which changes the color of some of the bars.

      Comment


        #4
        Hello GeorgeW,

        Thank you for your patience.

        May we test the full code on our end? If so, please attach to your response or send to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H - 1507047' in the subject line.

        You can attach your indicator to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Sorry PatrickH, this code is private and cannot be shared.

          Thanks for your response.

          Comment


            #6
            Do you have a toy version, scaled down version, or another example script that creates the same behavior?
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              No, I don't have a scaled down version. or anything else where it produces the same behaviour.

              Thanks

              Comment


                #8
                Think I have got it to work now. The 2 plots that diverged where using the same name for "period", when I changed one to "shortPeriod" that solved it.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by saeed, Today, 02:07 PM
                2 responses
                5 views
                0 likes
                Last Post saeed
                by saeed
                 
                Started by 7robert, Today, 01:40 PM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by bortz, Today, 12:57 PM
                2 responses
                16 views
                0 likes
                Last Post bortz
                by bortz
                 
                Started by richa61416, Today, 01:18 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by Robotman, Today, 01:08 PM
                0 responses
                6 views
                0 likes
                Last Post Robotman  
                Working...
                X