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 ageeholdings, Today, 07:43 AM
      0 responses
      7 views
      0 likes
      Last Post ageeholdings  
      Started by pibrew, Today, 06:37 AM
      0 responses
      4 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by rbeckmann05, Yesterday, 06:48 PM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      12 views
      0 likes
      Last Post burtoninlondon  
      Working...
      X