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

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.

    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.

        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?

            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 bmartz, 03-12-2024, 06:12 AM
                4 responses
                32 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by Aviram Y, Today, 05:29 AM
                4 responses
                12 views
                0 likes
                Last Post Aviram Y  
                Started by algospoke, 04-17-2024, 06:40 PM
                3 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by gentlebenthebear, Today, 01:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cls71, Today, 04:45 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X