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

Plotting variables

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

    Plotting variables

    I'd like to plot and indicator for trend.
    If a certain condition is met then the trend is up and the indicator plots 1, otherwise, if another condition is met the the trend is down and the indicator plots -1.

    Following is the code:

    if (CurrentBar < Barre1)
    return;
    if (Close[0] > MAX(High, Barre1)[1])
    {
    Plot0.Set(1);
    }

    if (Close[0] < MIN(Low, Barre1)[1])
    {
    Plot1.Set(-1);
    }

    The problem is that there are empty spaces but I'd like to have the previous value (1 or -1) until the trend does not change.

    How can I write the code to plot the previous value and have a continuous indicator?

    Thanks for any help.

    #2
    imported post

    Usea variableto store the current trend value. Declare the variable under the variables section:

    private double trend = 1;

    Then in the OnBarUpdate():

    if (CurrentBar < Barre1)
    return;

    if (Close[0] > MAX(High, Barre1)[1])
    trend = 1;
    else if (Close[0] < MIN(Low, Barre1)[1])
    trend = -1;

    Plot1.Set(trend);


    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Perfect.

      Now is working fine.

      Thanks very much.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by halgo_boulder, 04-20-2024, 08:44 AM
      2 responses
      21 views
      0 likes
      Last Post halgo_boulder  
      Started by mishhh, 05-25-2010, 08:54 AM
      19 responses
      6,189 views
      0 likes
      Last Post rene69851  
      Started by gwenael, Today, 09:29 AM
      0 responses
      5 views
      0 likes
      Last Post gwenael
      by gwenael
       
      Started by Karado58, 11-26-2012, 02:57 PM
      8 responses
      14,830 views
      0 likes
      Last Post Option Whisperer  
      Started by Option Whisperer, Today, 09:05 AM
      0 responses
      2 views
      0 likes
      Last Post Option Whisperer  
      Working...
      X