Australian (ASX) Stock Market Forum

Amibroker FAQ

Hi,

This is driving me mad :banghead:, can someone please explain why this isn't working!?
To explain I have a very simple system:
MAs = MA(C,20);
MAl = MA(C,50);
Buy = Cross(MAs,MAl);
Sell = Cross(MAl,MAs);

What I want to do is to stop issuing buy signals based on something else, ie, another filter, maybe when the market is a bear market.

So, my system would now look like this:

flagval = 0;

MAs = MA(C,20);
MAl = MA(C,50);

Buy = Cross(MAs,MAl) AND flagval = 1;
Sell = Cross(MAl,MAs);

Where the first variable 'flagval' changes from 0 to 1.
However, if I run the above code I still get the same number of buy signals.
Surely the above code should not give me any buy signals as flagval is always zero and my buy criteria is looking for flagval = 1.

What am I missing here?

Thanks
 
hi, im new to AB and im having some real trouble trying to code for the following.

I want to identify / be able to scan for when a stock gaps down (or up), on open and close back into the previous days range?

as per the following chart

can anyone at least point me in the right direction?

any help would be awesome
 

Attachments

  • Untitled.gif
    Untitled.gif
    16.9 KB · Views: 137
hi, im new to AB and im having some real trouble trying to code for the following.

I want to identify / be able to scan for when a stock gaps down (or up), on open and close back into the previous days range?

as per the following chart

can anyone at least point me in the right direction?

any help would be awesome


If you log into http://www.amibroker.com/members/library/list.php then you will find reversal formulae.

thanks for the link, very handy, but i am still struggling to find one that will resemble the one that i want.

Aside from going through
- AFL tutorial (a language which is a little foreign to me),
- Examples from the link above
- I have ordered Bandy's book on intro to AB

is there any other way of obtaining the correct formula if i still cant get it

or can i simply pay someone to do it?

Thanks in advance
 
Hi,

This is driving me mad :banghead:, can someone please explain why this isn't working!?
To explain I have a very simple system:
MAs = MA(C,20);
MAl = MA(C,50);
Buy = Cross(MAs,MAl);
Sell = Cross(MAl,MAs);

What I want to do is to stop issuing buy signals based on something else, ie, another filter, maybe when the market is a bear market.

So, my system would now look like this:

flagval = 0;

MAs = MA(C,20);
MAl = MA(C,50);

Buy = Cross(MAs,MAl) AND flagval = 1;
Sell = Cross(MAl,MAs);

Where the first variable 'flagval' changes from 0 to 1.
However, if I run the above code I still get the same number of buy signals.
Surely the above code should not give me any buy signals as flagval is always zero and my buy criteria is looking for flagval = 1.

What am I missing here?

Thanks

Try using an extended function with braces.

For example;

Buy = Close > 14
AND {
MA( Close , 15 ) > 10
AND Wilders( Close , 15 ) > 10
};

Sell = Sum( Close , 35 ) < 10
AND WMA( Close , 15 ) > 10
AND DEMA( Close , 15 ) > 10;

Short = 0;

Cover = 0;
 
Thanks for the replies.
I'm having trouble with the following though:
I'm trying to build a filter using the following formula:
copp = EMA( ROC( MA( C, 22 ), 250 ), 150 ) / 100;
trend = Copp>0 OR (Copp<0 AND ROC(Copp)>0));

The individual components of the trend formula work when plotted on a graph, ie, Copp<0 , and Copp<0 AND ROC(Copp)>0 but when I combine them as shown above they do not work correctly.

I've tried using the curly brackets as mentioned above but this just gives me a syntax error.

Does anyone know why my 'trend' formula isn't working?
 
hi, im new to AB and im having some real trouble trying to code for the following.

I want to identify / be able to scan for when a stock gaps down (or up), on open and close back into the previous days range?

as per the following chart

can anyone at least point me in the right direction?

any help would be awesome

