View Full Version : stop price method
nicko9
01-23-2007, 02:19 PM
I am using the strategy wizard. How can I create an Action to exit (or enter) a position by a stop limit order, where the stop price is equal to the current bar open price plus [previous n bars hi/lo range/y], and the limit price is the [stop price +5] usung ticks.
I will want to make the previous bars reference value, n and the devisor, y, variables that i can set for testing pruposes.
thanks
Nick
NinjaTrader_Ray
01-24-2007, 02:24 AM
Nick09,
Your requirements exceeds the capability of the Condition Builder within the Strategy Wizard. You would need to code this directly using the NinjaScriptEditor. You must start the strategy from within the wizard and in the "User Defined Inputs" section, declare the inputs "N" and "Y".
Within the NinjaScript Editor, you would add code that looked like the following:
double stopPrice = Open[0] + Range()[N] / Y;
EnterLongStopLimit(stopPrice + 5 * TickSize, stopPrice);
I have included a sample strategy attached in the zip file. Please unzip the contents into the folder C:\Program Files\NinjaTrader 6\bin\Custom\Strategy and you can then open and review it via Tools > Edit NinjaScript > Strategy.
Ray
nicko9
02-12-2007, 09:47 PM
When using 'Range' (as in your example below), if I want the range of a series of bars i.e. the difference between the highest high and the lowest low of the last 3 bars, how do I request that?
I think using your example, I'm getting the range of a single bar n bars ago ("rangebars"=n):
double BuystopPrice = Open[0] + (Range()[rangeBars] / rangeDiv);
Plot1.Set(BuystopPrice);
double SellstopPrice = Open[0] - (Range()[rangeBars] / rangeDiv);
Plot2.Set(SellstopPrice);
this produces a log error: "error on calling the OnBarUpdate method for indicator Yoda2 on bar 0: Object reference not set to an instance of an object.
Please could you point me in th right direction.
NinjaTrader_Ray
02-13-2007, 02:57 AM
Try this:
double highValue = MAX(rangeBars)[0];
double lowValue = MIN(rangeBars)[0];
double rangeValue= highValue - lowValue;
nicko9
02-13-2007, 08:39 PM
that works- thanks!