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 hazylizard, Today, 08:38 AM
        2 responses
        8 views
        0 likes
        Last Post hazylizard  
        Started by geddyisodin, Today, 05:20 AM
        2 responses
        17 views
        0 likes
        Last Post geddyisodin  
        Started by Max238, Today, 01:28 AM
        5 responses
        47 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by habeebft, Today, 07:27 AM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Working...
        X