Try this, it will give you the basic code but you may have to add some filters like min volume or turnover, and maybe 4 or 5 down days first to give you the set up you are looking for.

Code:
Cond1 = O < Ref(L,-1);
Cond2 = C > Ref(L,-1);

Buy = Cond1 AND Cond2;

Filter = Buy; // lists exploration results conforming to our buy criteria
AddColumn(Buy, "buy", 1.0); //
 
Thanks for the replies.
I'm having trouble with the following though:
I'm trying to build a filter using the following formula:
copp = EMA( ROC( MA( C, 22 ), 250 ), 150 ) / 100;
trend = Copp>0 OR (Copp<0 AND ROC(Copp)>0));

The individual components of the trend formula work when plotted on a graph, ie, Copp<0 , and Copp<0 AND ROC(Copp)>0 but when I combine them as shown above they do not work correctly.

I've tried using the curly brackets as mentioned above but this just gives me a syntax error.

Does anyone know why my 'trend' formula isn't working?

Too many brackets, try this

Code:
copp = EMA( ROC( MA( C, 22 ), 250 ), 150 ) / 100;
trend = Copp>0 OR (Copp<0 AND ROC(Copp)>0);
 
thanks for the link, very handy, but i am still struggling to find one that will resemble the one that i want.

Aside from going through
- AFL tutorial (a language which is a little foreign to me),
- Examples from the link above
- I have ordered Bandy's book on intro to AB

is there any other way of obtaining the correct formula if i still cant get it

or can i simply pay someone to do it?

Thanks in advance

Unfortunately there aren't many people conversant with AFL. Those that are don't let on. Basically what they are saying is learn it yourself like they had to or pay someone for it. A frustrating mind game but not debilitating.

Have a play with AFL Code Wizard using the LLV for 15 bars.
 
Unfortunately there aren't many people conversant with AFL. Those that are don't let on. Basically what they are saying is learn it yourself like they had to or pay someone for it. A frustrating mind game but not debilitating.

Greetings all --

I hope neither of your statements is true, or widely thought to be true.

Someone who has discovered a profitable trading system will probably not disclose it in a public forum. But there are a lot of people who are conversant with AmiBroker's afl language and program operations and are willing to help.

Check the Amibroker web site, watch the video tutorials, read the user's reference manual, and read the user's knowledge base. Download, read, and try some of the code in the library. But beware, the code you will find there is a mix of wheat and chaff.

Subscribe to the AmiBroker group hosted at Yahoo:
http://finance.groups.yahoo.com/group/amibroker/
There are over 9000 members and 145000 postings. There is a file section with a wealth of material.

Read the threads that interest you. Post questions you would like answered. The forum is very knowledgable and supportive, but do your research before posting. Check the references and search the threads to be certain that the question you want answered is not easily answered from those sources. The ideal question is accompanied by a code example that illustrates your question.

Thanks,
Howard
 
Greetings all --
The ideal question is accompanied by a code example that illustrates your question.

Thanks,
Howard
Hello Howard, I have a few things I need to know if you or anyone are willing to help, please. The first one is in relation to the following formula in which the instruction for use is to check the periodicity in Automatic Analysis to 1 minute. Trouble is I don't have a 1 minute option but maybe the code could be adjusted to work day bars? I tried changing code from in1Minute to inDaily but that didn't work.

Formula 1. Multiple time-frame MACD. Note: in order to run this code and calculate multiple time-frame MACD, enter it into Automatic Analysis (AA) window, go to Settings window, make sure that Periodicity is set to 1-minute. Then press "Scan" button in the AA window.
Code:
Count = 0;
result = 0;

for( i = 10; i <= 300; i++ )
{
   TimeFrameSet( i * in1Minute );
   m = MACD(12, 26 );
   TimeFrameRestore();
   m = IIf( TimeFrameExpand( m, i * in1Minute ) > 0, 1, -1 );
   result = result + m;
   Count++;
}

