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 Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,769 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        10 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        7 views
        0 likes
        Last Post rocketman7  
        Working...
        X