If statement help

Hi there, I've been studying AmiBroker for nearly a year now, and I think am in a situation where I NEED to use an if statement (not IIf).

My formula identifies a SpecialCase as an event when price hits my prescribed LimitEntryPrice AND the MissedTheBoatPrice in a single bar. So you get a signal, then the next bar you want to enter. However, if price goes up and hits your target before entry, then it invalidates the signal. You missed the boat.

IF the special case occurs, I then use TimeFrameSet/Restore/Expand to drill down into that bar (from a 15-minute bar to a 1-minute bar) to determine white price level, LimitEntryPrice or MissedTheBoatPrice, was hit first.
IF the special case does not occur, then I do not want to waste system resources (time) to drill down into the 1-minute time frame. I've tried this approach already, and my system grinds to a crawl when scrolling through the chart. I only want to drill down into that time frame when it's required.


My challenge: SpecialCase returns as an array. I need a numeric or Boolean value to control the if statement. What are my options with respect to pulling the value of SpecialCase bar out of the array and storing it into a numeric or boolean variable (non-array)?

I keep going in circles using functions like BarCount, LastValue(), BarIndex(), ValueWhen().
BarCount is the total number of bars in my chart. LastValue() is the last value of SpecialCase in the chart, BarIndex(), I try to use that in SpecialCase[BarIndex()] , but it tells me I can only use a number as an index (BarIndex() is an array :frowning: ). I tried ValueWhen(SpecialCase, BarCount) and that returns an array also.
AHHHHH this is probably the simplest thing in the history of things, but it's melting my brain! Help!!!

I can paste code if you guys need it, my real question is more focused on the "how do I get a number/Boolean for my if statement?"

Nathan.

It looks like I can use [BarCount-1], and it returns the value of the array from the bar to the farthest right on screen. It does a weird thing though. When I plot it, it plots a horizontal line all the way across the chart equivalent to the value of the Array of the bar to the far right. It looks kinda weird, but it may work when I'm running a back test?

Still digging into this one. If anyone has any experience, please give me a shout. Thanks.

See

Understanding how AFL works.

@nxg380, as suggested by @TrendSurfer you should try to better understand how AFL works.

In general, you should use the iif() function when you want to backtest your logic: you need to process all occurrences where your "special case" situation happens: if you use LastValue() then you are "forcing" to evaluate only the last particular case.

This may be fine if you use it on a chart to see only the most recent one (like when trading with a live feed) but it is not ok for a backtest that needs to handle all past events.

So I suggest you post the code to see how it can be modified for backtesting purposes.

Guys every day I'm trying to better understand AmiBroker! I've been through that document a time or two, but I'll take another look and see if I can't figure this out. Thank you.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.