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;
      DierkNinjaTrader Customer Service

      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 beatitela, Today, 12:03 AM
        0 responses
        1 view
        0 likes
        Last Post beatitela  
        Started by Bidder, Yesterday, 09:16 PM
        0 responses
        13 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by connorgrant5, Yesterday, 07:12 PM
        0 responses
        18 views
        0 likes
        Last Post connorgrant5  
        Started by Trader_55, Yesterday, 06:01 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_EricB  
        Started by aotubusen, Yesterday, 04:28 PM
        0 responses
        19 views
        0 likes
        Last Post aotubusen  
        Working...
        X