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 GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,279 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        19 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Tim-c, Today, 02:10 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        5 views
        0 likes
        Last Post Taddypole  
        Started by chbruno, 04-24-2024, 04:10 PM
        4 responses
        52 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Working...
        X