Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
earliest event for querying account positions?
Collapse
X
-
earliest event for querying account positions?
In what event is the earliest place I can safely query the account positions to see what positions are open?Tags: None
-
Hello NinjaCustomer,
Thank you for the question.
Can you provide more details on the context of where you are wanting to check the position? Is this from an addon or another type of script?
The earliest you can execute code will depend on the type of script use in addition to what Account object we are referring to here.
If you mean the Addon account which you locate, the earliest you can access the Positions would be after finding the account and assigning it to a variable. The scope where that is used also matters. If this was a Strategy that could be used anywhere from State.SetDefaults and on really. If this is a custom addon, that really depends on the context of what you made, without details on where you are trying to execute this I would likely be unable to answer this question with any accuracy.
Please let me know if I may be of additional assistance.JesseNinjaTrader Customer Service
-
it is from an addon - I'm not sure what account object, just want to query positions on the current account.
Comment
-
Hello NinjaCustomer,
Thank you for your reply.
Have you at this point reviewed the addon samples that we have in the help guide surrounding accessing an account?:
Or the full addon sample you can import which is also in the help guide?:
Both of these samples demonstrate accessing an account however without more detail about your specific question I don't know if I could be of further assistance.
An addon by default has no account, you would need to implement an account picker if you are using a GUI add-on, or use the syntax from the first to find an account by its string name. In both situations, you have an account object which has sub-methods and collections. Here is another example using the string name for finding an account and accessing the positions from the account object:
In relation to your earlier question, how early this can be accessed depends on your addon. If its a GUI addon, you will likely want to try and replicate what is shown in the addon sample for its account picker. If you have some other type of non-gui addon or something that affects other windows you will need to review your logic to see where this may best fit in.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
here is my predicament
currently my addon does not loop positions.
instead it uses
OnPositionUpdate() however I have no idea what account that is.. I've been testing it only on a SIM account. I want to make it so that if I restart NT8 then I can check the existing positions. I want to do this at the earliest possible moment where this data would be available. Maybe on a SIM that is immediately? but I think on a live account you should wait until the account is connected? if I check it too early I assume it would just show no positions.
Comment
-
Hello NinjaCustomer,
Thank you for your reply.
however I have no idea what account that is
It sounds like you created something which has logic to get an account already because your observing OnPositionUpdate which requires an account to observe. This may be an account picker or the string example I previously provided which is getting the account in your script. You have not provided any information about your addon at this point so I am unsure what you may have coded so far. If you can provide more information about your addon and the syntax you used, that would be helpful as I am just guessing based on your description here.
I want to make it so that if I restart NT8 then I can check the existing positions
If you are trying to wait for a connection to check your account, you could review the addon section of the help guide about using connection information: https://ninjatrader.com/support/help...atusupdate.htm
Please let me know if I may be of further assistance.
JesseNinjaTrader Customer Service
Comment
-
yes you are right.. it searches for the SIM account and then adds the onPositionUpdate...
no windows are created..
well, I mean I don't need to wait for a connection if it will already be populated with the last known positions.. is that what will happen? if I check the positions before the connection is successful?
Comment
-
Hello NinjaCustomer,
I had mentioned the connection status because a live account would not be available if you are not connected or on a different connection than the connection is associated with. The positions collection will be available if you find the target account and access the positions. If you check for the live account before you are connected it is likely you would not find the account and not be able to check the positions.
Please let me know if I may be of further assistance.JesseNinjaTrader Customer Service
Comment
-
is it really necessary to -= OnConnectionStatusUpdate or
-= OnPositionUpdate? in OnCleanup() I'm not sure if it will be fired since I create no windows or tabs in my addon
I don't seem to have any Cleanup() to override
namespace NinjaTrader.NinjaScript.AddOns
{
public class MyAddon : NinjaTrader.NinjaScript.AddOnBase
Last edited by NinjaCustomer; 03-14-2019, 01:59 AM.
Comment
-
Hello NinjaCustomer,
Thank you for your reply.
Yes, you do need to unsubscribe from open event handlers. You haven't provided enough detail about your addon for me to point a direction here, you would need to provide more of a sample of where you are setting up the account in your addon.
If you don't have a window, where are you checking the account? Are you using OnWindowCreated in some way to do this?
However you have created your addon, you will need to implement some kind of cleanup to clean the events you use up. If you are using the addon in a basic way from OnWindowCreated, you can use the addons OnStateChange to handle the addons lifecycle and cleaning of objects.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
yes it was using OnWindowCreated, now I've moved that code to
OnConnectionStatusUpdate() (and use a flag so I don't execute my init code more than once) what state in OnStateChange should I use?
Comment
-
Hello NinjaCustomer,
For more information about OnStateChange please see the OnStateChange documentation: https://ninjatrader.com/support/help...=OnStateChange
State.Terminated would be when the addon terminates.
Please let me know if I may be of additional assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johnMoss, 03-04-2024, 01:53 PM
|
3 responses
46 views
0 likes
|
Last Post
by AndyM
Today, 06:13 PM
|
||
Started by algospoke, Today, 06:01 PM
|
0 responses
8 views
0 likes
|
Last Post
by algospoke
Today, 06:01 PM
|
||
Started by cre8able, Today, 05:53 PM
|
0 responses
8 views
0 likes
|
Last Post
by cre8able
Today, 05:53 PM
|
||
Started by Wessel, 03-23-2024, 02:37 PM
|
3 responses
24 views
0 likes
|
Last Post Today, 04:58 PM | ||
Started by martini, Yesterday, 04:45 PM
|
4 responses
32 views
0 likes
|
Last Post
by martini
Today, 04:48 PM
|
Comment