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 SmartArtsStudio, Yesterday, 09:41 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by Lumbeezl, Today, 01:20 AM
        0 responses
        4 views
        0 likes
        Last Post Lumbeezl  
        Started by fawzanalim, Yesterday, 05:59 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by JuanPabloQuevedo, Yesterday, 05:27 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by StevenNelson, Yesterday, 03:24 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jason  
        Working...
        X