NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 08-11-2007, 10:39 AM   #1
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default EnterLongStop

Hi,

I am having difficulties in developing a strategy (a simple one) which launch an order long stop, more specifically, I am executing

EnterLongStop in the updateOnBar() method, and the order is launched in the control center, pending in the accept Mode and after a minute or so, it goes in Cancelled mode. I searched in the log and I found that the order was logged as buy Limit !!!

if I launch an order manually from an open chart in the GUI, then the order is taken as a buy stop, so I think this is a bug problem.

Please help me,
Best regards
flaviufechete is offline  
Reply With Quote
Old 08-11-2007, 10:41 AM   #2
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

OOps,

I forgot to mention that I am connected to the Simulated Data Feed so it is possible that if this is a bug of your framework, it might have to deal with this, I didn't try my strategy with real data market, but since the manual order launch is working on simulated data feed with the sim account, I think it should work from strategy deployment also.

Best regards.
flaviufechete is offline  
Reply With Quote
Old 08-11-2007, 11:01 PM   #3
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please provide a simple-as-possible scenario (including strategy) in order to reproduce the problem.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-12-2007, 03:20 AM   #4
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

protected override void OnBarUpdate()
{
if (ToTime(Time[0]) == ToTime(DateTimeHour, DateTimeMinute, DateTimeSecond)) {
Print("current value of instrument " + Instrument.ToString() + " is " + High[0].ToString());
double val = High[0] + 7 * 0.0001;
Print("buy long stop at " + val);
EnterLongStop(High[0] + 7 * 0.0001, "signalLongStop");
SetProfitTarget("signalLongStop", CalculationMode.Price, High[0] + 27 * 0.0001);
SetStopLoss("signalLongStop", CalculationMode.Price, Low[0], false);
}
}



I've noticed that sometimes work, but most of the time it says oredr pending and in the end it tells me that order has been cancelled.

DateTimeHour, DateTimeMinute, DateTimeSecond are set as static variables with the timestamp of a future closing bar.
I work with this strategy on simulated feed with the sim account and on a currency. In the Initialize method I have only CalculateOnCloseBar = true

I don't understand why the order gets cancelled.

Best regards.
flaviufechete is offline  
Reply With Quote
Old 08-12-2007, 04:48 AM   #5
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please consult the logs: there likely is logged the cause of trouble. Since you likely are testing your strategy on the sim feed (so on "realtime" data and not as backtest on historical data), I would speculate that you do not have set a starting price for the tested instrument for the sim feed: http://www.ninjatrader-support.com/H...struments.html
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-12-2007, 05:02 AM   #6
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Based on your speculation I checked the Instrument Manager and it provides for my currency a Seem Feed Start Price of 1.00

and anyway I am checking the bars always on the chart and when the order is submitted, a cross tagged with the stop loss and take profit is displayed and a voice is telling me that order is pending, the cross is places above my current High bar value (because it is an Enter Long Stop order), and a few seconds later the same voice is telling me that order is cancelled.

Here it is my last order in the log :

8/12/2007 1:56:01 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=Cancelled Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
8/12/2007 1:56:00 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=PendingCancel Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
8/12/2007 1:55:01 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=Accepted Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
8/12/2007 1:55:00 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=PendingSubmit Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
8/12/2007 1:52:26 PM,Strategy,Starting NinjaScript strategy 'TestEnterLongStop/68a60bb13e0a4391bd653b71d676912e' : On starting a real-time strategy - SubmitLive,
flaviufechete is offline  
Reply With Quote
Old 08-12-2007, 05:05 AM   #7
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

NT cancels out orders as they are not "confirmed" by the next bar. Since you have a time base filter in place the order just could get canceled out on next bar after your filter. You will see that as you set TraceOrders=True (please consults the docs).
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-12-2007, 05:42 AM   #8
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

This is very strange behaviour from my point of view <NT cancels out orders as they are not "confirmed" by the next bar>

Why is that my logic works with a EnterLong() order in a time filter frame and not with an EnterLongStop() ?


Why does an order get cancelled if I don't say so ? in the logic of onBarUpdate() which is just a callback triggered on a closing event bar. It should do just that, trigger the event not cancel my orders if I am not specifying this in the logic of the method.

And in my method I am saying that at some specific moment in time execute an order and carry on with that order. If I am giving up for the time filter then the logic of onBarUpdate will execute an order at each closing bar event.
flaviufechete is offline  
Reply With Quote
Old 08-12-2007, 05:45 AM   #9
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> This is very strange behaviour from my point of view <NT cancels out orders as they are not "confirmed" by the next bar
This by no means is strange behavior. Most retail backtesting products like e.g. TradeStation operate the same way.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-12-2007, 07:43 AM   #10
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok, but still,

Why is that my logic works with a EnterLong() order in a time filter frame and not with an EnterLongStop() ?
flaviufechete is offline  
Reply With Quote
Old 08-12-2007, 11:35 PM   #11
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Sorry, not sure I follow.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-13-2007, 02:00 AM   #12
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok, I will try to be very explicit, hope I'll make myself understood.

I have this following code in onBarUpdate

protected override void OnBarUpdate()
{
if (ToTime(Time[0]) == ToTime(09, 00, 00)) {
EnterLong(1, "signalLongStop");
SetProfitTarget("signalLongStop", CalculationMode.Price, High[0] + 27 * 0.0001);
SetStopLoss("signalLongStop", CalculationMode.Price, Low[0], false);
}
}

and I have this time filter which says that when it is 9:00 AM it will submit with NT a long order for market price, ok ? if I deploy the strategy, it works, it launches a stop loss and a take profit for this long market price order.

OK, now my problem is that the same code doesn't work for EnterLongStop() or EnterShortStop(), and I don't understand why it is cancelled on the next bar close, because it shouldn't. it doesn't make any sense, and I would like to ask you if this is not the way to do it, HOW CAN I PUT AN ENTERLONGSTOP() order on the NT platform when I want that order at some specific time. (if this is not the way to do it, the docs are not clear about this, I spent hours looking and found nothing)

Thanks.
flaviufechete is offline  
Reply With Quote
Old 08-13-2007, 02:05 AM   #13
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

As pointed out below your code will not work, since any pending order will be cleared out next bar if the signal is not confirmed by the previous bar processed.

The reason your market order below works is, that it got filled before the "cancel if signal is not confirmed" logic is triggered. As soon as you place a limit or stop(limit) order is might not get filled immediately by then would be canceled out due to the "cancel if signal is not confirmed" logic.

-> you need to call EnterLongStop on every OnBarUpdate call as loong as your entry condition is true and not only once at 09:00:00
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-13-2007, 02:18 AM   #14
flaviufechete
Junior Member
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok, I understand now, I will try to adapt the code to fit the requirements for enterlongstop(),

thanks
flaviufechete is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:18 PM.