PDA

View Full Version : Limit order question


Jeff 15
04-06-2009, 07:44 AM
I have a strategy I would like to add a limt order upon the stoploss being activated at the stop price.

I was thinking something like:

if (SetStopTarget("Long"))
{
EnterLongLimt (10000, "LL")
}

This of course is not correct. Can you point me in the right direction?
Thank you,

NinjaTrader_Josh
04-06-2009, 08:15 AM
Jeff 15,

You will have to work within the OnOrderUpdate() method to submit an order off of an order event. Please see the reference sample section of the forums for an idea of how to use OnOrderUpdate(): http://www.ninjatrader-support2.com/vb/showthread.php?t=7499

Jeff 15
04-06-2009, 01:05 PM
Ok, I read the info you sent me and the help guide on "OnOrderUpdate" I have amended my stategy. I think I should have the new limit order under Onexecution because I only want it entered if it is stopped out. Im not sure how to have the EnterLongLimit recognize the new limit price as the executed stoploss. I have attached a sceen shot.

Thank you for help.:)

NinjaTrader_Josh
04-06-2009, 02:52 PM
Jeff 15,

You need to store the stop loss price you used into your own variable. Then you can reference it again in OnExecution.

Jeff 15
04-06-2009, 03:34 PM
Can you tell me where I might reference this in the help guide or support forum?

Thank you,

NinjaTrader_Josh
04-06-2009, 03:56 PM
Jeff 15,

There is no reference. It is a simple programming concept. Whatever value you decide to use as your stop loss, also save it into a variable.

General idea. Untested code.
myStop = Close[0] + 15 * TickSize;
SetStopLoss(CalculationMode.Price, myStop);
....
EnterLongLimit(myStop);

Something like that.

Jeff 15
04-07-2009, 08:03 AM
I read as much as I could find on saving variables. I think Im pretty close. Im just having trouble asigning the variable. I have attached screen shot. Any advice would be great.

Thank you,

NinjaTrader_Josh
04-07-2009, 08:35 AM
Jeff 15,

You cannot use the word TickSize as your variable since this is a reserved word. All you need to do is declare yourself a variable as a double then you can store whatever value you want.

In Variables section of your code:
private double myVar = 0;

In your OnExecution somewhere
myVar = execution.Order.AvgFillPrice;

To use this value now you can just call myVar.