Thank you
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
How to enter on CalculateOnBarClose=true but exit on false?
Collapse
X
-
Originally posted by relogical View PostCan someone please show me some code on how I can enter a trade on CalculateOnBarClose=true but exit on =false?
Thank you
ref: http://www.ninjatrader.com/support/f...ad.php?t=19387
-
Hello relogical,
Thank you for your post.
If you are going to use SetStopLoss() or if you plan to place an Exit(Long/Short)Limit() or Exit(Long/Short)StopLimit() or Exit(Long/Short)Stop() order, these will sit with the broker and will be filled anytime the price passes through the order price. If these are placed at the time of entry and are working with the broker, these will fill at any time and not just when a bar closes.
If, however, you are wanting to exit an order using a market order with Exit(Long/Short)() based on conditions for an exit, you will need to either use intra-bar granularity or have the script run with CalculateOnBarClose set to false.
To use intra-bar granularity add a secondary series to your script of one tick.
For example:
protected override void Initialize()
{
Add(PeriodType.Tick);
}
Then in your OnBarUpdate code use the primary data series to enter a trade and the secondary data series to exit the trade.
For example:
if (BarsInProgress == 0 // && Conditions to enter trade here)
{
EnterLong(0, 1, "entry")
}
if (BarsInProgress == 1 // && Conditions to exit trade here)
{
ExitLong(0, 1, "exit", "entry");
}
The second method would be to use CalculateOnBarClose as false and use FirstTickOfBar to determine when to enter a trade.
Below is a link to the help guide on FirstTickOfBar.
http://www.ninjatrader.com/support/h...ttickofbar.htm
Also, here is a link to a sample that does something like this.
http://www.ninjatrader.com/support/f...ad.php?t=19387Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by haas88, 03-21-2024, 02:22 AM
|
19 responses
220 views
0 likes
|
Last Post Today, 09:06 AM | ||
Started by ZeroKuhl, Yesterday, 04:31 PM
|
4 responses
28 views
0 likes
|
Last Post
by ZeroKuhl
Today, 08:57 AM
|
||
Started by cupir2, Yesterday, 07:44 PM
|
3 responses
21 views
0 likes
|
Last Post Today, 08:33 AM | ||
Started by reynoldsn, Yesterday, 07:26 PM
|
2 responses
15 views
0 likes
|
Last Post
by reynoldsn
Today, 08:32 AM
|
||
Started by MartinT, 05-17-2023, 06:00 AM
|
18 responses
173 views
0 likes
|
Last Post
by flybuzz
Today, 08:20 AM
|
Comment