AddToComposite( result / Count, "~MACD"+Name(), "X" );
Buy=1;

x = Foreign("~MACD"+Name(),"C");

Plot( x, "MTMACD", colorBlue , styleThick ) ;

PlotGrid(0.5 );
PlotGrid(-0.5);
The other question is in regard to the following code which is supposed to identify a receding MACD histogram. "(ie. changing from a positive slope to a negative slope or changing from a negative slope to a positive slope)"

I can't see where a buy signal would be initiated to register on the scan.
Code:
GraphXSpace = 8;
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );

mm = MACD(r1, r2);
ms = Signal(r1, r2, r3);

f1 = ((r3+1)*MM-2*MS)/(r3-1);
f2 = EMA(C,r1)*(r1-1)/(r1+1);
f3 = EMA(C,r2)*(r2-1)/(r2+1);
f4 = 2/(r1+1) - 2/(r2+1);

dcv = (f1-f2+f3)/ f4;

Plot(dcv,"",4);
PlotOHLC(O,H,L,C,"",1,styleCandle);
Title = Name() + "  -  " + FullName() + "  -  " + Date() + "  -  Close = " + WriteVal(C,0.3) + "  -  DCV = " + WriteVal(dcv,0.3);
 
Greetings all --

I hope neither of your statements is true, or widely thought to be true.

Someone who has discovered a profitable trading system will probably not disclose it in a public forum. But there are a lot of people who are conversant with AmiBroker's afl language and program operations and are willing to help.

Check the Amibroker web site, watch the video tutorials, read the user's reference manual, and read the user's knowledge base. Download, read, and try some of the code in the library. But beware, the code you will find there is a mix of wheat and chaff.

Subscribe to the AmiBroker group hosted at Yahoo:
http://finance.groups.yahoo.com/group/amibroker/
There are over 9000 members and 145000 postings. There is a file section with a wealth of material.

Read the threads that interest you. Post questions you would like answered. The forum is very knowledgable and supportive, but do your research before posting. Check the references and search the threads to be certain that the question you want answered is not easily answered from those sources. The ideal question is accompanied by a code example that illustrates your question.

Thanks,
Howard


Thanks Wysiwyg and Howard for your replies, i will look into that yahoo group as well
 
The other question is in regard to the following code which is supposed to identify a receding MACD histogram.
Please disregard the above question as I have found a better code to do the business.
Sicilian Trader
Re: Amibroker FAQ
hi, im new to AB and im having some real trouble trying to code for the following.

I want to identify / be able to scan for when a stock gaps down (or up), on open and close back into the previous days range?

as per the following chart

can anyone at least point me in the right direction?

any help would be awesome

I see Valley cracked the code and Anthony finished it off. I can't see it bearing fruit though. :eek:
 
Hi, can anyone please help me to construct this straight channel?
Upper channel line = EMA+EMA*2
Lower channel line = EMA-EMA*2
Thank you.
 
Please disregard the above question as I have found a better code to do the business.


I see Valley cracked the code and Anthony finished it off. I can't see it bearing fruit though. :eek:

yeah, you're right , its all over the place, i dont have any stops in, and the signals arent selective as to when to buy or sell ie. after 3 consecutive up days or down days.

Im just starting out with testing, and i am trying to avoid the pitfulls of testing, curve fitting , optmizing etc

thanks for your help
 
yeah, you're right , its all over the place, i dont have any stops in, and the signals arent selective as to when to buy or sell ie. after 3 consecutive up days or down days.

Im just starting out with testing, and i am trying to avoid the pitfulls of testing, curve fitting , optmizing etc

thanks for your help

My suggestion would be to find out when that set up works best and then try to build a code for that. You would also then try testing small changes in the code, like different trend filters, buying after 3-5 days down in a strong trend etc etc.
I personally would be looking to buy a set up like that either in a strong trend or @ a strong support zone.

Try this, it will give you the basic code but you may have to add some filters like min volume or turnover, and maybe 4 or 5 down days first to give you the set up you are looking for.

