Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with exit orders generating an extra one

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • linkcou
    replied
    Hi Jesse,
    Seems to be a glitch or something but now it's working well.
    Thanks a lot for your support, it's been really helpful
    Best,

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello linkcou,

    Yes if you want to add the short side you would need similar logic.

    From the image I cant tell when that print is from but at the time the print was made it was 20 bars from the last exit. To find out which bar that is associated with you would need to print out the bar time along with those details.

    Leave a comment:


  • linkcou
    replied
    Hi Jesse, the strategy works really well!! thanks! However, there is still something that i don't understand. See below the context:

    I have a condition to enter in a new position only if 1 bar has passed from the last Exit limit/stop. I added the condition (see screenshot below). However, when i track this number i realized that the "ExitStopLimit" is not calculated correctly.
    For instance, see below 2nd screenshot that shows that the last ExitStopLong happened 7 bars ago but when i print the BarsSinceExitExecution it shows 20 bars. Any idea why?

    Click image for larger version

Name:	image.png
Views:	214
Size:	3.4 KB
ID:	1274665
    Click image for larger version

Name:	image.png
Views:	200
Size:	201.2 KB
ID:	1274666

    Leave a comment:


  • linkcou
    replied
    Hello Jesse, Thanks!

    Yes, indeed i have the OnExecutionUpdate to create the stoploss order. I added the "ExitLimitL" order in the OnExecutionUpdate + update the OnBarUpdate.

    Quick question: if i want to do the same in the short side, i should just replicate, correct?

    See below the code updated:

    ONEXECUTIONUPDATE:
    Click image for larger version

Name:	image.png
Views:	200
Size:	33.3 KB
ID:	1274543
    ONBARUPDATE:
    Click image for larger version

Name:	image.png
Views:	190
Size:	18.7 KB
ID:	1274544

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello linkcou,

    Yes that will change when it gets submitted as well if that is the only time you are submitting the order. I see that you have an entryOrder variable, if you have OnExecutionUpdate in your script that would be a good location to initially submit the order and then later from OnBarUpdate you can issue updates for each bar. I would suggest to do like the sample in the following link which submits the orders in OnExecutionUpdate based on the entry fill so its immediately protected and then updates the order later from OnBarUpdate.



    This sample does a breakeven in OnBarUpdate, you would replace that with your condition to update the order price on each first tick of bar.

    Leave a comment:


  • linkcou
    replied
    Thanks Jesse! Quick follow-up: will that not have an impact the moment the exit limit is submitted? In most of the cases i enter and exit in the same bar so i want to prevent the exit limit to be created 1 bar after the entry order

    Below the new code. Does this work?
    Click image for larger version

Name:	image.png
Views:	194
Size:	31.1 KB
ID:	1274538

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello linkcou,

    If you need to update the price then adding the bool will prevent that condition from doing that. Rather than adding a bool you should likely add a condition checking for IsFirstTickOfBar so that order can be updated once per bar. That will allow the position to update once the order fills so that it will not submit a new order at the same time. You would still want to use live until cancelled in that case so the order can remain active when you are not calling it on each tick.



    Leave a comment:


  • linkcou
    replied
    Hi Jesse,
    thanks for the tip. Actually I need the limit order to be updated in every bar with a new limit level.

    Do you still think it's better to add that? What is the major difference between the 2 options?

    Thanks!

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello linkcou,

    Yes that looks correct, that should prevent the condition from becoming true more than once. The only other note here is that you likely want to change that order to being live until cancelled so it does not become expired similar to how your entry order is coded.


    ExitLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName, string fromEntrySignal)

    Leave a comment:


  • linkcou
    replied
    mmm i think it makes sense, thanks! Yes, indeed i am running this OnEachTick.

    Below the piece of code with the entry condition + exit condition with the new boolean "AvoidDoubleExit". Is this what you meant?
    Click image for larger version

Name:	image.png
Views:	190
Size:	29.1 KB
ID:	1274529

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello linkcou,

    From the timestamp it looks like the orders were submitted at almost the same time, are you running the script OnEachTick? If so you may need to implement a bool variable in your condition to make sure it only happens once. In the condition check if a bool is false. In the action when you submit the order set the bool to true. You could reset the variable in the entry condition so the target is ready to submit once each time the entry happens.

    Leave a comment:


  • linkcou
    started a topic Problem with exit orders generating an extra one

    Problem with exit orders generating an extra one

    Hi team,

    I have a strategy that enter with a limit order and then exit either with another limit order or by stoploss.

    The orders are generated correctly but when the order exit with the limit order and cancels the stop order, somehow it creates an additional exit limit order that makes me enter again in the market (which i dont want)..

    I dont know what i am doing wrong here. Could someone help with this?

    I am adding a screenshot that shows the orders generated where you can see that there are 2 "ExitLimitLong". I would like to avoid the creation of the 2nd one.Click image for larger version

Name:	image.png
Views:	215
Size:	21.3 KB
ID:	1274524
    Additionally adding the piece of code where I call the exitlimit order in the "OnBarUpdate()":
    Click image for larger version

Name:	image.png
Views:	198
Size:	7.9 KB
ID:	1274525

    Thank you in advance!​

Latest Posts

Collapse

Topics Statistics Last Post
Started by Pointtoni, Yesterday, 11:41 PM
3 responses
24 views
0 likes
Last Post jenacie.com  
Started by DayTradingDEMON, Yesterday, 02:10 PM
5 responses
29 views
0 likes
Last Post DayTradingDEMON  
Started by Nate G, 03-17-2025, 02:53 PM
4 responses
59 views
1 like
Last Post timko
by timko
 
Started by several, 03-18-2025, 03:53 AM
11 responses
175 views
1 like
Last Post timko
by timko
 
Started by Amelie4262, Today, 10:45 AM
0 responses
10 views
0 likes
Last Post Amelie4262  
Working...
X