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 10-24-2008, 03:13 AM   #1
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default Set Stop Loss with limit price

Hallo.
Can I use the Set method to place StopLoss with limit price or the only way is ExitLongStopLimit()???

Czarek
Czarek is offline  
Reply With Quote
Old 10-24-2008, 08:31 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You will need to use ExitLongStopLimit().
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-24-2008, 01:30 PM   #3
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default

I try use this method but the strategy cancell my order on the next bar.
I use OnExecution(IExecution execution).
My order syntax is: stopOrderLong1 = ExitLongStopLimit(execution.Order.Filled,firstEntr yLong - stop ,firstEntryLong - stop, "MyStopLong1", "MyEntryLong1");
Cancelation note:
20/9/2007 1:55:00 Cancelled expired order: BarsInProgress=0: Order='NT-00365/Back101' Name='MyStopLong1' State=Working Instrument='MHI 10-08' Action=Sell Limit price=26040 Stop price=26040 Quantity=0 Strategy='MHIAVGIOrder' Type=StopLimit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='df9f56e93a604018a468f9c560736a25' Gtd='1/12/2099 0:00:00'

What could be possiblem reason that strategy cancell my stop order on the next bar?


Rgsd
Czarek
Czarek is offline  
Reply With Quote
Old 10-24-2008, 01:37 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

The reason is here in your printout. "Cancelled expired order". You need to resubmit this order every single OnBarUpdate() event or else it will expire and auto cancel. Alternatively you can use liveUntilCancelled = true, but then to cancel it you will have to manually call CancelOrder().
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-24-2008, 01:45 PM   #5
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default

is that mean that I should change the method from OnExecution(IExecution execution) to OnBarUpdate() ??
Czarek is offline  
Reply With Quote
Old 10-24-2008, 01:57 PM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

I would recommend you just use liveUntilCancelled = true. Submit in OnExecution and then cancel if you don't want this order anymore later.
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-26-2008, 11:22 PM   #7
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default

Hallo.
When I place ExitLongStopLimit() sometimes order price hi the gap between the bars and is never filled. It could bring big losts.
Is the possible to place 2 stop orders for same position?? One ExitLongStopLimit() and the market order with bigger offset??

Rgds
Czarek.
Czarek is offline  
Reply With Quote
Old 10-27-2008, 08:12 AM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Czarek,

You can run into problems placing two orders like that. If the price spikes and hits both stops what happens then? Will both your stops try to fill? That will leave you with a short position. Instead what you may want to do is monitor your first stop and resubmit with adjustments if some weird gapping happens.
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-31-2008, 06:49 AM   #9
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default

Hallo.
If my first stop ExitLongStopLimit() hit the gap I would like to cancell it and place ExitLongStop with higher stop price and I would like to sure this time stop order will be executed immidiately that's why I want to place market order.
I think I can do do it if I be able too determinate current price than check that is higher than stop price and check that ExitLongStopLimit() is not filled. I think I can monitore stopLimit by StopLoss1 == execution.Order.Token but I do not know to check the current price for comarision to the stop price??
Czarek is offline  
Reply With Quote
Old 10-31-2008, 08:15 AM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You can check price like how you normally would do it. Close[0]. You can check your IOrder object for the stop and the limit prices of your orders.
http://www.ninjatrader-support.com/H...V6/IOrder.html

Ex:
Code:
if (myStopOrder != null && Close[0] > myStopOrder.StopPrice)
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-05-2008, 12:19 AM   #11
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default

HI.
I have 2 questions.
1. This is my entry order code:
Code:
if  (Close[1] < Close[0]
       && entryOrderLong2 == null)
    
   {
       limitPrice = Close[0]; 
    entryOrderLong2 = EnterLongLimit(positionsize, limitPrice-priceBack*TickSize,"MyEntryLong2");
      }
if the order (EnterLongLimit) hit he gap, strategy keep this order until next bar close time, than the order is cancelled and if the market going in good direction is placed again and if hit gap again strategy keep it until bar close and cancell again than wait one more bar and place again. Of course each order is placed with adjustment. The problem is that strategy keep order one bar and cancell for the next bar. So one bar order is valid one cancelled.
I would like strategy only amend the order price and keep this order all time.
The solution I found is cancell && entryOrderLong2 == null but I do not know if strategy will work properly without this code??
Can you find for me better solution??
My strategy is based on your sampel: Sample OnOrderUpdate.

