PDA

View Full Version : Calculating a limit entry


kevinh786
12-07-2008, 10:54 AM
Can someone help me code the following limit entry...

For a long limit entry, I want the entry order to be placed at the closest tick above the 15 period EMA. For example if the EMA is at 828.35 I want the limit order to be placed at 828.50. If the EMA is at 828.50, I want the limit order to be placed at 828.75. I just need it to work on the ES at the moment but I'd like it to work on all markets eventually.

My current code that doesn't give the correct entry is...

myEntryOrder = EnterLongLimit(DefaultQuantity, EMA(Close, 15)[0] + 1 * TickSize , "Long Entry");

Thanks for any help.

Kevin

span.jajahWrapper { font-size:1em; color:#B11196; text-decoration:underline; } a.jajahLink { color:#000000; text-decoration:none; } span.jajahInLink:hover { background-color:#B11196; }

NinjaTrader_Ray
12-07-2008, 01:58 PM
Try this:

myEntryOrder = EnterLongLimit(DefaultQuantity, Instrument.MasterInstrument.Round2TickSize(EMA(15)[0] + TickSize), "Long Entry");


More information - http://www.ninjatrader-support.com/HelpGuideV6/InstrumentMasterInstrumentRound2TickSize.html

kevinh786
12-07-2008, 03:16 PM
Thank you Ray for the response but it's not exactly what I'm looking for.

The Instrument.MasterInstrument.Round2TickSize seems to be rounding to the closest tick, be it lower or higher.

For my long entry, I only want to round up. So if the EMA is at 872.05, I want it to round to 872.25 not 872.00.

Any suggestions?

Thanks again.

Kevin

NinjaTrader_Ray
12-07-2008, 03:20 PM
Would adding some additional logic like this work?

if (value < EMA value) value = value + TickSize;

kevinh786
12-07-2008, 03:46 PM
That might work but I don't know how to incorporate that code into my program. I'm not sure where to put it.

Would I have to create a new variable?

I'm still pretty new to programming.

Thanks Ray.

Kevin

NinjaTrader_Bertrand
12-08-2008, 05:35 AM
Hi Kevin,

Yes, it would be best to create a new variable where you calculate your limit order entry value based on your conditions.

Before moving on, please take a look at our indicator and strategy creating tutorials, which give you a great start for custom coding on your own -

http://www.ninjatrader-support.com/HelpGuideV6/Overview18.html

http://www.ninjatrader-support.com/HelpGuideV6/Overview39.html

Here is a link to more advanced Reference Samples and NinjaScript Tips on this forum - http://www.ninjatrader-support.com/HelpGuideV6/ReferenceSamples.html