![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
Hallo.
Can I use the Set method to place StopLoss with limit price or the only way is ExitLongStopLimit()??? Czarek |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
You will need to use ExitLongStopLimit().
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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().
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
is that mean that I should change the method from OnExecution(IExecution execution) to OnBarUpdate() ??
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
I would recommend you just use liveUntilCancelled = true. Submit in OnExecution and then cancel if you don't want this order anymore later.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
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?? |
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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)
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
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");
}
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. |
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#14 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Jun 2008
Posts: 159
Thanks: 0
Thanked 0 times in 0 posts
|
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");
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");
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");
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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |