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

A Slope Colored Higher Time Frame SMA Ploted on a Smaller Time Frame Chart

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

    A Slope Colored Higher Time Frame SMA Ploted on a Smaller Time Frame Chart

    I want to Plot A Slope dependent Colored Higher Time Frame SMA Ploted on a Smaller Time Frame Chart (Ex. 13 SMA from 8 Range Chart on a 4R Chart).

    The Problem I think I'm having is when the Slope Changes from one to another (Rising or Falling) there is a Gap between the colors (See Picture Attached).

    Following is the Code (In next Post) I used and I'm not sure how to correct the logic to Plot what the Last state of the Slope Color was in the blank Gaps before the Slope Color changes?

    Thank You in Advance...
    Attached Files

    #2
    [CODE]
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
    return;

    //Rising Slope
    if(BarsArray[1][1] < BarsArray[1][0])
    {
    PlotSMA1.Set(LinReg(BarsArray[1],sMA1)[0]);
    }
    //Falling Slope
    if(BarsArray[1][1] > BarsArray[1][0])
    {
    PlotSMA2.Set(LinReg(BarsArray[1],sMA2)[0]);
    }
    //Flat Slope and previous Slope was Rising
    if(BarsArray[1][1] == BarsArray[1][0] && BarsArray[1][2] < BarsArray[1][1])
    {
    PlotSMA1.Set(LinReg(BarsArray[1],sMA1)[0]);
    }
    //Flat Slope and previous Slope was Falling
    if(BarsArray[1][1] == BarsArray[1][0] && BarsArray[1][2] > BarsArray[1][1])
    {
    PlotSMA2.Set(SMA(BarsArray[1],sMA2)[0]);
    }
    [CODE]

    Comment


      #3
      jmca2000,

      Thank you for your post.

      What is occurring here is that there are certain bars that are not hitting the conditions to set the plot dataseries.

      I can changed around the code to have it all one plot and set the values for that bar specifically.

      You can add in the conditions to change the color of the plot per your conditions using PlotColors[]

      Code:
      if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
      			return;
      
      			//Rising Slope
      			if(BarsArray[1][1] < BarsArray[1][0])
      			{
      				PlotSMA1.Set(LinReg(BarsArray[1],sMA1)[0]);
      			}
      			//Falling Slope
      			else if(BarsArray[1][1] > BarsArray[1][0])
      			{
      				PlotSMA1.Set(LinReg(BarsArray[1],sMA2)[0]);
      			}
      			//Flat Slope and previous Slope was Rising
      			else if(BarsArray[1][1] == BarsArray[1][0] && BarsArray[1][2] < BarsArray[1][1])
      			{
      				PlotSMA1.Set(LinReg(BarsArray[1],sMA1)[0]);
      			}
      			//Flat Slope and previous Slope was Falling
      			else if(BarsArray[1][1] == BarsArray[1][0] && BarsArray[1][2] > BarsArray[1][1])
      			{
      				PlotSMA1.Set(SMA(BarsArray[1],sMA2)[0]);
      			}
      http://www.ninjatrader.com/support/h...plotcolors.htm
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Thanks for your help Cal.

        Yes That Fixed It....
        Last edited by jmca2000; 09-05-2014, 04:16 PM.

        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
        4 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