I have a problem with my strategy StopLoss. I have 12 entries on 4 different values and 3 target values and 3 stop values. I use LimitOrders. The problem occurs if Entry and Stop are on the same bar then my Stop order doesnt work. As you can see entries SellZero1 and SellOne1 get stopped on defined value. SellTwo1 and SellThree1 entry signals that should also be stopped out on the same value are skiped becuse they are opened on the same bar as stoploss is reached. Can you please help me with the solution how to make this work.
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
Limit entry and limit stop on the same bar
Collapse
X
-
Limit entry and limit stop on the same bar
Hi,
I have a problem with my strategy StopLoss. I have 12 entries on 4 different values and 3 target values and 3 stop values. I use LimitOrders. The problem occurs if Entry and Stop are on the same bar then my Stop order doesnt work. As you can see entries SellZero1 and SellOne1 get stopped on defined value. SellTwo1 and SellThree1 entry signals that should also be stopped out on the same value are skiped becuse they are opened on the same bar as stoploss is reached. Can you please help me with the solution how to make this work.1 PhotoTags: None
-
Hello beluga123,
Thank you for your post.
What calculation mode are you using for your strategy? On Bar Close, On Price Change or On Each Tick?
It's a little difficult for me to determine what may be going on here from your screenshot. Would you be able to provide a sample of you code for the entries and the exits?
Also, are you running the strategy in real time, or is this a backtest?
Thanks in advance; I look forward to assisting you further.Kate W.NinjaTrader Customer Service
-
Hi,
Thanks for quick replay
Here are few more screen shots for my exit logic. I determine StopLong1=1 when my entry conditions are met and first order BuyZero1,2,3 are filed. My Stops are calculated based on ATR. If i set my Exits in Stops and Targets tab in Strategy builder then works fine and it detect my exit on same bar but if i set directly in Conditions and Actions then it doesnt work on same bar. I would set it in Stops and Targets tab but then my ATR calculation doesnt work properly. I use On Each Tick calculation. I run my strategy directly on chart so i guess on historical data.
Do you have any suggestions how to fix this. ATR calculated StopLoss in Stops and Targets tab would be perfect but i cant figure out how to set the ATR value that would work in Stops and Targets tab.
Thanks4 Photos
Comment
-
Hello baluga123,
Thank you for your reply.
First, I would expect that a strategy running real-time (live brokerage account, live market simulation, Market Replay etc...) will produce different results than the performance results generated during a backtest, such as the historical trades that appear prior to real time data on a chart.
Fills on Historical Data are determined based on 4 data points, the OHLC of a bar, since that is the only information that is known during a backtest and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.
On Historical Data, OnBarUpdate will only update On Bar Close. This is why your exits that are set directly in the Conditions and Actions aren't working on the same bar the position is entered - all these orders are being entered at the same time, so the position is not yet open when you're trying to close it.
The reason they do work from the Stops and Targets tab is because the stop and target are being placed as separate orders that aren't contingent on an existing position. ExitLong() for example will only fire if a Long position exists. The ones from the stops and targets tab are basically cancelling out your initial entry for the bar.
I would suggest trying the strategy with a calculate mode of OnEachTick or OnPrice change on Market Replay data using the Playback Connection to better see how it would function on real time data - I think you'll find that the behavior is different when you're not running it On Bar Close.
Your other options would all really involve unlocking the code, adding a secondary 1 tick data series, and submitting your orders to that series instead of the primary data series to allow for more granular data when on historical data.
Please let us know if we may be of further assistance to you.
Kate W.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by warreng86, 11-10-2020, 02:04 PM
|
4 responses
1,355 views
0 likes
|
Last Post
by mathewlo
Today, 09:18 PM
|
||
Started by Perr0Grande, Today, 08:16 PM
|
0 responses
2 views
0 likes
|
Last Post
by Perr0Grande
Today, 08:16 PM
|
||
Started by elderan, Today, 08:03 PM
|
0 responses
5 views
0 likes
|
Last Post
by elderan
Today, 08:03 PM
|
||
Started by algospoke, Today, 06:40 PM
|
0 responses
10 views
0 likes
|
Last Post
by algospoke
Today, 06:40 PM
|
||
Started by maybeimnotrader, Today, 05:46 PM
|
0 responses
12 views
0 likes
|
Last Post Today, 05:46 PM |
Comment