View Full Version : Using 'price' and borrowing existing code
grd974
07-07-2007, 08:30 AM
1) I would like to use price in a custom indicator.
When I write 'price' under the editor and compile I get this error: " The name 'price' does not exist in the current context ".
Knowing that NT6 comes with a "PriceAlert" indicator, I replace 'price' with 'PriceAlert.Price' which yieds to that error: " 'NinjaTrader.Indicator.Indicator.PriceAlert(double , bool)' is a 'method', which is not valid in the given context ".
So what should I do to use 'price' ?
2) Are properties, methods and classes embedded in provided NinjaScripts available to end users ? If yes, how can I copy a chunk of that code and insert it in my custom indicators ?
NinjaTrader_Ray
07-07-2007, 09:01 AM
1) What do you mean by use 'price'? Do you mean accessing OHLC data?
2) Open any script, highlight a selection of code, right click copy, then paste it into any script you are working on. Keep in mind, direct copy of code may not always be copied in a compileable state. You need to make sure you copy all required code or ammend variables that may be used in the copied code that is local to the file it was copied from.
grd974
07-07-2007, 10:10 AM
No, I mean tick price at the time alert condition is fullfilled
Here is my custom indicator :
protected override void OnBarUpdate()
{
if (High[0] == MAX(High, 34)[0])
Alert("Up"...);
else if (Low[0] == MIN(Low, 34)[0])
Alert("Dn"...);
}
In the AlertPrice NT indicator, I found this code :
Alert(DateTime.Now.Millisecond.ToString(), NinjaTrader.Cbi.Priority.Medium, "Price level '" + Price + "' hit!", Cbi.Core.InstallDir + @"\sounds\Alert4.wav", 0, Color.Yellow, Color.Black);
and I want to use it instead of my 'Up & Dn Alerts' but when I paste it over my own lines of code, the 'Price' name begets compilation errors.
NinjaTrader_Ray
07-07-2007, 01:25 PM
Thanks for the clarification.
This is because "Price" refers to a property/variable that is local to that indicator. Its not an available property of the indicator class itself.
Since you only want the price, do this:
Alert(DateTime.Now.Millisecond.ToString(), NinjaTrader.Cbi.Priority.Medium, "Price level '" + Close[0] + "' hit!", Cbi.Core.InstallDir + @"\sounds\Alert4.wav", 0, Color.Yellow, Color.Black);
grd974
07-07-2007, 01:45 PM
I am not sure I was crystal clear; what I am looking for is the Last Price which would appear in a Market Analyzer window.
How can I use that Last Price in my custom indicator ?
NinjaTrader_Ray
07-07-2007, 02:05 PM
Yes you were crystal clear.
Close[0] is the the most recent price provide you have the indicator's CalculateOnBarClose property set to false so it updated on each incoming tick.