![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Hi,
To implement more realistic fills in Forex, we need to use Bid/Ask data for the fills. The syntax for adding a Bid/Ask data series is Code:
Add(string instrumentName, PeriodType periodType, int period, MarketDataType marketDataType) Baruch |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
|
Baruch, yes, you can use a certain property to get the instrument's name:
Code:
string instName = Instrument.FullName;
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Austin thanks,
Yes I know that, but the Add() function is used in Initialize. Will at that point the instrument be known to the strategy? Baruch p.s. Why don't you have an overload for bid/ask without the instrumentName? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
|
Baruch, please try checking if instrument is null first.
Code:
if (Instrument != null)
{
string instName = Instrument.FullName;
Add(instName, ...);
}
I am not sure why there isn't a add bid/ask overload. I'll forward that as a suggestion.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Austin hi,
I know how to check and prevent the strategy from crashing. Do you really think that Quote:
Baruch |
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Feb 2009
Posts: 285
Thanks: 2
Thanked 54 times in 41 posts
|
you can get the current bid/ask from the following code. no need to add any additional dataseries.
Code:
this.GetCurrentAsk(); this.GetCurrentBid(); |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
bukkun thanks,
But I think that I do need the Add(). This is because I need to enter and exit my trades on different BarsInProgress. So I enter LongLimit on Ask series and exit Shorts on Ask series. Baruch |
|
|
|
|
|
#8 | |
|
Senior Member
Join Date: Feb 2009
Posts: 285
Thanks: 2
Thanked 54 times in 41 posts
|
Quote:
Code:
EnterLongLimit(GetCurrentAsk(),"signal name"); Code:
ChartControl.GetChartCaption |
|
|
|
|
|
|
#9 | |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Quote:
I don't want to enter immediately, but at specific price! The question is if on current bar the high >= MyPrice so it will enter a trade. Baruch p.s. I'm running back tests on granular resolution of 1 minute. |
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
|
GetCurrentAsk() and Bid() return the close of the bar when you're backtesting, not actual bids and asks. When running real-time, these methods behave as expected.
Baruch, the reason I suggested adding in the null check is because sometimes it works. From the help guide, "NOTE: The properties in this class [Instrument] should NOT be accessed within the Initialize() method." That is why I recommended you add in the manual name, so you have a working solution. Basically, anything that could give you the instrument name (Instrument, BarsPeriod, etc) you can't access from Initialize().
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#11 | |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Hi Austin,
I understand perfectly. Quote:
So your second solution is to hard code the curency I run the back test against in to the Add(). So do you prepose to create 20 strategies for 20 curency pairs only to work with bid/ask? Baruch |
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,017 times in 998 posts
|
Baruch, this is unfortunately correct - or you add a string input so you can set the symbol needed at runtime.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Bertrand,
I have a question: If in my strategy I add: Add(PeriodType.Tick,10); And I backtest my strategy on instrument XXX and "Price based on = Last" and "Type=Minute" What will be the instrument and the MarketDataType of my second data series? Now if I backtest my strategy on instrument XXX and "Price based on = Ask" and "Type=Minute" What will be the instrument and the MarketDataType of my second data series? Hopefully from your answers you will understand that it needs to be an overload with MarketDataType but without an Instrument. Baruch |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hello Baruch,
If you don't specify a MarketDataType within the add statement, then added series will be last. It will work this way even if you select ask as primary series when running the strategy. Hard coding instrument name is only solution for now. I will forward a request for new overload that allows specifying marketdata type without requiring instrument.
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 01-17-2011 at 11:29 AM.
|
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Mar 2009
Posts: 442
Thanks: 0
Thanked 25 times in 16 posts
|
Thanks,
I will wait. In the mean time I want to say that it works by extracting the name from Instrument.FullName Baruch |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Backtest order fills at Ask\Bid? | Ironleg | Strategy Analyzer | 5 | 03-07-2012 07:19 AM |
| How do I implement this idea | falcon00 | Automated Trading | 1 | 05-28-2010 05:35 AM |
| IDataSeries - Can we implement and pass to NT methods/functions? | Brillo | Indicator Development | 9 | 04-27-2010 08:48 AM |
| Market Replay Fills vs Live Real Money Fills | Lusitano | Strategy Development | 1 | 03-02-2009 09:38 AM |
| implement a function on NT | kuroro13 | Indicator Development | 8 | 08-06-2008 05:31 PM |