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
Understanding start behavior
Collapse
X
-
Understanding start behavior
Please help me to understand Start Behavior for a strategy. I currently have the behavior set to "Wait until flat, synchronize account". But I just activated a strategy, and on the chart it shows that there is an active short on the chart. I believe currently the strategy will wait until that trade finishes, and then it will start initiating trades once the strategy is flat. How can I get the strategy to activate a trade on the NEXT signal, without having it activate immediately based on the last signal?Tags: None
-
Hello Bionian,
The strategy will process historical data before real-time data.
Historical orders will appear on the chart.
https://ninjatrader.com/support/foru...442#post782442
With Wait until flat, if the strategy calculates a historical position open, it will wait until a virtual order closes the historical position before placing any real-time orders.
Once the strategy has become flat or crossed through flat, the strategy name will become green indicating the strategy is now sending real-time orders.
https://ninjatrader.com/support/foru...541#post811541
To prevent a strategy from processing any historical data use:
if (State == State.Historical)
return;
To exit a position on the last historical bar use:
if (State == State.Historical && CurrentBar == Count - 2)
{
if (Position.MarketPosition == MarketPosition.Long)
ExitLong();
if (Position.MarketPosition == MarketPosition.Short)
ExitShort();
}Chelsea B.NinjaTrader Customer Service
- Likes 1
-
Chelsea:
I inserted your code into the strategy. I don't necessarily want to prevent the strategy from processing historical data, but I do want to be able to apply the script and begin executing trades immediately, without waiting for the virtual order to close the historical position, when I see signs from price action that the market has temporarily converted into a sideways market. Can you tell me if I inserted the script properly? The strategy appear to still function, but I don't know if it will accurately begin generating signals on live data immediately.
OneMinSwingIndScalpCloseOnRevC345StartNow.zip
Thanks-
Rick
Comment
-
Hello Bionian,
Yes, at the top of OnBarUpdate(), this would cause any historical position to be exited on the last historical bar.
Are you finding that the strategy still has a virtual historical position (showing yellow on the Strategies tab of the Control Center) once real-time data is being received when you are testing?Chelsea B.NinjaTrader Customer Service
Comment
-
Yes Chelsea.
Since I have had an opportunity to test the strategy today, it appears that it is doing just want I wanted. I it is exiting any open positions, but still showing historical trades, so I can continue to monitor the effectiveness of the strategy. This will help me learn to program. I saved a copy of the strategy which is still available in Chart Builder, so I can continue to modify it. Then I can compare the two, before and after then copy and paste the new code into the strategy you see here.
Thanks for you help, as always. Hopefully before long I will be able to code them myself.
Rick
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHello Bionian,
Yes, at the top of OnBarUpdate(), this would cause any historical position to be exited on the last historical bar.
Are you finding that the strategy still has a virtual historical position (showing yellow on the Strategies tab of the Control Center) once real-time data is being received when you are testing?
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHello trader14,
Are you only enabling the strategy before the market opens?
If not, the historical position may not be flat if there is data process.
See below about resuming a strategy.
http://ninjatrader.com/support/forum...332#post499332
Comment
-
Hello trader14,
If you restart a strategy after the market is open, then even if it was flat when the market opened that is not going to prevent new orders from being placed after the market is open.
Are you trying to prevent all new orders after the market is open?
Resuming a strategy would require Immediately Submit. This is outlined in the forum post I have linked.Chelsea B.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHello trader14,
If you restart a strategy after the market is open, then even if it was flat when the market opened that is not going to prevent new orders from being placed after the market is open.
Are you trying to prevent all new orders after the market is open?
Resuming a strategy would require Immediately Submit. This is outlined in the forum post I have linked.
Comment
-
Hello trader14,
I'm not clear on how Exit on session close is involved.
The strategy is calculating a historical position with historical data every time it is enabled.
This includes historical data from the new session.
It sounds like you are wanting to disable a strategy and re-enable a strategy and have the position be resumed as described in the forum post I have linked. Is this not what you are wanting to do?Chelsea B.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHello trader14,
I'm not clear on how Exit on session close is involved.
The strategy is calculating a historical position with historical data every time it is enabled.
This includes historical data from the new session.
It sounds like you are wanting to disable a strategy and re-enable a strategy and have the position be resumed as described in the forum post I have linked. Is this not what you are wanting to do?
However, if I attempt to restart my strategy DURING THE 1 HOUR BREAK using "wait until flat" as I want to do to reboot/refresh my PC, I initially I expected the strategy to turn GREEN during the 1 hour close. I wrongly expected it to know that it should be in a flat state (as the strategy dictates all positions are exited just before market close) and be ready to trade at the open. However, I now know this isn't the case. When the my strategy is restarted during the close using the "wait until flat" start behavior, it ALWAYS enters a virtual position (turns and stays yellow) and does not realize that it really should be flat according to the strategy rules. This is a problem because now, my strategy won't trade the way it normally should had I been leaving it running as the above paragraph mentions. The only alternative is to use "immediately submit" but that doesn't work either because it violates my strategy rules but not waiting for a bar to fully close.
So, Ninjatrader doesn't have a start behavior that works my strategy. I can't reboot my PC during the close because neither "wait until flat" or "immediately submit" will allow my strategy to trade the way it should. The only alternative for me, is to start the strategy once and leave it running forever.
Comment
-
Hello trader14,
I may still not be understanding.
It still sounds like you want to disable and re-enable a strategy and have it resume the position (the strategy would start green not yellow).
Can you clarify further if this is not what you are wanting to do?
Yes, a strategy with wait until flat that starts with a historical position will ALWAYS wait until flat before it turns green.
Your strategy logic is what is creating the historical position.
When you mention: "The only alternative is to use "immediately submit" but that doesn't work either because it violates my strategy rules but not waiting for a bar to fully close."
I do not understand your meaning by 'not waiting for a bar to fully close'.
You can wait for a bar to fully close. You can do something before a bar fully closes. You can do either. What is the issue?
Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
147 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
5 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,282 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
Comment