PDA

View Full Version : Referencing Previous Instance(s) Of Condition


roxana
05-22-2007, 06:07 AM
If I want to reference the bar on which a trade was instigated or a bar (or set of bars) nbars ago when a condition(s) was last satisfied,how do I do this please?

NinjaTrader_Dierk
05-22-2007, 06:42 AM
Try e.g.
SMA(14)[5]
to retrieve the 14 period SMA 5 bars ago.

roxana
05-22-2007, 07:16 AM
I really do want to escape Tradestation's hegemony but easylanguage gives them the killer punch until you're able to upgrade your wizard to a comparable level.Either that or provide an EL to C# translator.

NinjaTrader_Ray
05-22-2007, 07:17 AM
We currently do not have a method to be able to check "How many bars ago did condition X occur". You would have to code this yourself.

NinjaTrader_Dierk
05-22-2007, 09:39 AM
Next update will support TradeStation like logic for CountIf, MRO and LRO.

whitmark
08-01-2007, 06:23 AM
I've noticed in the help that the Countif function (as well as MRO/LRO functions) is caveated in that it will not work with multiple instruments or timeframes. Is this still the case, and if so, do you offer an alternative approach? Converting boolean expressions to doubles, setting these 1/0 values to a dataseries and then using the SUM function on this dataseries to count the occurances didn't work as expected.

Regards,

Whitmark

NinjaTrader_Dierk
08-01-2007, 07:08 AM
You always could code a workaround going with similar logic (by running the checks on all bars of the lookback period). The methods provided are just for convenience.

whitmark
08-01-2007, 02:18 PM
For clarification, consider the following example where Low[0] and Close[0] are from an hourly series (BarsInProgress = 0) and user defined variable YestDailyLow is assigned during a Daily series bar close event (BarsInProgress = 1). One would think the way to invoke a CountIf would be:

If (BarsInProgress == 0)
{
myCond = CountIF( delegate (return Low[0] <= YestDailyLow && Close[0] >= YestDailyLow;), 5) > 2);
}

But I can see how an extended lookback might not correctly evaluate the BarsArray[1] values retained in the user defined variable YestDailyLow. Would it be helpful to retain the BarsArray[1] values in a dataseries aligned to the BarsArray[0] interval to make the CountIF work properly for multiple timeseries strategies? For example:
If (BarsInProgress == 0)
{
myCond = CountIF( delegate (return Low[0] <= YestDailyLowSeries[0] && Close[0] >= YestDailyLowSeries[0] ;), 5) > 2);
}
Will this work to address the caveat on the CountIf function?

Regards,

Whitmark

NinjaTrader_Ray
08-01-2007, 02:32 PM
You can't fit a square peg in a round hole :).

The method will not work on a multi-time frame strategy.

whitmark
08-01-2007, 03:30 PM
Okay, but do I get points for trying? I'll cry "uncle" and use the brute force method below:

if (BarsInProgress == 0)
{
YestDailyLowSeries.Set( YestDailyLow );
int count = 0;
for ( int i = 0, i < 5 && CurrentBar - 5 >= 0; i++ )
{
if ( Low[i] <= YestDailyLowSeries[i] && Close[i] >= YestDailyLowSeries[i] ) Count++;
}
myCond = count > 2;

Any chance a "square peg" version of CountIf is on the development horizon? As you can image, having a function that can determine whether X conditions occured across Y events within Z bars can be pretty useful and something AmiBroker can apparently do across multiple timeframes. Thanks.

Regards,

Whitmark

ccie8340
08-01-2007, 04:42 PM
Ray,

Looking at Marks' post and your reply now....So what are the options for countif where multitimeframe is involved?. Can you pls suggest some alternatives if that means coding in c# thats fine..But I just need some ideas so that I can get the function created in C#.

Thanks.

Cheers,Padhu

NinjaTrader_Ray
08-01-2007, 05:13 PM
You have to self code a loop that iterates through a specified number of bars checking for your condition.