Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Help with position handling
Collapse
X
-
Your right, thats script is totally incorrect.Originally posted by koganam View PostYou show both orders being filtered by the same BarsInProgress. It is hard to see how that is any different from having no bars filter.
I've been working on this all morning, and anyhow this thing looks impossible to do in the managed approach keeping CalculateOnBarClose = true;
I see 2 solutions:
1. moving to the advance order handling (IOrder), but unfortunately my skills are still poor, and I don't find a proper tutorial that explain how this works;
2. As you've mentioned in your past thread, use CalculateOnBarClose = false; but reading your threads bring me to 2 questions on the code below:
1. don't you think that the use of CalculateOnBarClose = false is risky, as it could generate more trades than in the case CalculateOnBarClose = true?Code:private bool _boolReverseOnOppositeSignal = false; CalculateOnBarClose = true. private void GoShort(string strEntryName) { if (this._boolReverseOnOppositeSignal) ExitLong(); EnterShortLimit(DefaultQuantity, Close[0], strEntryName); }
2. what exactly do I need boolean flag for? wouldn't i get the same by using the code without, like below:
Code:
Code:CalculateOnBarClose = false; private void GoShort(string strEntryName) { ExitLong(); EnterShortLimit(DefaultQuantity, Close[0], strEntryName); }
Comment
-
I got your point.Originally posted by koganamYou are reading more into my query than there is. The boolean flag that I was using in that code had a completely different purpose. My query was on why I could not exit by market and enter by limit on the same bar if COBC was true. With or without the boolean flag, that code was not viable.
IOW, you are assuming that I was attempting to solve the problem when I made the query of NT support. I was not: I wanted to know why the construct was not working. I was looking to isolate the problem when I made the query: not attempting to solve a problem that I had not at that time properly identified.
I simply gave you the thread as a reference so that you can see that the issue has been previously discussed, so that you would not spend time going over what was already known. The code in that thread is not a solution to the problem: it was merely a demonstartion of how the problem arose.
My understanding so far is that you can only exit by market and enter by limit on the same bar if COBC is set to false, the code below should work fine:
please correct me if wrongCode:protected override void OnBarUpdate() { //Enter long if (CrossAbove()) { ExitShort(); EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0])); }
Comment
-
1. Yes, it is, and one must take proper steps to programatically handle it. One runs the danger of being hopelessly whipsawed if one is not careful, or of being put into a trade mid-bar that turns out not to be a correct signal by the time that the bar closes.Originally posted by sburtt View PostYour right, thats script is totally incorrect.
I've been working on this all morning, and anyhow this thing looks impossible to do in the managed approach keeping CalculateOnBarClose = true;
I see 2 solutions:
1. moving to the advance order handling (IOrder), but unfortunately my skills are still poor, and I don't find a proper tutorial that explain how this works;
2. As you've mentioned in your past thread, use CalculateOnBarClose = false; but reading your threads bring me to 2 questions on the code below:
1. don't you think that the use of CalculateOnBarClose = false is risky, as it could generate more trades than in the case CalculateOnBarClose = true?Code:private bool _boolReverseOnOppositeSignal = false; CalculateOnBarClose = true. private void GoShort(string strEntryName) { if (this._boolReverseOnOppositeSignal) ExitLong(); EnterShortLimit(DefaultQuantity, Close[0], strEntryName); }
2. what exactly do I need boolean flag for? wouldn't i get the same by using the code without, like below:
Code:
Code:CalculateOnBarClose = false; private void GoShort(string strEntryName) { ExitLong(); EnterShortLimit(DefaultQuantity, Close[0], strEntryName); }
That having been said, in reality, in Stop&Reverse code, Mar****rders really are not as bad as they at first blush might look: in the aggregate, what you lose on one side, you gain on the other, and vice-versa. Then again, I do understand that you may prefer the solution that you are now exploring, separating the exit from the reversal entry, which is much more precise, and does not depend on statistically nulling out slippage.
2. You are reading more into my query than there is. The boolean flag that I was using in that code had a completely different purpose. My query was on why I could not exit by market and enter by limit on the same bar if COBC was true. With or without the boolean flag, that code was not viable.
IOW, you are assuming that I was attempting to solve the problem when I made the query of NT support. I was not: I wanted to know why the construct was not working. I was looking to isolate the problem when I made the query: not attempting to solve a problem that I had not at that time properly identified.
I simply gave you the thread as a reference so that you can see that the issue has been previously discussed, so that you would not spend time going over what was already known. The code in that thread is not a solution to the problem: it was merely a demonstration of how the problem arose.
Comment
-
Please read my amended response, and take care of the possibilities/dangers that I outlined, regarding whipsaws and invalid entries by close-of-bar.Originally posted by sburtt View PostI got your point.
My understanding so far is that you can only exit by market and enter by limit on the same bar if COBC is set to false, the code below should work fine:
please correct me if wrongCode:protected override void OnBarUpdate() { //Enter long if (CrossAbove()) { ExitShort(); EnterLongLimit(Close[0] - RngFrac * (High[0] - Low[0])); }
Comment
-
Thanks for your help so far. I really appreciated it.Originally posted by koganam View PostPlease read my amended response, and take care of the possibilities/dangers that I outlined, regarding whipsaws and invalid entries by close-of-bar.
De facto the indicator I use in my strategy takes as a reference the median point of each bar, rather than the close, this helps reduce noise and very rarely gives false signals, meaning i will try to go live with COBC = false and see how much this differs from my expectations.
again thanks
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
670 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
379 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
111 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
582 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment