![]() |
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 |
|
Junior Member
Join Date: Oct 2009
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
Hello,
I am trying to use IOrders to store my entry prices and then use those values to exit after target/stop condition is triggered. But when I backtest the below code and when I print the entry1price, entry2price, diff to output: I just get 3 zeros on the output window plus the stop gets trigged immediately on the same bar, but the price never dropped 100 points. What’s causing this?… (note: This doesn’t make sense to me, but the code works if I change ‘<’ to ‘>’ in the condition that triggers the stop….also this is a multi instrument strategy) Can someone please give me a bit advice on how to fix this Thanks for your time in advance ![]() #region Variables private IOrder entryOrder1 = null; private IOrder entryOrder2 = null; private double entry1Price = 0; private double entry2Price = 0; #endregion protected override void OnBarUpdate() { currentdiff = closes[1][0] – closes[2][0]; //this is the entry If (condition1 && entryOrder1 == null && entryOrder2 == null { entryOrder1 = EnterLong(); entryOrder2 = EnterShort(); } //this to calculate the difference between my entry prices on two instruments If (entryOrder1 != null && entryOrder2 != null) { if (entryOrder1.Filled > 0 && entryOrder2.Filled > 0) { entry1Price = entryOrder1.AvgFillPrice; entry2Price = entryOrder2.AvgFillPrice; diff = entry1Price - entry2Price; } //this is the profit target //currentdiff is calculated on each bar If(currentdiff >= diff + 100 && entryOrder1 != null && entryOrder2 != null) { ExitLong(); ExitShort(); entryOrder1 = null; entryOrder2 = null; Print(entry1Price); Print(entry2Price); Print(diff); } //this is the stop If(currentdiff <= diff - 100 && entryOrder1 != null && entryOrder2 != null) { ExitLong(); ExitShort(); entryOrder1 = null; entryOrder2 = null; Print(entry1Price); Print(entry2Price); Print(diff); } } else {} |
|
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Market Replay and IOrders | gregid | Version 7 Beta General Questions & Bug Reports | 13 | 01-13-2010 02:13 PM |