PDA

View Full Version : How to cancel the SetProfitTarget


toyogo00
04-23-2008, 11:01 AM
Hi

On the "Backtest" menu, I set "Time in force" = Day (instead of GTC) and I set the Session from 12:00:00AM to 11:59:00PM.

The following is my program that will execute the BuyStop order when the condition met. It would also cancell the order if the triggered buy stop order is not filled for the day. However, I find that the ProfitTarget & StopLoss order is not cancelled automatically when the buy stop order is cancelled due to the "Time in force" triggered.

Shall I use OnOrderUpdate(IOrder order) to cancel it manually(I don't know how to do so) or there is a parameter to set. Pls advise!


protected override void Initialize()
{
SetProfitTarget("Ent", CalculationMode.Ticks, 400);
SetStopLoss("Ent", CalculationMode.Ticks, 400, false);
CalculateOnBarClose = false;
}

protected override void OnBarUpdate()
{
if ("My specific condition here")
{
EnterLongStop(100000, High[0], "Ent");
}
}

Regards,
Toyogo

NinjaTrader_Ray
04-23-2008, 11:10 AM
Not sure I follow...

The stop/target are only placed as you have a position open. So if you have an open position at session close, do you not want the stop/target to persist into the next session?

toyogo00
04-23-2008, 12:34 PM
Hi,

I want to end the stop/target at the end of the session. Anyway, after recompile the program, it has cancelled stop/target automatically if the buystop order cancelled.

There is another question. How do I set the "Backtest" parameter such that there is only one buystop order (one trade) per session even if the same condition met multiple times. (or through programming)

Regards,
Toyogo

NinjaTrader_Ray
04-23-2008, 01:34 PM
You would have to self program some flag that is set once the 1st order of a session has been submitted and then reset this when the property FirstBarOfSession is true.

toyogo00
04-23-2008, 11:06 PM
Hi,
Thanks. While trying to program a flag, I found that my buystop order was first accepted, then cancelled on the next bar (1min) without valid reason. (don't know what has triggered it). I've checked it is a valid order as prices of triggered bar is small then the stop price.

I thought it may be due to SetProfit/Stop so I remarked it out. (see below). The print of OnOrderUpdate shows that the BuyStop order is accepted at 2.00pm but cancelled at 2.01pm. Pls help


protected override void Initialize()
{
/// SetProfitTarget("Ent", CalculationMode.Ticks, 400);
/// SetStopLoss("Ent", CalculationMode.Ticks, 400, false);

CalculateOnBarClose = false;
}

protected override void OnBarUpdate()
{
if (certain condition)
{
/// will only reset to null at the FirstBarOfSession
if (entryOrder == null)
entryOrder = EnterLongStop(100000, Highvalue,"Ent");
}
}

*****
CurrBarTm :14/4/2008 2:00:00 PM
PendingSubmit
Ent
1.97355
0
*****
*****
CurrBarTm :14/4/2008 2:00:00 PM
Accepted
Ent
1.97355
0
*****
*****
CurrBarTm :14/4/2008 2:00:00 PM
Working
Ent
1.97355
0
*****
*****
CurrBarTm :14/4/2008 2:01:00 PM
PendingCancel
Ent
1.97355
0
*****
*****
CurrBarTm :14/4/2008 2:01:00 PM
Cancelled
Ent
1.97355
0
*****


Regards,
Toyogo

NinjaTrader_Dierk
04-23-2008, 11:34 PM
Please make sure you understand how orders are managed in NinjaScript: http://www.ninjatrader-support.com/HelpGuideV6/Overview36.html

Orders that automatically expire (cancel) at the end of a bar unless re-submitted

toyogo00
04-24-2008, 03:52 AM
Hi Dierk and Ray,

I would like to express my greatest thanks to both of you. Without very much programming knowledge (more than 10yrs ago), I managed to do the first customized strategy with your help.

Moreover, your service and response is so fast and effective that no other vendors near it. I am sure Ninja Trader will become one of the top platform in the near future.

I will definately support it and recommend to other traders....

Regards,
Toyogo

NinjaTrader_Ray
04-24-2008, 07:04 AM
Thanks for the compliment!