Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use of Log function

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

    Use of Log function

    I have just started learning C# and NinjaScript. I wish to produce an alert box which I believe I can use the log function to use. I have tried doing the following in an indicator after the OnBarUpdatebar call.

    If Vol [0] > Vol [1]
    Log etc (ie print Log Alert)

    Unfortunately the computer crashes on using this function, while it compiles without any errors. I have used the Alert function ok with various
    conditions, so I presume it is something about the use of the Log function
    which is causing the problem

    Any help on using the Log function would be appreciated!

    #2
    See if this helps - http://www.ninjatrader-support.com/v...ead.php?t=3170
    RayNinjaTrader Customer Service

    Comment


      #3
      Don't try this at home

      Thanks Ray, perhaps you or someone could answer why the following script completely crashed Ninja

      Please note the last two lines of the method below:

      I am trying to get a pop up box in response to a simple volume check on the last bar. The Alerts work fine, however on entering the last two lines, although the script compiled fine, on adding the indicator, NinjaTrader
      completely crashed the computer. Even a fresh install of Ninja suffered the
      same problem, and it took me several attempts at reinstalling to get Ninja back. I would be very interested to know why this happened. I suspect it is something to do with an indefinite loop somewhere!

      Please note the script may have been: if (Vol() [0] > Vol() [1]...........




      protectedoverridevoid OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.
      //Do not calculate if we don't have enough bars
      if(CurrentBar < period) return;
      //Get a sum of prices over the specified period
      double sum = 0;
      for (int barsAgo = 0; barsAgo < period; barsAgo++)
      {sum = sum + Input[barsAgo];
      }
      // Calculate and set the 'average' value to the 'Plot0' property
      Plot0.Set(sum/Period);
      if (VOL()[0] > VOL()[1])
      Alert(
      "myAlert", NinjaTrader.Cbi.Priority.High, "Volume Higher than Previous Bar", "Alert1.wav", 10, Color.Black, Color.Yellow);
      if (VOL()[0] > 100)
      Alert(
      "myAlert1", NinjaTrader.Cbi.Priority.High, "Volume > 100", "Alert1.wav", 10, Color.Black, Color.Yellow);
      if (Vol()[0] > Vol()[Math.Min(CurrentBar, 1)])
      Log("This is a test", NinjaTRader.Cbi.LogLevel.Alert);
      }

      Comment


        #4
        I don't see anything after a 1 minute review that would cause it to crash, any error messages in log? If not, you will have to comment out most code and add line by line to see find the offending line.

        Also, you can use the SUM() indicator instead of doing it yourself.
        RayNinjaTrader Customer Service

        Comment


          #5
          Please make sure you don't call Log() on every incoming tick, since this might flood the logs with unnecessary info. Use Print() for debugging purposes.
          DierkNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kazisl, Today, 06:41 PM
          0 responses
          2 views
          0 likes
          Last Post kazisl
          by kazisl
           
          Started by einstein, Today, 06:20 PM
          0 responses
          2 views
          0 likes
          Last Post einstein  
          Started by op1031, Today, 05:51 PM
          0 responses
          4 views
          0 likes
          Last Post op1031
          by op1031
           
          Started by nighttrader99, Today, 04:34 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by Simon Investimens, Today, 02:51 PM
          1 response
          15 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Working...
          X