Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A problem with an indicator.

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

    A problem with an indicator.

    Hi all,

    I'm a beginner with ninjaScript and i am trying to develop a simple indicator:
    I need that :
    If the close[0] is greater that close [1] ------>Indicator value = Close [0] and Remember this close
    If the close[0] is not greater that close [1]----> indicator value = Remember.

    I am trying this code...
    __________________________________________________ _______

    double remember = 0;

    If (Close[0] > Close[1])
    {
    Plot0.Set(Close[0]);
    Remember = (close[0]); -------- > I need that this variable remember this Close !.
    }
    else
    {
    Plot0.set(Remember);
    }
    __________________________________________________ _______
    If i write this code the indicator values will be “ close” or “0” but do not remember the last close when the sentence is false

    Does anyone have an example script that shows how to remember values ?.
    I need that the indicator remember that close.

    Sorry for my english and thanks for your help.


    Regards



    #2
    You need to create a variable whose scope (liftime) is that of the indicator.

    Under the variables section of the indicator add:

    private double remember = 0;

    then your code would look like:

    if (Close[0] > Close[1])
    {
    Plot0.Set(Close[0]);
    remember = Close[0];
    }
    else
    {
    Plot0.Set(remember);
    }
    RayNinjaTrader Customer Service

    Comment


      #3
      Also: make sure you add code like this:
      Code:
      if (CurrentBar < 1)
           return;

      Comment


        #4
        Yeah !
        Now! ,the indicator is working very well !
        Thanks a lot for your help Ray and thanks for your time.
        This support is fantastic !

        Regards

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        585 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        340 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X