Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Triggering orders to be submitted by addon via indicator

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

  • BartMan
    replied
    Originally posted by Kylemcfar57x View Post
    well i may have been a bit too optimistic, i finished on Saturday so the market was closed, long story short it works flawlessly on market reply, but live i get an occasional double entry on reversal, so i figured it was flipping too fast before the ui thread returned that the pos was not long yet so it entered again, i tried to use await but every time i try pass orderers through the thread dispatcher it just spams orders instead of doing one even without the dispatcher just an async method with await does the same thing, even tried executing the code to simulate clicks on chart trader for entry same result not sure what im messing up i was never good with threading, commented stuff is what i tried before, it all executes but i think its not letting market position get to the argument, thats also passed through a thread, the instrument to flatten data is also passed through a thread but held in a list so i dont think its that, it runs as expected in market replay in this form but i cant get it to work using await Click image for larger version Name:	image.png Views:	0 Size:	23.2 KB ID:	1233222​
    instead of

    if (marketPosition != 1)
    Try
    if ( Position.MarketPosition ==MarketPosition.Flat )​

    Leave a comment:


  • Kylemcfar57x
    replied
    yea i was beginning to think that was the case, i was just trying to think of a condition that could work for my strat, i found this post about current bar, im going to explore that option, thanks for your help https://ninjatrader.com/support/foru...1Ig0P9Tuc00Oe0

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Kylemcfar57x,

    It sounds like the condition to submit the order is happening multiple times if you are getting multiple fills. You would have to look at the entry logic, that has nothing to do with the account events.

    A general flow for a complete Trade (entry + exit) would be that you have a condition for example in OnBarUpdate and it submits a single order one time. This logic needs to happen only 1 time and then stop happening so no more orders are submitted. This condition won't know that the position is not flat until later so you need to make your own way of ensuring this condition only happens 1 time to submit the order. Generally a condition like a Crossover or something that can only logically happen one time per bar could be used to control that. Depending on the configuration of your script you may need to add some extra complexity to the entry condition or use your own variables to control when it is allowed.

    Once the entry condition is satisfied it will submit the order which then gets filled. When the fill happens the account events like ExecutionUpdate trigger. That execution event can be used to then submit targets for that entry because we know the entry was filled at that point. Once your target fills and the strategy has completed the trade you could allow the entry condition to happen again at that point.





    Leave a comment:


  • Kylemcfar57x
    replied
    ok i spent the past few days reworking order handling i made methods to separate each action and checking filled ect, but my issue is that even on the initial entry from flat, im getting multiple fills, on a signal, the events dont help in this situation since they come in until after, unless im missing something, i tried to use a flag so it would only execute once but that doesn't seem to be working either

    im currently at a loss as to get my order to fill only once, on market reply it works flawlessly but on sim i always get multiple fills, i would greatly appreciate any suggestions

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Kylemcfar57x,

    No those are available on the account object as well. As a learning exercise to help know what is available I would suggest do do the following:
    1. Open the help guide and use the left side toolbar to drill down to the following section: NinjaScript -> Language reference -> Addon -> Account
    2. Then look at the left side bar at the various topics surrounding Account. You can see the different collections/events for the account and each page will have samples.
    You can always reference the main Account help guide page for an example of finding an account and it also includes the order events: https://ninjatrader.com/support/help...ount_class.htm

    You likely can accomplish your goal fully from the indicator, the indicator class has all of the same ability as the addon class will in respect to using the Account.

    Leave a comment:


  • Kylemcfar57x
    replied
    those are only available through strategy class right? i used all these janky workarounds to make it work as an indicator class, i might be able to keep it as an indicator, if i can access these events as an indicator. can you have shared methods between strat and indicator? i would need to do some major restructuring

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Kylemcfar57x,

    From the image it looks like you have problematic logic. You cannot check a position like that directly after calling an method such as Flatten, you would have to wait for the position update event which means the positions were flattened before running that market Position check code. That code likely needs to be removed from the BuyOrder method and placed into its own method being called from OnOrderUpdate/OnPositionUpdate/OnBarUpdate at a separate time.

    When working with normal NinjaScript strategies you have to wait at a minimum of 1 bar event before doing a position check so the position is updated. When working directly with the account you instead have to wait for the actual account events for whatever you are trying to do. For example submitting targets for an entry would be done in OnExecutionUpdate based on the entries filled event. If you are trying to reverse a position you would need to cancel any open orders and wait for confirmation they were cancelled, clean up those orders variables and then close the position and wait for its confirmation. Once the orders are canceled and the position is flat you can reset any associated logic before doing the entry for the reversal.

    You never need async/dispatching for NinjaScript based code. Using async and dispatchers is specific for UI related logic or cross threaded logic, your script wont run into that just by submitting orders and trying to do logic based on the position. You just need to re structure your code to listen to the account events to drive your logic. Adding dispatching or async for your logic or order events will take them out of the scripts context and do those changes at a random later time.

    I also see using await/Tasks and Delay there, you never want to use tasks or any kind of delay/waiting/while looping in a script to avoid locking it up. Pausing your codes execution in NinjaScript is not good for performance, you should always let the script execute its actions as fast as possible to avoid UI freezing.








    Leave a comment:


  • Kylemcfar57x
    replied
    well i may have been a bit too optimistic, i finished on Saturday so the market was closed, long story short it works flawlessly on market reply, but live i get an occasional double entry on reversal, so i figured it was flipping too fast before the ui thread returned that the pos was not long yet so it entered again, i tried to use await but every time i try pass orderers through the thread dispatcher it just spams orders instead of doing one even without the dispatcher just an async method with await does the same thing, even tried executing the code to simulate clicks on chart trader for entry same result not sure what im messing up i was never good with threading, commented stuff is what i tried before, it all executes but i think its not letting market position get to the argument, thats also passed through a thread, the instrument to flatten data is also passed through a thread but held in a list so i dont think its that, it runs as expected in market replay in this form but i cant get it to work using await Click image for larger version  Name:	image.png Views:	0 Size:	23.2 KB ID:	1233222
    Last edited by Kylemcfar57x; 01-30-2023, 01:58 AM.

    Leave a comment:


  • Kylemcfar57x
    replied
    You can ignore my previous responses i solved it everything is working great now and no exceptions, i tied the flatten method to gather the account id and put it in a list to be flattend, i was also able to eliminate the addon i used to pull the chart trader info by accessing the info through the thread dispatcher

    Leave a comment:


  • Kylemcfar57x
    replied
    Well i found a way to cancel the atms on reverse orders it works good, but im getting this exception, i didn't want to use flatten bc it closes all orders but i seen that you can add individual instruments to the list, i could use the click event in instrument to also add the current one to the list but since its been so long since ive coded im not sure how to remove it then seems like it could get janky, if im trading 2 instruments it could cancel the others, unless i could create a unique list for each instance of the indicator so its not shared idk...

    Click image for larger version

