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

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 Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        4 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        19 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Working...
        X