PDA

View Full Version : Use of Log function


MicroAl
05-05-2008, 09:05 AM
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!

NinjaTrader_Ray
05-05-2008, 10:02 AM
See if this helps - http://www.ninjatrader-support.com/vb/showthread.php?t=3170

MicroAl
05-07-2008, 12:16 PM
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;
}
// 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()[[B]Math.Min(CurrentBar, 1)])
Log("This is a test", NinjaTRader.Cbi.LogLevel.Alert);
}

NinjaTrader_Ray
05-07-2008, 12:42 PM
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.

NinjaTrader_Dierk
05-07-2008, 12:50 PM
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.