Name:	image.png
Views:	727
Size:	29.7 KB
ID:	1233063

    Leave a comment:


  • Kylemcfar57x
    replied
    ok new can of worms opened, the leftover brackets from the atm are not closed when position is reversed, i seen a post about get atm id and cancel that atm but it seems like thats strat only, or am i mistaken, i dont want to use flatten can i cancel the oco leftover from the atm before a new entry?Click image for larger version

Name:	image.png
Views:	741
Size:	90.0 KB
ID:	1233061

    Leave a comment:


  • Kylemcfar57x
    replied
    Ok it worked thankyou, i missed where string must say Entry
    Last edited by Kylemcfar57x; 01-27-2023, 06:43 PM.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Kylemcfar57x,

    In what you provided in post 1 you are submitting orders to an account using account.Submit. Instead of that you would create the order like shown in that help guide sample and use account.CreateOrder and StartAtmStrategy. Starting an ATM order vs a regular order are two different methods in the addon framework.

    Leave a comment:


  • Kylemcfar57x
    replied
    I'll try playing around with it maybe i was entering the parameters wrong, it will still work with sim or market replay right?

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Kylemcfar57x,

    Yes it would be the same way that you would do it from an addon, you can use StartAtmStrategy. https://ninjatrader.com/support/help...tmstrategy.htm

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
0 responses
647 views
0 likes
Last Post Geovanny Suaza  
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
0 responses
369 views
1 like
Last Post Geovanny Suaza  
Started by Mindset, 02-09-2026, 11:44 AM
0 responses
108 views
0 likes
Last Post Mindset
by Mindset
 
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
0 responses
572 views
1 like
Last Post Geovanny Suaza  
Started by RFrosty, 01-28-2026, 06:49 PM
0 responses
573 views
1 like
Last Post RFrosty
by RFrosty
 
Working...
X