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 cre8able, Yesterday, 01:16 PM
      3 responses
      11 views
      0 likes
      Last Post cre8able  
      Started by ChartTourist, Today, 08:22 AM
      0 responses
      6 views
      0 likes
      Last Post ChartTourist  
      Started by LiamTwine, Today, 08:10 AM
      0 responses
      2 views
      0 likes
      Last Post LiamTwine  
      Started by Balage0922, Today, 07:38 AM
      0 responses
      5 views
      0 likes
      Last Post Balage0922  
      Started by JoMoon2024, Today, 06:56 AM
      0 responses
      6 views
      0 likes
      Last Post JoMoon2024  
      Working...
      X