Australian (ASX) Stock Market Forum

Amibroker - How to do this?

Joined
18 January 2007
Posts
178
Reactions
0
In AB, how do I check if an indicator gave a positive signal in the last 7 days ?
For example if STOCH or MACD crossed its signal line 5 days ago but the EMA just crossed ? as sometimes not all the signals cross at the same time. I have been trying but with no success.
thanx.
 
Re: Amibroker - How To do this....

In AB, how do I check if an indicator gave a positive signal in the last 7 days ?
For example if STOCH or MACD crossed its signal line 5 days ago but the EMA just crossed ? as sometimes not all the signals cross at the same time. I have been trying but with no success.
thanx.
Use the "Hold" code.
HOLD
- hold the alert signal Trading system toolbox



SYNTAX hold( EXPRESSION, periods )
RETURNS ARRAY
FUNCTION Holds a "true" result of EXPRESSION for the specified number of periods. This true result is held true over the number of periods specified even if a "false" result is generated.
EXAMPLE hold( cross(rsi(14),70),5 )
 
Re: Amibroker - How To do this....

thanx for that wayneL,

does "This true result is held true over the number of periods specified even if a "false" result is generated. " mean that, lets say, the signal got generated 5 days ago and HOLD is keeping it, but in the mean time the RSI has fallen below the threshhold, HOLD would still give me a positive ?
 
Re: Amibroker - How To do this....

thanx for that wayneL,

does "This true result is held true over the number of periods specified even if a "false" result is generated. " mean that, lets say, the signal got generated 5 days ago and HOLD is keeping it, but in the mean time the RSI has fallen below the threshhold, HOLD would still give me a positive ?
yes exactly
 
Re: Amibroker - How To do this....

You can also use BarsSince, as in:

sig1 = Cross(macdLine, macdSignal); // MACD crossover
sig2 = Cross(ema1, ema2); // EMA crossover

haveSignal = sig2 && BarsSince(sig1) <= 7;

GP
 
Re: Amibroker - How To do this....

thanx guys for it. Can I use lookback as well?

I tried with BarsSince and somehow I didn't get any buy signals. When I removed the barsSince condition I got buy signals.

Here is how it looks for me.

Code:
Signal1 = BarsSince(MABuy) <= 7;
Signal2 = BarsSince(sig2) <= 7;
Signal3 = BarsSince(sig1) <= 7;
Buy = Signal1 AND Signal2 AND Signal3;

So when I replace it with
Code:
Buy = Signal1 OR Signal2 OR Signal3
I get buy signals.

thanx for ur help guys.
 
Re: Amibroker - How To do this....

Are you sure you're actually getting all three buy signals within those 7 days apart?

Use DebugView and add a trace loop after the "Buy=" statement like this:

dt = DateTime();
for (i = 0; i < BarCount; i++)
_TRACE(DateTimeToStr(dt) + StrFormat(": MABuy = %1.0f, sig1 = %1.0f, sig2 = %1.0f", MABuy, sig1, sig2));

then after doing a run, look through the trace for all the '1' indications and see if there are any that comply with the 7 days apart conditions.

Or trying testing with only two conditions at a time, to see which pairs are not falling within the 7 days apart.

GP
 
Re: Amibroker - How To do this....

Hi ya all. My AFL syntax skills are zilch and frankly I have no intention of learning more than the basics.

I have a VPA formula that I need a function removed/disabled from it and simply if possible. That being the ticker and url on the chart background.

I think it is this part

Code:
if( Status("action") == actionCommentary ) 
(
printf ( "=========================" +"\n"));
printf ( "VOLUME PRICE ANALYSIS" +"\n");
printf ( "www.vpanalysis.blogspot.com" +"\n");
printf ( "=========================" +"\n");
printf ( Name() + " - " +Interval(2) +  "  - " + Date() +" - " +"\n"+"High-"+H+"\n"+"Low-"+L+"\n"+"Open-"+O+"\n"+
"Close-"+C+"\n"+ "Volume= "+ WriteVal(V)+"\n");
WriteIf(Vpc,"=======================","");
WriteIf(Vpc,"VOLUME ANALYSIS COMMENTARY:\n","");
 
Was wondering if someone could help with finding engulfing candles on the weekly chart.
Mucked around with "TimeFrameSet" but can't devise the code to do the scan.
Cheers
 
Was wondering if someone could help with finding engulfing candles on the weekly chart.
Mucked around with "TimeFrameSet" but can't devise the code to do the scan.
Cheers
One of the difficulties using algorithmic techniques with candle patterns is defining the candles. I would start there.

Pick a candle you are planning to use. Say it is EngulfingCandle. Think about the characteristics that make that candle unique -- length of upper whisker, body, lower whisker, relationship to previous bar, etc. Write a definition as a function in AmiBroker's afl. The function takes prices (OHLC), bar by bar, and tests whether that bar qualifies to be the particular candle pattern. The function returns True when the conditions are met, False for all other bars.

That was the hard part.

Now pass a price history array to the function to evaluate whether the current bar, or previous bar if you wish, was an EngulfingCandle. Issue the trading signal that you want to go with it. Evaluate results.
 
One of the difficulties using algorithmic techniques with candle patterns is defining the candles. I would start there.

Pick a candle you are planning to use. Say it is EngulfingCandle. Think about the characteristics that make that candle unique -- length of upper whisker, body, lower whisker, relationship to previous bar, etc. Write a definition as a function in AmiBroker's afl. The function takes prices (OHLC), bar by bar, and tests whether that bar qualifies to be the particular candle pattern. The function returns True when the conditions are met, False for all other bars.

That was the hard part.

Now pass a price history array to the function to evaluate whether the current bar, or previous bar if you wish, was an EngulfingCandle. Issue the trading signal that you want to go with it. Evaluate results.

Hi Howard
Thanks for your reply (and your other contributions at ASF).
I know how to code the criteria for an engulfing candle (code as if doing it on a daily chart). Its when I want to scan, using that code, on a weekly chart that I am having problems with.

Cheers, dutchie
 
I'm new to Amibroker but think you don't need to change your code, only the time frame. If you change the time frame each bar matches your new time frame. Using TimeFrameSet you change the number of seconds each bar represents (60 = 1 minute, 3600 = 1 hour, 432001 = 1 week etc) and Amibroker uses your new time scale.

I wrote the following which creates a drop down parameter in the analysis window allowing you to run the same code for daily, weekly and monthly time periods.

TimeScale = ParamList("Time Period .", "Daily|Weekly|Monthly" );

if ( TimeScale == "Daily" )
{ Period = 86400 ; }
if ( TimeScale == "Weekly" )
{ Period = 432001 ; }
if ( TimeScale == "Monthly" )
{ Period = 2160001 ; }

TimeFrameSet( Period ); // switch time frame
 
Hi tmstu and Howard,
Thanks for your help and responses.
I will experiment with "timeframeset" et al.

Cheers, dutchie
 
Top