2. What could be the possible reason of such log:5/11/2008 0:31:33 Strategy Error on calling the 'OnExecution' method for strategy 'EUROAVGLimitIOrder2stopBreakeven': Object reference not set to an instance of an object.

Rgds
Czarek.
Czarek is offline  
Reply With Quote
Old 11-05-2008, 08:12 AM   #12
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Czarek,

1. I am not sure exactly what you mean, but remember that you need to resubmit limit and stop orders on every single bar to keep it alive if you want it not to be automatically cancelled. Please try the liveUntilCancelled = true parameter and then use CancelOrder() when you want to cancel it.

2. Please see this tip: http://www.ninjatrader-support2.com/...ead.php?t=4226
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-06-2008, 12:52 PM   #13
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default

Josh.
I up date code to keep liveUntilCancelled = true parameter and keep odrer alive and order is keep all time but if price hit the gap is not updated on each bar close (price is all time same not amended in each bar close price)
if (Close[1] < Close[0]
&& entryOrderLong2 == null)

{
limitPrice = Close[0];
entryOrderLong2 = EnterLongLimit(0, true,positionsize, limitPrice-priceBack*TickSize,"MyEntryLong2");
}
How update order price on each bar close???
Rgds.
Czarek
Last edited by Czarek; 11-06-2008 at 12:55 PM.
Czarek is offline  
Reply With Quote
Old 11-06-2008, 12:57 PM   #14
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

If you want to update price you will need to resubmit the order. If you are going to resubmit your order on every bar you might as well leave liveUntilCancelled as false and then just keep resubmitting at either the same price or a new price.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-07-2008, 12:52 AM   #15
Czarek
Senior Member
 
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
Default

Josh.
I have tested 3 codes combination, only one works but I'm not sure if it is correct solution.
My strategy is based on sample shown here: http://www.ninjatrader-support2.com/...ead.php?t=3222
In this sample entryOrderLong1 == null is added to entry conditions.

General problem is: how to place EnterLongLimit() and amend this order on each bar close if price hit the gap.

1.
Code:
if ( maxClose < Close[0]
                && Open[0] < Close[0]
                && maxOpen < Close[0]
                && entryOrderLong1 == null
                && Position.MarketPosition == MarketPosition.Flat)
       {
        limitPrice = Close[0];
    entryOrderLong1 = EnterLongLimit(0,true,positionsize, limitPrice-priceBack*TickSize,"MyEntryLong1");
With liveUntilCancelled=true strategy place order and keep it alive with same price. Do not update price on each bar close.

2.
Code:
if ( maxClose < Close[0]
                && Open[0] < Close[0]
                && maxOpen < Close[0]
                && entryOrderLong1 == null
                && Position.MarketPosition == MarketPosition.Flat)
       {
        limitPrice = Close[0];
    entryOrderLong1 = EnterLongLimit(0,false,positionsize, limitPrice-priceBack*TickSize,"MyEntryLong1");
With liveUntilCancelled=false strategy place order with adjustment but every second bar. So one bar keep order alive, keep canceled on second bar, and place on third bar etc..
Better but stiill not good.

3.
Code:
if ( maxClose < Close[0]
                && Open[0] < Close[0]
                && maxOpen < Close[0]
 
                && Position.MarketPosition == MarketPosition.Flat)
       {
        limitPrice = Close[0];
    entryOrderLong1 = EnterLongLimit(0,false,positionsize, limitPrice-priceBack*TickSize,"MyEntryLong1");
With liveUntilCancelled=false and if snipped: && entryOrderLong1 == null, is removed, strategy place order on the each bar close with adjustment. This solution is OK.
But I' not sure if snipped: entryOrderLong1 == null, is removed, strategy will work properly?????
I'm arfraid that it could be reason of some errors.

Please advise me if I can freely remove if snipped: && entryOrderLong1 == null or show me snipped whih resolve my problem in correct way.

Rgds
Wesley
Czarek 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Next day open price lover than stop loss. Czarek Strategy Development 7 06-13-2011 05:39 AM
Stop limit orders and price freezes amiindew Miscellaneous Support 9 03-29-2009 05:19 AM
Inputting stop loss, profit target and limit prices. Scooter1 Miscellaneous Support 11 10-09-2008 10:37 AM
how to get current stop/limit/last executed price z32000 General Programming 1 11-29-2007 12:57 AM
Strategy: Modifying the price of stop loss and profit target orders NinjaTrader_Josh Reference Samples 0 09-06-2007 12:46 PM


All times are GMT -6. The time now is 06:02 PM.