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
Cannot flat the account position after restart Strategy
Collapse
X
-
Hello localappleseed,
After my Strategy is re-started, previous pending ExitLongLimit() is no longer resumed by itself. So I don't have pending ExitLongLimit(). You are saying I could submit a ExitLong() immediately? That's what I did in the sample code.
After my Strategy is re-started, previous pending ExitLongLimit() is no longer resumed by itself. So I don't have pending ExitLongLimit(). You are saying I could submit a ExitLong() immediately? That's what I did in the sample code.
A couple of more questions:
1) Can I use EnterShortLimit() to sell my existing 100 share of IBM in account after Strategy starts? This may flat my account.
2) Is there a way to submit a virtual order and also virtually executed? This can also help me to sync my account.
I look forward to being of further assistance.
Leave a comment:
-
Jesse's comments: If you have the exit limit order open while the strategy is running and want to flatten it, you could cancel the limit order and then submit an exit order to close it immediately.
After my Strategy is re-started, previous pending ExitLongLimit() is no longer resumed by itself. So I don't have pending ExitLongLimit(). You are saying I could submit a ExitLong() immediately? That's what I did in the sample code.
A couple of more questions:
1) Can I use EnterShortLimit() to sell my existing 100 share of IBM in account after Strategy starts? This may flat my account.
2) Is there a way to submit a virtual order and also virtually executed? This can also help me to sync my account.
Thanks
Leave a comment:
-
Hello
Do you mean my call ExitLongLimit() was called too soon before a match was found?
Is there a way to find the match using my own code, or confirm a match is found?
Currently default "Wait Until Flat" is used, but not working as I expected. Per definition "If the Strategy Position is not flat, the strategy will place all trades in a virtual sense until the Strategy Position reaches or crosses a flat state", I am not sure how Strategy is doing this in Virtual, is there a way to Print something to confirm what it is doing?
I use Strategy to buy 100 shares of IBM stocks, as soon as stocks are bought, the Strategy will use ExitLongLimit() to send an exit order which can survive some time like 1-100 minutes. I try to flat my account Using my strategy if Strategy is re-started during ExitLongLimit() is pending.
I look forward to being of further assistance.
Leave a comment:
-
Hi, Jesse,
Thanks for your help on this. Further questions as follows:
You mentioned "What you have shown would not work because the exit is called immediately and won't match any open position".
Do you mean my call ExitLongLimit() was called too soon before a match was found?
Is there a way to find the match using my own code, or confirm a match is found?
Currently default "Wait Until Flat" is used, but not working as I expected. Per definition "If the Strategy Position is not flat, the strategy will place all trades in a virtual sense until the Strategy Position reaches or crosses a flat state", I am not sure how Strategy is doing this in Virtual, is there a way to Print something to confirm what it is doing?
Here is a bit of my strategy background:
I use Strategy to buy 100 shares of IBM stocks, as soon as stocks are bought, the Strategy will use ExitLongLimit() to send an exit order which can survive some time like 1-100 minutes. I try to flat my account Using my strategy if Strategy is re-started during ExitLongLimit() is pending.
Thanks.
Leave a comment:
-
Hello localappleseed,
The strategy would have had to entered the original order as it did in the first test to resume the same position, once it did that it could work in realtime to exit that position using the exit order you have. What you have shown would not work because the exit is called immediately and won't match any open position.
This will also relate to your strategies selected start behavior. https://ninjatrader.com/support/help...hlightsub=sync
You could likely use Wait until flat, synchronize account if the intent was to start flat, that will compare the account position and if not flat will submit orders to flatten the account. That would remove the need for your exit condition and that logic, you would instead just have normal exit logic if you plan to exit a position at some point.
I look forward to being of further assistance.Last edited by NinjaTrader_Jesse; 09-22-2020, 07:46 AM.
Leave a comment:
-
Cannot flat the account position after restart Strategy
I am testing if my code can flat my bought stock after restarting Strategy. Here are the steps, but ExitLong() couldn't successfully work:
1) run the following ode, wait long enough to let EnterLongLimit() bought 100 shares of stock IBM.
2) stop Strategy, and restart Strategy
3) ExitLong() doesn't work.
Can you help to point out what I may have done wrong? Thanks.
need_flat = first_time = true; // initial value
protected override void OnBarUpdate()
{
if (need_flat)
{
Order myExit = ExitLong(); // being called once, 1st time to run Strategy doesn't do anything. I expect it do the job during the 2nd time to run
Print (" After () = = " + myExit); // it prints nothing for myExit after re-start Strategy.
need_flat = false;
}
if (first_time)
{
myEntry = EnterLongLimit(0, true, 100, GetCurrentBid() - 0.02, "MyBUY"); // this is called only once, wait until it is executed, so there are 100 bought IBM stocks in account.
first_time = false;
need_flat = false;
}
}Last edited by localappleseed; 09-21-2020, 09:14 PM.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by LawrenHom, Today, 10:45 PM
|
0 responses
3 views
0 likes
|
Last Post
by LawrenHom
Today, 10:45 PM
|
||
Started by love2code2trade, Yesterday, 01:45 PM
|
4 responses
28 views
0 likes
|
Last Post Today, 10:31 PM | ||
Started by funk10101, Today, 09:43 PM
|
0 responses
7 views
0 likes
|
Last Post
by funk10101
Today, 09:43 PM
|
||
Started by pkefal, 04-11-2024, 07:39 AM
|
11 responses
37 views
0 likes
|
Last Post
by jeronymite
Today, 09:37 PM
|
||
Started by bill2023, Yesterday, 08:51 AM
|
8 responses
44 views
0 likes
|
Last Post
by bill2023
Today, 09:27 PM
|
Leave a comment: