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

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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rocketman7, Today, 01:00 AM
          0 responses
          1 view
          0 likes
          Last Post rocketman7  
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          27 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 04-23-2024, 09:53 PM
          2 responses
          74 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          193 views
          0 likes
          Last Post Hasadafa  
          Working...
          X