Code:
Cond1 = O < Ref(L,-1);
Cond2 = C > Ref(L,-1);

Buy = Cond1 AND Cond2;

Filter = Buy; // lists exploration results conforming to our buy criteria
AddColumn(Buy, "buy", 1.0); //
 
My suggestion would be to find out when that set up works best and then try to build a code for that. You would also then try testing small changes in the code, like different trend filters, buying after 3-5 days down in a strong trend etc etc.
I personally would be looking to buy a set up like that either in a strong trend or @ a strong support zone.

Thanks Nomore4s

Where am I putting that code in relation to the one I already have?



gapclosingfromupopen =Open > Ref(H,-1) AND C > Ref(L,-1) AND C < Ref(H,-1);

gapclosingfromdownopen=Open < Ref(L,-1) AND C > Ref(L,-1) AND C < Ref(H,-1);

Color= IIf(gapclosingfromupopen,colorRed,IIf(gapclosingfromdownOpen,colorBlue,ParamColor("color",colorBlack)));

Filter= gapclosingfromupopen OR gapclosingfromdownopen;

AddColumn(C,"");

AddColumn(gapclosingfromupopen,"up");

AddColumn(gapclosingfromdownOpen,"down");



_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Plot( C, "Close", color , styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

_SECTION_END();


The one I have




Cond1 = O < Ref(L,-1);
Cond2 = C > Ref(L,-1);

Buy = Cond1 AND Cond2;

Filter = Buy; // lists exploration results conforming to our buy criteria
AddColumn(Buy, "buy", 1.0); //


This one you gave me


Thanks
 
Thanks Nomore4s

Where am I putting that code in relation to the one I already have?

lol, it's already in there.

gapclosingfromdownopen is pretty much the same code as mine just presented in different ways.
Mine is also presented as a BUY set up as well as an exploration(scan). Using a buy set up with different trailing stops or sell set ups will let you backtest the various set ups to get some stats on what works and what doesn't.

I have just run a scan on the code in blue and it brings up a lot of set ups that are rubbish, you need to add some filters to it to narrow down what you want.

Here is a more complete code you can use to do some very basic testing on to get some stats.

Try it without a max stop and with a max stop, change the number of days down, run with or with out a trend filter etc etc and see how the results vary and try to understand what effect changing these things has on the results and then run over different time periods to see the effect on the results in different market conditions.
Then you also need to come up with some sort of exit strategy as this testing only tests the movement after 3,5,10,20 or whatever bars from the buy set up. You could also refine the entry by using a traders trick entry or something along those lines for an entry.

This code is not a complete mech system it is only the basic code to do some basic testing on. Good luck

Code:
// Buy set up - Buy after a gap down and a close to fill the gap. Cond2 is 4 down days.
// Cond3 is EMA filter but run tests with & without this filter to see how results vary.

Cond1 = O < Ref(L,-1) AND  C > Ref(L,-1); // Open is lower then yesterdays close but close is higher then yesterdays low
Cond2 = Ref(C,-1) < Ref(C,-2) AND Ref(C,-2) < Ref(C,-3) AND Ref(C,-3) < Ref(C,-4); //Yesterdays close is lower then day before close etc etc
Cond3 = H > EMA(C,200); // Todays H is greater then 200 day EMA

Buy = Cond1 AND Cond2 AND Cond3;

// Trade exits after 3,5,10,20 bars depending on settings, vary these setting to see effect on results.
// Could also try some sort of trailing stop depending on what you are trying to achieve
ApplyStop(stopTypeNBar, stopModeBars, 10); // Exit after 3,5,10,20 bars depending on settings
Cond1 = C < Ref(C,-365);
Cond2 = C > Ref(C,-365);
Sell = Cond1 & Cond2;

Filter = Buy; // lists exploration results conforming to our buy criteria
AddColumn(Buy, "Buy", 1.0); //
 
Top