View Full Version : BarsSinceEntry
mballagan
05-06-2009, 11:32 AM
I am using BarsSinceEntry within a strategy but when testing using market replay no trades are being fired.
Syntax is :
if(BarsSinceEntry("LongEntryCrosses")>1)
{
//enter long trade
LongOrderCrosses = EnterLong(LotSize,"LongEntryCrosses");
}
Is there a reason for this?
If I take out the test on some bars the strategy is attempting to place a trade multiple times (100s) and this is then being cancelled due to logic I think within the strategy
NinjaTrader_Josh
05-06-2009, 11:37 AM
mballagan,
You cannot use that condition like that because for the very first trade there was no BarsSinceEntry() > 1. You will need to code a set for the first trade and a separate set for subsequent trades you wish to use the BarsSinceEntry logic with.
mballagan
05-06-2009, 11:56 AM
Ok thanks so I have used the following code:
bool entertradecondition = false;
Trade firstTrade = Performance.AllTrades[0];
if(firstTrade == null)
{
entertradecondition = true;
}
else
{
entertradecondition = BarsSinceEntry()>1;
}
if(entertradecondition)
{
//enter trade
}
NinjaTrader_Josh
05-06-2009, 12:01 PM
mballagan,
You can try it.
mballagan
05-06-2009, 03:18 PM
It doesnt seem to work. I have more than one time series in the strategy although only executing trades on the primary series.
If using the syntax:
Trade firstTrade = Performance.AllTrades[0];
Is there a way I can retrieve the label the trade was initialised under?
For example if EnterLong("LongOrder1") was used the label is LongOrder1.
NinjaTrader_Josh
05-06-2009, 03:36 PM
http://www.ninjatrader-support.com/HelpGuideV6/TradeClass.html
You will want to go to the individual IExecutions and then grab the Name properties from them.