![]() |
|
|||||||
| Strategy Analyzer Support for automated system backtesting and optimization using the NinjaTrader Strategy Analyzer. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: May 2011
Posts: 6
Thanks: 0
Thanked 2 times in 2 posts
|
Good afternoon,
While I do have historical bid and ask from my data provider, I understand that by default, NT7 uses the "Last" data when backtesting. To make my backtest more realistic, I would have to always buy at the ask price and sell at the bid price. Well, I think doing this may be complicated. First, I would have to add a few data streams, e.g. Code:
Add(Symbol1, PeriodType.Minute, 1, MarketDataType.Ask); Add(Symbol1, PeriodType.Minute, 1, MarketDataType.Bid); Third, I don't think I'd be able to use SetProfitTarget and SetStopLoss properly, as they probably use only the primary DataSeries (please do correct me if I'm wrong). So if I used the ask stream to get long, now I'd need the bid data series to sell (close the position). Finally, if I run my strategy for multiple instruments, these complications increase tenfold. I don't want to hardcode the instrument name into the strategy. Should I use the "Unmanaged approach"? Am I unnecessarily complicating things here? Why doesn't NT7 handle the bid/ask issue internally? I understand that not all data providers support historical bid/ask - but the fact is that some do. Thanks in advance for your help! |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Mar 2011
Location: Denver, CO
Posts: 103
Thanks: 0
Thanked 0 times in 0 posts
|
Hello Shahar,
Thank you for your first post and welcome to the NinjaTrader forums! This approach of adding two additional instruments for the bid and ask market data is the most straight forward work-around for accessing this data in a backtesting environment. Regarding trading from the ask, bid and SetStopLoss() and SetProfitTarget(), they will work on the primary series but it should not be too unwieldy to handle. You can set them with your second and third series' data with Closes[][] or by setting them in a BarsInProgress check for the appropriate series. The same goes for order entry, you can pass the 2nd or 3rd data series' current close value for ask/bid. You could use the unmanaged order approach, but with some minor work on setting your order entries, stops and profit targets, you can achieve what you are trying to do. This is assuming you want to only work with one currency pair at a time - EUR/USD, with EUR/USD bid and EUR/USD ask added for example. If you do not want to add 2 data series for back testing ask and bid, testing with market replay would be a better alternative for this as level 2 data will be available if recorded/downloaded, with only 1 instrument in your strategy. You can set the replay speed to 500x to quickly test some days worth of data tick by tick. Please let me know if I can assist you any further.
Dexter
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: May 2011
Posts: 6
Thanks: 0
Thanked 2 times in 2 posts
|
It is really disappointing that NT7 does not have an option to "automatically" buy at ask and sell at bid, when historical data are available. Please consider incorporating this feature in future releases.
I understand how to enter with a secondary series, as EnterLong and EnterShort, for example, have a barsInProgressIndex parameter. However, SetStopLoss and SetProfitTarget do not have this parameter. How exactly do I make sure that a short position is closed when SetProfitTarget/SetStopLoss reach the ask price, rather than the bid price? Would something like Code:
if (BarsInProgress == 2)
{
stoploss = Close[0] + (stopLossDistance);
takeProfit = Close[0] - (takeProfitDistance);
SetStopLoss("Sell", CalculationMode.Price, stoploss, false);
SetProfitTarget("Sell", CalculationMode.Price, takeProfit);
}
Where would this then fit in the code, assuming you entered the short position on the bid stream? I assume you would first have to check your MarketPosition - this gets ever so complicated for the simplest of strategies. Again, please seriously consider having a built-in feature for this in the next release. Thanks!
Last edited by Shahar; 05-10-2011 at 03:19 PM.
Reason: Changed signal name
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Mar 2011
Location: Denver, CO
Posts: 103
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Shahar,
The code you posted would have the stop loss and profit target set based on the 3rd series price, that is correct. The managed order approach will automatically submit them once you're in a position. If you want them to be based off the price but not dynamically update each tick/bar, you could set them in OnOrderUpdate() or OnExecution() after getting a fill. This would submit them at your default, then update them to your desired price based on the ask/bid immediately after. SetProfitTarget(), SetStopLoss() and SetTrailingStop() apply to all series in strategy. If you would like to manage exits on a finer per series basis, ExitShortStop(), ExitShort() etc can do this with a bars in progress index parameter. Please let me know if I can assist you any further.
Dexter
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: May 2009
Posts: 202
Thanks: 7
Thanked 2 times in 2 posts
|
Shahar, did you get it working?
|
|
|
|
![]() |
| Tags |
| backtest, forex, spread |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| option to remove "buy ask" and "sell bid" on chart trader | leontancfa | Charting | 1 | 07-01-2009 01:23 PM |
| summary of "strategy realized" is not equal "account performance, total net profit"" | Fragolino | Miscellaneous Support | 1 | 02-19-2009 04:12 AM |
| Difference between "trades" and "strategies" results | suitguy1 | Automated Trading | 1 | 07-25-2008 03:05 PM |
| "'OrderRejected'. Strategy has sent cancel requests" & "There is no market data..." | Elliott Wave | Strategy Development | 6 | 04-12-2008 12:03 AM |
| Control center "strategies" tab, "Positions tab, and "Market Analyzer" not | funk101 | Strategy Development | 6 | 04-10-2007 03:44 AM |