Would be helpful, if backtesting would show the same behaviour and produce those double exit orders as well...Anyway, Thx!!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Unlogical RT trading behaviour with IB
Collapse
X
-
Hello,
OK glad this resolved the issue.
What your most likely facing is a race condition.
Heres why.
You need at least one OnBarUpdate() to occur after you exit a position for the new position to be represented.
So what you where most likely having happen is that the
ExitLong() was called in the same OnBarUpdate()
This Exited for 8 Contracts.
Then in this same OnBarUpdate() you then also called EnterShort(). Which since one OnBarUpdate() hasnt passed and all the position variables are still not updated. EnterShort thinks your in a long position still even though ExitLong() has submitted its orders to the live servers and is still awaiting the position to be flat.
Therefor when you called EnterShort() It was also sending in the Exit order to sell 8 and then sending in order to then go short 4 contracts.
But since this takes time in a live situation this is the reason this is different vs sim vs live.
This is the reason for OnOrderUpdate(). This way you can wait for an exit long order to fill before submitting and EnterShort for example. If this was inside OnOrderUpdate() you would have been fine. However since this was inside OnBarUpdate the bar Updated before the order did and you ended with a double order.
Let me know if I can be of further assistance.
Comment
-
I am once back again with a question concerning the RT behaviour of my strategy.
The reason I post it here is that it happens only when OnBarUpdate is called in realtime (historical == false) and when a position is on.
The following error happens in OnBarUpdate: "Index was out of bounds.... " I have done quite a lot of searching in the forum, when this kind of error occurs and I think I have understood the problem. It happens when bars are referenced, which are at the moment of the call of OnBarUpdate() not available.
However in my piece of code - where the problem occurs (Print "2" is reached, while Print "3" is not reached) - I do not see that error:
Print("2");
// EXIT BLOCK
// LONG Exits
if (Position.MarketPosition == MarketPosition.Long && Signal == 0) ExitLong();
if (Position.MarketPosition == MarketPosition.Long) ExitLongStop(ExitStopPrice);
// SHORT Exit
if (Position.MarketPosition == MarketPosition.Short && Signal == 0) ExitShort();
if (Position.MarketPosition == MarketPosition.Short) ExitShortStop(ExitStopPrice);
// Check, whether position was stopped out
if ((Signal == 1) && (YD_Position == 1) && (Position.MarketPosition != MarketPosition.Long)) LONG_StoppedOut = true;
if ((Signal == -1) && (YD_Position == -1) && (Position.MarketPosition != MarketPosition.Short)) SHORT_StoppedOut = true;
Print("3");
Since I have no clue I definitely need your support once again, sorry for that!!
Thx, PeterLast edited by unter821; 02-10-2011, 03:17 PM.
Comment
-
Peter,
What was the complete error message you saw? It should provide more information to figure out where exactly in your code you are accessing an invalid index value.
Best bet to isolate this would be to use try-catch blocks around your code to figure out where exactly it is having issues. Put these all around your code segments so you can isolate which segment is causing the problem and slowly drill down to the exact line causing the problem. http://www.ninjatrader.com/support/f...ead.php?t=9825Josh P.NinjaTrader Customer Service
Comment
-
Josh,
The following error message is displayed: Error on calling 'OnBarUpdate' method for strategy 'MacroStrategy/40676dafabf540b6bc9fbebfc96d7b44': Der Index war außerhalb des Arraybereichs (=Index was out of bounds)
I have found out, that it happens in this code line:
if (Position.MarketPosition == MarketPosition.Long) ExitLongStop(ExitStopPrice);
I am using two different entries each with a unique signalname (but only one is active at one time). Could it be, that I have to use the parameter "fromEntrySignal" in the exit. I have actually no clue.....Last edited by unter821; 02-11-2011, 03:56 AM.
Comment
-
Peter, thanks for the reply - you should be able to use either overload, with no tagging to an entry it would apply to the full position then - is the error still coming when you try the below?
if (Position.MarketPosition == MarketPosition.Long) ExitLongStop(ExitStopPrice, "your entry signal name here');BertrandNinjaTrader Customer Service
Comment
-
Hello,
Are you sure this is the location of the error? As I would continue to look into this as I dont see why this would cause this error witht he information provided you should be fine. How did you narrow it down to here?
Please add in a few try() catch() blocks to your code as josh suggested, I would add 3.
One before this code section, another with the If Statement in it and another after that as a minimum.
Then run a test in Markey Replay for example if you need to and let me know what block fails.
Let me know if I can be of further assistance.
Comment
-
Hello,
I did narrow it down with Print statements and I arrived exactly in that line. And I did that for several instruments, always the same line.
But anyway, I will implement the try() catch() blocks as you suggest and hopefully we can narrow it down that way
Best, Peter
Comment
-
Hello,
By using try catch block my findings were confirmed: The error happens exactly in the specified code of line ExitShortStop or ExitLongStop in OnBarUpdate(). I am now a little more clever in that the error happens inside PlaceOrder()
What does Placeorder() exactly do in this context? Could it be an index problem with bars?
Interestingly it does not happen for every instrument, so my task now is to find out the differences...
Error protocoll:
FDAX
FESX
ExitShortStop Error
11.02.2011 22:00:00 System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs (= Index out of bounds)
bei NinjaTrader.Strategy.StrategyBase.PlaceOrder(Int32 selectedBarsInProgress, Boolean liveUntilCancelled, OrderAction action, OrderType orderType, Int32 quantity, Double limitPrice, Double stopPrice, String signalName, String fromEntrySignal, String oco, Boolean simStop)
bei NinjaTrader.Strategy.StrategyBase.ExitShortStop(Do uble stopPrice)
bei NinjaTrader.Strategy.MacroStrategy.OnBarUpdate()
FSMI
FGBS
ExitLongStop Error
11.02.2011 22:00:00 System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs.
bei NinjaTrader.Strategy.StrategyBase.PlaceOrder(Int32 selectedBarsInProgress, Boolean liveUntilCancelled, OrderAction action, OrderType orderType, Int32 quantity, Double limitPrice, Double stopPrice, String signalName, String fromEntrySignal, String oco, Boolean simStop)
bei NinjaTrader.Strategy.StrategyBase.ExitLongStop(Dou ble stopPrice)
bei NinjaTrader.Strategy.MacroStrategy.OnBarUpdate()
FGBL
ExitLongStop Error
11.02.2011 22:00:00 System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs.
bei NinjaTrader.Strategy.StrategyBase.PlaceOrder(Int32 selectedBarsInProgress, Boolean liveUntilCancelled, OrderAction action, OrderType orderType, Int32 quantity, Double limitPrice, Double stopPrice, String signalName, String fromEntrySignal, String oco, Boolean simStop)
bei NinjaTrader.Strategy.StrategyBase.ExitLongStop(Dou ble stopPrice)
bei NinjaTrader.Strategy.MacroStrategy.OnBarUpdate()
FGBM
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Barry Milan, Today, 10:35 PM
|
1 response
7 views
0 likes
|
Last Post Today, 10:48 PM | ||
Started by WeyldFalcon, 12-10-2020, 06:48 PM
|
14 responses
1,428 views
0 likes
|
Last Post
by Handclap0241
Today, 10:43 PM
|
||
Started by DJ888, Yesterday, 06:09 PM
|
2 responses
9 views
0 likes
|
Last Post
by DJ888
Today, 10:31 PM
|
||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
40 views
0 likes
|
Last Post
by jeronymite
Today, 10:10 PM
|
||
Started by bill2023, Today, 08:51 AM
|
2 responses
16 views
0 likes
|
Last Post
by bill2023
Today, 10:10 PM
|
Comment