![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Aug 2008
Posts: 233
Thanks: 19
Thanked 5 times in 5 posts
|
Hi,
I'm having some intermittent trouble with the following; I am using this line of code to save the prior trade as a private double in the variables section. Code:
protected override void OnPositionUpdate(IPosition position)
{
if (position.MarketPosition == MarketPosition.Long) priorTrade = position.AvgPrice;
Print(Instrument.FullName + " " + position.AvgPrice);
}
I loaded the strategy today which should have placed a long limit to buy, when it didn't I removed this line of code below referencing the prior trade and reloaded the strategy which placed the order. Code:
priorTrade != gNumb().Line4[0] Regards, suprsnipes |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 974 times in 957 posts
|
suprsnipes, when do you reset the price level to not take a trade, daily weekly?
Not sure I fully follow, but to me it seems your logic is working as this trade as perhaps at the same price level as the last one saved to the corresponding variable?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Aug 2008
Posts: 233
Thanks: 19
Thanked 5 times in 5 posts
|
Hi Bertrand,
The variable priorTrade is only stored for the session as far as I know...does the variable reset when you stop the strategy? My logic is as you have mentioned. I'm using the priorTrade to ensure if all other conditions are met AFTER the strategy has already entered a long position at the same price level as the priorTrade then my strategy will ignore the signal. I am testing another strategy with the same priorTrade code where I am NOT running into the same problem. The main issue is the strategy won't place any trades whatsoever, but as soon as I remove the line of code regarding the priorTrade the strategy runs as expected...can you offer any further suggestions? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 974 times in 957 posts
|
suprsnipes, well if you do not reset it explicitly at Session break it may still be filled from a prior session as the strategy cycles through the historical OnBarUpdate() part as you start it up. So you would need to debug the values being set by the strategy for this variable as you already determined it works as expected without this involved in your conditions.
http://www.ninjatrader-support2.com/...ead.php?t=3418
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Aug 2008
Posts: 233
Thanks: 19
Thanked 5 times in 5 posts
|
Thanks for the quick reply (as always),
Bertrand could you please let me know where you would suggest I place the code to reset the priorTrade variable? Regards, suprsnipes |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 974 times in 957 posts
|
You're welcome, you could place it at the session break then -
http://www.ninjatrader-support.com/H...sionBreak.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Aug 2008
Posts: 233
Thanks: 19
Thanked 5 times in 5 posts
|
Hi Bertand,
After pointing me in the right direction which I really appreciate by the way, to reset the priorTrade variable at the start of each session this is what I come up with. Code:
protected override void OnBarUpdate()
{
// At the start of a new session
if (Bars.SessionBreak)
{
// Reset the priorTrade variable
priorTrade = 0;
}
}
Learning heaps by the way...and it's great the you guys at NT offer support to inexperienced programmers willing to have a go. Best regards, suprsnipes |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 974 times in 957 posts
|
You're welcome, great this helped you made it work.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Position.AvgPrice = Order Fill Price? | tonyh | Strategy Development | 1 | 03-13-2010 12:28 PM |
| Position.AvgPrice | Faspomy | Strategy Development | 7 | 02-16-2010 10:52 AM |
| Position.AvgPrice Real Value | daven | Automated Trading | 1 | 10-30-2008 09:31 AM |
| Why Position.AvgPrice gives not exact price | pmaglio | Strategy Development | 8 | 07-24-2008 12:32 PM |
| Position.AvgPrice | MrBaffalo | Strategy Development | 1 | 05-16-2007 09:01 AM |