Any ideas on how to work around this, or somehow help you guys figure out why then happens??? It doesn't do it EVERYTIME, but it does happen frequently.
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
I found a bug that appears every so often...
Collapse
X
-
I found a bug that appears every so often...
When ever I EnterLong() or EnterShort() from within a strategy, there are times when the Position.AvgPrice gives back a number of "0.0018" or something like this. Now there is NO WAY the position could have been opened at that low of number especially when the bid is more like 1.4019.
Any ideas on how to work around this, or somehow help you guys figure out why then happens??? It doesn't do it EVERYTIME, but it does happen frequently.Last edited by VagyokC4; 09-28-2007, 07:46 AM.Tags: None
-
Here's my code...
Could it be that I'm checking that property too quickly. I.E. I enter the position then immediatly check that property.
Do I need to wait for a second or two before checking the AvgPrice property?
Here's my code:
{
EnterLong();
double EntryPrice = Position.AvgPrice;
Print(EntryPrice); // Somtimes is not an accurate number
}
Comment
-
Originally posted by NinjaTrader_Dierk View Post>> Could it be that I'm checking that property too quickly.
Absolutely.
a) realtime: market orders are not filled right away. Exchanges take a few milli seconds to fill orders (same on sim account).
b) backtest: market order are only filled after you returned from the OnBarUpdate method.
So my next two questions are:
1) Does using Thread.Sleep have any adverse effect on the system?
2) How long should I put the thread to sleep before checking the AvgPrice property so that I'm 99.9% guaranteed I get an accurate value?
Ie.
{
EnterLong();
System.Threading.Thread.Sleep(1000);
double EntryPrice = Position.AvgPrice;
}
or do I need to wait for the next OnBarUpdate to be 100% accurate?Last edited by VagyokC4; 09-28-2007, 08:06 AM.
Comment
-
Thread.Sleep will not do what you are looking for. The only solution is checking Position.Quantity on every OnBarUpdate call if it has the expected quantity and then trigger next actions.
Note: Upcoming NT6.5 (available in a few weeks) provides position update events which you could handle for finer granularity of control.
Comment
-
Originally posted by NinjaTrader_Dierk View PostThread.Sleep will not do what you are looking for. The only solution is checking Position.Quantity on every OnBarUpdate call if it has the expected quantity and then trigger next actions.
Note: Upcoming NT6.5 (available in a few weeks) provides position update events which you could handle for finer granularity of control.
{
// Assert Position.Quantity == 0
EnterLong(5);
While (Position.Quantity != 5)
{
}
double EntryPrice = Position.AvgPrice;
}
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by kaywai, 09-01-2023, 08:44 PM
|
5 responses
601 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by xiinteractive, 04-09-2024, 08:08 AM
|
6 responses
22 views
0 likes
|
Last Post Today, 12:31 AM | ||
Started by Pattontje, Yesterday, 02:10 PM
|
2 responses
16 views
0 likes
|
Last Post
by Pattontje
Yesterday, 11:49 PM
|
||
Started by flybuzz, 04-21-2024, 04:07 PM
|
17 responses
230 views
0 likes
|
Last Post
by TradingLoss
Yesterday, 11:45 PM
|
||
Started by agclub, 04-21-2024, 08:57 PM
|
3 responses
17 views
0 likes
|
Last Post
by TradingLoss
Yesterday, 11:42 PM
|
Comment