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

setting a value in a recursive variable

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

    setting a value in a recursive variable

    I am trying to create a recursive variable that holds its historical values and am not able to figure out how to do this in Ninjascript.

    The following is ThinkScript code from TOS:

    def C = C[1] + volume;
    plot CumulativeVolume = C;


    Thanks!

    #2
    Originally posted by tradernith View Post
    I am trying to create a recursive variable that holds its historical values and am not able to figure out how to do this in Ninjascript.

    The following is ThinkScript code from TOS:

    def C = C[1] + volume;
    plot CumulativeVolume = C;


    Thanks!
    Show the code that you have now, and we can see how to correct it. It is pretty simple in NinjaScript, but certainly a different paradigm from ThinkScript, and definitely not as concise.

    Comment


      #3
      Originally posted by tradernith View Post
      I am trying to create a recursive variable that holds its historical values and am not able to figure out how to do this in Ninjascript.

      The following is ThinkScript code from TOS:

      def C = C[1] + volume;
      plot CumulativeVolume = C;


      Thanks!
      Below you will find a translation.

      Code:
      [COLOR=Green]// add plot in Initialize section[/COLOR]
      [COLOR=Blue]protected override void[/COLOR] Initialize()
      {
          Add([COLOR=Blue]new[/COLOR] Plot([COLOR=Blue]new[/COLOR] Pen(Color.DarkOrange, 2), PlotStyle.Bar, "Cumulated Volume"));
          ........
      }
      
      [COLOR=Green]// calculate cumulated volume in OnBarUpdate()[/COLOR]
      [COLOR=Blue]protected override void [/COLOR]OnBarUpdate()
      {
           [COLOR=Blue] if[/COLOR](CurrentBar == 0)
                  C.Set(Volume[0]);
            [COLOR=Blue]else[/COLOR]
                  C.Set(C[1] + Volume[0]);
            ......
      }
      
      [COLOR=Green]// define property for the first plot[/COLOR]
      [COLOR=Blue]#region[/COLOR] Properties
      [Browsable(false)]
      [XmlIgnore()]
      [COLOR=Blue]public[/COLOR] DataSeries C
      {
            [COLOR=Blue]get[/COLOR] { [COLOR=Blue]return[/COLOR] Values[0]; }
      }
      ....
      [COLOR=Blue]#endregion[/COLOR]
      Last edited by Harry; 06-15-2013, 02:51 AM.

      Comment


        #4
        Thanks Harry and Koganam! Let me try this out.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by benmarkal, Yesterday, 12:52 PM
        3 responses
        22 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by helpwanted, Today, 03:06 AM
        1 response
        17 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        11 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        6 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        244 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Working...
        X