Australian (ASX) Stock Market Forum

CanOz

Home runs feel good, but base hits pay bills!
Joined
11 July 2006
Posts
11,543
Reactions
519
I thought i might start this thread to place some interesting code that i come across in other forums etc. Makes it a little easier to find and we can share interesting things as well.

This code looks for line that you've drawn as support or reistance. I have not tried this yet, but just thought some might find it interesting....

Cheers,


CanOz

Code:
  //------------------------------------------------------------------------------ 
// 
//  Formula Name:    half-automated Trading System 
//  Author/Uploader: Thomas Zmuck  
//  E-mail:          thomas.zm@aon.at 
//  Date/Time Added: 2001-12-21 16:45:47 
//  Origin:           
//  Keywords:        half-automated Trading System 
//  Level:           basic 
//  Flags:           system,exploration 
//  Formula URL:     http://www.amibroker.com/library/formula.php?id=142 
//  Details URL:     http://www.amibroker.com/library/detail.php?id=142 
// 
//------------------------------------------------------------------------------ 
// 
//  This System finds stocks, where the price reached a support or resistance 
//  line, that you have manually drawn. 
// 
//  You must give every line any of these 6 predifined StudyID's 
// 
//  (RE,SU,UP,DN,RI,ST). The system automaticaly detects, if the line is 
//  currently a support or resistance line. 
// 
//  There are two modes: Modus == 0; I called it "after touching" , because you 
//  become the signal after the stock has touched any support or resistance 
//  line.Adjustment for touching is "ALvalue and AHvalue" With ALvalue you can 
//  define, how near the Low must go to any support line, equivalent AHvalue to 
//  resistance line, before a signal is given. 
// 
//  With Modus == 1 "bLvalue and bHvalue" you can detect stocks, where the 
//  price is before touching any line, so you mostly can find signals for the 
//  next trading day and so you have enough time to check other arguments and 
//  then you can buy at the exact support Level or sell at the exact resistance 
//  level. 
// 
//  Cross_buy_value = 1.03; Cross_sell_value = 0.97; 
// 
//  Here you can define the value, where the price must reached, before a 
//  signal would be generated. For example: 1.03 means that a buy signal is 
//  given, when the price is 3% above the last resistance. equivalent the 
//  cross_sell_value. 
// 
//  With the Explore Function you can see the distance from the current close 
//  to all support and resistance lines in percent. 
// 
//  Re = Resistance Su = Support 
// 
//  In the indicator window you can see the close and all your study's 
//  (currently 6 study's possible). 
// 
//  So you can quickly see, if you've forgotten to give a study ID to any line. 
// 
//  Attention: Dont forget, that the back-test brings unrealistic results, 
//  because the signals only real at the time that you've drawn the study. 
// 
//  Also dont forget in the explore window, that only the resistance and 
//  support distances are shown, that you have drawn and defined with a study 
//  ID. 
// 
//  So enjoy it! 
// 
//  Every comments are welcome 
// 
//------------------------------------------------------------------------------ 
 
Modus = 0;  
/*Modus 0 = after touching (bLvalue and bHvalue)*/ 
/*Modus 1 = before touching* (ALvalue and AHvalue)*/  
bLvalue = 1.06;   ALvalue = 1.02; 
bHvalue = 0.93;   AHvalue = 0.99; 
 
Cross_buy_value  = 1.03; 
Cross_sell_value = 0.97; 
/*this is the value, where a line cross is defined as true, it's a way to ignore false breakout's  default = 3 % */ 
 
MLV = IIf (Modus ==0, ALvalue, 
bLvalue);/*Modus_Low_value */ 
MHV = IIf (Modus ==0, AHvalue, bHvalue);/*Modus_High_value */ 
 
/*Study - Definition  - give your name's */ 
L1 = Study ("SU"); L2 = Study ("RE"); L3 = Study ("DN"); 
L4 = Study ("UP"); L5 = Study ("RI"); L6 = Study ("ST"); 
 
/*Buy Conditions*/ 
N1 = L <= MLV * L1 AND IIf(Modus == 1,L >= Alvalue * L1,C>0) AND C > L1 AND Ref (L,-1)>L1; 
N2 = L <= MLV * L2 AND IIf(Modus == 1,L >= Alvalue * L2,C>0) AND C > L2 AND Ref (L,-1)>L2; 
N3 = L <= MLV * L3 AND IIf(Modus == 1,L >= Alvalue * L3,C>0) AND C > L3 AND Ref (L,-1)>L3; 
N4 = L <= MLV * L4 AND IIf(Modus == 1,L >= Alvalue * L4,C>0) AND C > L4 AND Ref (L,-1)>L4; 
N5 = L <= MLV * L5 AND IIf(Modus == 1,L >= Alvalue * L5,C>0) AND C > L5 AND Ref (L,-1)>L5; 
N6 = L <= MLV * L6 AND IIf(Modus == 1,L >= Alvalue * L6,C>0) AND C > L6 AND Ref (L,-1)>L6; 
 
P1 = C > L1*Cross_buy_value AND (Ref (C,-1)<L1 OR Ref (C,-2)<L1); 
P2 = C > L2*Cross_buy_value AND (Ref (C,-1)<L2 OR Ref (C,-2)<L2); 
P3 = C > L3*Cross_buy_value AND (Ref (C,-1)<L3 OR Ref (C,-2)<L3); 
P4 = C > L4*Cross_buy_value AND (Ref (C,-1)<L4 OR Ref (C,-2)<L4); 
P5 = C > L5*Cross_buy_value AND (Ref (C,-1)<L5 OR Ref (C,-2)<L5); 
P6 = C > L6*Cross_buy_value AND (Ref (C,-1)<L6 OR Ref (C,-2)<L6); 
 
/*Sell Conditions*/ 
Q1 = H >= MHV * L1 AND IIf(Modus == 1,H <= AHvalue * L1,C>0) AND C < L1 AND Ref (H,-1)<L1; 
Q2 = H >= MHV * L2 AND IIf(Modus == 1,H <= AHvalue * L2,C>0) AND C < L2 AND Ref (H,-1)<L2; 
Q3 = H >= MHV * L3 AND IIf(Modus == 1,H <= AHvalue * L3,C>0) AND C < L3 AND Ref (H,-1)<L3; 
Q4 = H >= MHV * L4 AND IIf(Modus == 1,H <= AHvalue * L4,C>0) AND C < L4 AND Ref (H,-1)<L4; 
Q5 = H >= MHV * L5 AND IIf(Modus == 1,H <= AHvalue * L5,C>0) AND C < L5 AND Ref (H,-1)<L5; 
Q6 = H >= MHV * L6 AND IIf(Modus == 1,H <= AHvalue * L6,C>0) AND C < L6 AND Ref (H,-1)<L6; 
 
R1 = C < L1*Cross_sell_value  AND (Ref (C,-1)>L1 OR Ref (C,-2)>L1); 
R2 = C < L2*Cross_sell_value  AND (Ref (C,-1)>L2 OR Ref (C,-2)>L2); 
R3 = C < L3*Cross_sell_value  AND (Ref (C,-1)>L3 OR Ref (C,-2)>L3); 
R4 = C < L4*Cross_sell_value  AND (Ref (C,-1)>L4 OR Ref (C,-2)>L4); 
R5 = C < L5*Cross_sell_value  AND (Ref (C,-1)>L5 OR Ref (C,-2)>L5); 
R6 = C < L6*Cross_sell_value  AND (Ref (C,-1)>L6 OR Ref (C,-2)>L6); 
/*Buy & Sell PART*/ 
Buy = N1 OR N2 OR N3 OR N4 OR N5 OR N6 OR  
      P1 OR P2 OR P3 OR P4 OR P5 OR P6; 
Sell = Q1 OR Q2 OR Q3 OR Q4 OR Q5 OR Q6 OR  
       R1 OR R2 OR R3 OR R4 OR R5 OR R6; 
/*Explore-Part*/ 
L1_diff =  (L1/ C -1)*100; 
L2_diff =  (L2/ C -1)*100; 
L3_diff =  (L3/ C -1)*100; 
L4_diff =  (L4/ C -1)*100; 
L5_diff =  (L5/ C -1)*100; 
L6_diff =  (L6/ C -1)*100; 
 
Filter = Buy OR Sell; 
 
AddColumn( L1_diff,  WriteIf (C > L1 ,"Su1_%", "Re1_%"),1.1 ); 
AddColumn( L2_diff,  WriteIf (C > L2 ,"Su2_%", "Re2_%"),1.1 ); 
AddColumn( L3_diff,  WriteIf (C > L3 ,"Su3_%", "Re3_%"),1.1 ); 
AddColumn( L4_diff,  WriteIf (C > L4 ,"Su4_%", "Re4_%"),1.1 ); 
AddColumn( L5_diff,  WriteIf (C > L5 ,"Su5_%", "Re5_%"),1.1 ); 
AddColumn( L6_diff,  WriteIf (C > L6 ,"Su6_%", "Re6_%"),1.1 ); 
 
/*Graph-Part*/ 
Plot (C,"close",1,64); 
Plot (L1,"L1",2,1);/*white*/ 
Plot (L2,"L2",5,1);/*green*/ 
Plot (L3,"L3",7,1);/*yellow*/ 
Plot (L4,"L4",4,1);/*red*/ 
Plot (L5,"L5",6,1);/*blue*/ 
Plot (L6,"L6",9,1);/*orange*/
 
Gee...where do I start ;)

Karthik released some new code a week ago which may be of interest to anyone who has had a look at his VPA code. He calls it "Effort Index". I've been looking at it for a few days in conjunction with the modified version of his VPA code I use for trading futures. I've noticed a few "heads up" signals from it but nothing startling at this stage. His blog has an explanation of how to use it, as well as a video.

http://karthikmarar.blogspot.com.au/2013/06/effort-index-afl.html

http://karthikmarar.blogspot.com.au/2013/06/my-latest-video-on-latest-indicator.html

Karthik doesn't hide his code behind DLL's or proprietary code so anyone is free to use it and adjust it as they need which fits in well with my open source software philosophy :)

A liitle about Karthik and why he's happy to share his work:

http://karthikmarar.blogspot.com.au/2012/07/the-first-question-that-would-arise.html

Here's the code:

Code:
//Volume Price Analysis - Effort Verus Result Index Afl  - Version 1.0
// Afl by Karthikmarar
// www.karthikmarar.blogspot.com
//============================================================
_SECTION_BEGIN("Effort versus Result - V.1.0");
//SetChartBkColor(colorWhite); 
SetChartOptions(0,chartShowArrows|chartShowDates);
Vlp  = Param("Volume lookback period",40,20,200,10);
Vrg  = MA(V,Vlp);// average volume
rg   = (H-L); //Spread
arg  = Wilders(rg,Vlp);//Average Spread
rs   = abs(C-Ref(C,-1));//Result
rsg  = Wilders(rs,Vlp);//Average Result
sro  = rg/arg;//ratio of spread to average
Vro  = V/Vrg;//ratio of volume to average
rso  = rs/rsg; //ratio of result to average
smax = HHV(sro,Vlp);
smin = LLV(sro,Vlp);
Vmax = HHV(Vro,Vlp);
Vmin = LLV(Vro,Vlp);
rmax = HHV(rso,Vlp);
RMIn = LLV(rso,Vlp);
snor = (sro - smin)*100/(smax-Smin);
Vnor = (Vro - Vmin)*100/(Vmax-Vmin);
rnor = (rso - RMIn)*100/(rmax-RMIn);
EI   = rnor/Vnor;

SelectedIndicator = ParamList( "Show", "Raw Effort-Result,Effort Index", 1 );
SelectedResult = ParamList( "Select", "Spread,Bar to Bar", 1 );
switch ( SelectedIndicator )
{ 
case "Raw Effort-Result":
switch ( SelectedResult )
{

case "Spread":
SetBarFillColor( colorOrange ); 
PlotOHLC(0,snor,0,snor,"Result",IIf(C>Ref(C,-1),colorLime,colorRed), styleCandle |styleThick) ;
Plot(MA(snor,Vlp),"Avg Result",colorYellow,1|styleDashed|styleThick);
SetBarFillColor( colorGreen ); 
PlotOHLC(0,-Vnor,0,-Vnor,"Effort",IIf(C>Ref(C,-1),colorLime,colorRed), styleCandle|styleThick ) ;
Plot(MA(-Vnor,Vlp),"Avg Effort",colorTurquoise,1|styleDashed|styleThick);
break;
case "Bar to Bar":
SetBarFillColor( colorOrange ); 
PlotOHLC(0,rnor,0,rnor,"Result",IIf(C>Ref(C,-1),colorLime,colorRed), styleCandle |styleThick) ;
Plot(MA(rnor,Vlp),"Avg Result",colorYellow,1|styleDashed|styleThick);
SetBarFillColor( colorGreen ); 
PlotOHLC(0,-Vnor,0,-Vnor,"Effort",IIf(C>Ref(C,-1),colorLime,colorRed), styleCandle|styleThick ) ;
Plot(MA(-Vnor,Vlp),"Avg Effort",colorTurquoise,1|styleDashed|styleThick);

break;
}
break;
case "Effort Index":
SetBarFillColor( colorGreen ); 
PlotOHLC(0,EI,0,EI,"Effort Index",colorTurquoise, styleCandle|styleThick ) ;
break;
}
_SECTION_END();
 
Thanks Captain, much appreciated!:xyxthumbs

CanOz
 
I've noticed a few "heads up" signals from it but nothing startling at this stage.

Just to expand on that a bit. I've noticed in consolidation zones on the Kospi where the effort index gives a higher than average result on very low volume bars that close on their high or low indicating that supply or demand has dried up and it signals a move before an actual breakout from the zone. The VPA code tends to give a cluster of signals in a consolidation zone anyway but in conjunction with the effort index it could be worth further investigation and some work on the code.
 
Just to expand on that a bit. I've noticed in consolidation zones on the Kospi where the effort index gives a higher than average result on very low volume bars that close on their high or low indicating that supply or demand has dried up and it signals a move before an actual breakout from the zone. The VPA code tends to give a cluster of signals in a consolidation zone anyway but in conjunction with the effort index it could be worth further investigation and some work on the code.

Yeah, some interesting spikes on EOD stuff as well, just eyeballing charts with it.
 
Yeah, some interesting spikes on EOD stuff as well, just eyeballing charts with it.

Ah, excellent, hope you find it useful. I've only had a look at it this week with the Kospi, I'll have a look at some EOD charts over the weekend.

I'll try to post some other code in this thread if people are interested. Don't want it to turn into just a discussion of VPA. I just posted Karthik's code because it's quite new and interesting. Hopefully this thread will add to the extensive Amibroker resources that are already in ASF :)
 
Yeah, there is allot code out there but unfortunately some of it has errors in, so i thought if i run it over the syntax check then at least the stuff we post on here should be ok.

CanOz
 
Ah, excellent, hope you find it useful. I've only had a look at it this week with the Kospi, I'll have a look at some EOD charts over the weekend.

I'll try to post some other code in this thread if people are interested. Don't want it to turn into just a discussion of VPA. I just posted Karthik's code because it's quite new and interesting. Hopefully this thread will add to the extensive Amibroker resources that are already in ASF :)

Always interested in your postings CB your accuracy is always most welcome, please post away.

Great thread Can
 
Always interested in your postings CB your accuracy is always most welcome, please post away.

Thanks IFocus, much appreciated. I'll go through my library and links of Amibroker stuff over the weekend and see what I can find. There's a lot of code in TJ's AFL library and other places easily available so I'll try and find some that I've modified myself or that isn't easy to find like Karthik's code I posted above.

Great thread Can

+1

Threads such as these and postings on the Ami Yahoo list are how I learned to code with Ami. I do a bit of work with open source software and Linux as well and get a lot of enjoyment from sharing coding ideas.
 
Hey All,

Just playing around on Amibroker and getting a feel for it. How do I create a formula to scan for Stocks which I just have added that there share price is less then .005 cents?.

Thanks
 
Hey All,

Just playing around on Amibroker and getting a feel for it. How do I create a formula to scan for Stocks which I just have added that there share price is less then .005 cents?.

Thanks

Try the Amibroker help thread for this sort of question.

Filter = C<.005;
Adccolumn(C,"close");
Addcolumn(C*V, "indicative turnover");

Then hit EXPLORE
 
Code:
// double doji exploration 
// By Boufalo Ver. 1.00   
// 
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), ParamStyle("Style") | GetPriceStyle() ); 
 
doji = (O == C);
NearDoji1 = (abs(O-C)<= ((H-L)*0.1));
NearDoji2 =NearDoji1 AND Ref(NearDoji1,-1);
NearDoji3 =NearDoji1 AND Ref(NearDoji1,-1) AND Ref(NearDoji1,-2);
 
  showDoji = ParamToggle("NearDoji ","SHOW|HIDE",1);
    if( showDoji )
    {
    PlotShapes( shapeDigit0*doji , colorGreen, 0, H, 45 );  
    PlotShapes( shapeDigit1*NearDoji1  , colorBlue, 0, H, 30 );    
    PlotShapes( shapeDigit2*NearDoji2 , colorOrange, 0, H, 30 );    
    PlotShapes( shapeDigit3*NearDoji3, colorBrightGreen, 0, H, 30 );  
    }
 
 
Filter = NearDoji2 OR NearDoji3 ;
 
AddColumn (NearDoji1 ,"1Doji ",1);
AddColumn (NearDoji2 ,"2Doji ",1);
AddColumn (NearDoji3 ,"3Doji ",1);
 
Try the Amibroker help thread for this sort of question.

Filter = C<.005;
Adccolumn(C,"close");
Addcolumn(C*V, "indicative turnover");

Then hit EXPLORE

Thanks

- - - Updated - - -

Hey There

Thanks for the formula I gave it a go but nothing came up when I hit explore, sorry to be privately messaging you.


Try the Amibroker help thread for this sort of question.

Filter = C<.005;
Addccolumn (C,"close");
Addcolumn (C*V, "indicative turnover");

Then hit EXPLORE
 
Hi Guys,

Does anyone have/know how to write code to buy when the EMA of volume moves above/below a certain multiple of the EMA value...eg buy XYZ when volume is 2 X's the volume EMA value.

And yes I am a newbie
 
Hi Guys,

Does anyone have/know how to write code to buy when the EMA of volume moves above/below a certain multiple of the EMA value...eg buy XYZ when volume is 2 X's the volume EMA value.

And yes I am a newbie

a = EMA(V,10);//10 day EMA of volume
aa = Ref(a,-1);//yesterday's value
Buy = V/2>aa;
 
Hello all,

I just purchased Amibroker along with Norgate Premium Data for ASX end of day data. I worked through Howard Bandy's v. useful "Introduction to Amibroker" publication. My main issue/hurdle is learning how to code using Amibroker's AFL. I have never done anything like this before and thought I'd start gently by attempting to filter for all stocks that have made a new 52 week high for week ending 9 May 2014. I wrote the following in the formula editor (referencing Mr Bandy's example5.afl and modifying to my requirement) :

Liquidity = MA ( C * V, 21 );
New52High = High == HHV ( C, 52 );

Filter = Liquidity >= 100000;
AddColumn ( New52High, "52 High", 1.0 );

I ran an Explore on this - Apply To *All symbols with - Range 1 recent bar(s).
The results gave me stocks which did not reach new 52 week highs as of week ending 9 May. I am honestly clueless. I had set my chart to Weekly for this formula. I had also attempted various iterations by choosing 260 and setting the charts to Daily; removing the liquidity requirement.

I have already searched the Amibroker support site but cannot begin to understand the AFL language that is spoken :( Would appreciate any help or suggestions on where I can get more help in plain english. :banghead:

THanks in advance.
 
Hello all,

I just purchased Amibroker along with Norgate Premium Data for ASX end of day data. I worked through Howard Bandy's v. useful "Introduction to Amibroker" publication. My main issue/hurdle is learning how to code using Amibroker's AFL. I have never done anything like this before and thought I'd start gently by attempting to filter for all stocks that have made a new 52 week high for week ending 9 May 2014. I wrote the following in the formula editor (referencing Mr Bandy's example5.afl and modifying to my requirement) :

Liquidity = MA ( C * V, 21 );
New52High = High == HHV ( C, 52 );

Filter = Liquidity >= 100000;
AddColumn ( New52High, "52 High", 1.0 );

I ran an Explore on this - Apply To *All symbols with - Range 1 recent bar(s).
The results gave me stocks which did not reach new 52 week highs as of week ending 9 May. I am honestly clueless. I had set my chart to Weekly for this formula. I had also attempted various iterations by choosing 260 and setting the charts to Daily; removing the liquidity requirement.

I have already searched the Amibroker support site but cannot begin to understand the AFL language that is spoken :( Would appreciate any help or suggestions on where I can get more help in plain english. :banghead:

THanks in advance.

I've forgotten most of what used to know but:

Liquidity = MA ( C * V, 21 );
New52High = High > ref( HHV ( C, 52 ),-1);

Filter = Liquidity >= 100000 AND New52High;
AddColumn ( New52High, "52 High", 1.0 );

Should get you a little closer.
 
Hello all,

I just purchased Amibroker along with Norgate Premium Data for ASX end of day data. I worked through Howard Bandy's v. useful "Introduction to Amibroker" publication. My main issue/hurdle is learning how to code using Amibroker's AFL. I have never done anything like this before and thought I'd start gently by attempting to filter for all stocks that have made a new 52 week high for week ending 9 May 2014. I wrote the following in the formula editor (referencing Mr Bandy's example5.afl and modifying to my requirement) :

Liquidity = MA ( C * V, 21 );
New52High = High == HHV ( C, 52 );

Filter = Liquidity >= 100000;
AddColumn ( New52High, "52 High", 1.0 );

I ran an Explore on this - Apply To *All symbols with - Range 1 recent bar(s).
The results gave me stocks which did not reach new 52 week highs as of week ending 9 May. I am honestly clueless. I had set my chart to Weekly for this formula. I had also attempted various iterations by choosing 260 and setting the charts to Daily; removing the liquidity requirement.

I have already searched the Amibroker support site but cannot begin to understand the AFL language that is spoken :( Would appreciate any help or suggestions on where I can get more help in plain english. :banghead:

THanks in advance.

Chart time frame and time frame of analysis are independent! So go to backtest settings "General" tab and set periodicity there.
In the code I have added New52High AND Status( "LastBarInRange" ) to Filter. New52high is main condition since you want to filter stocks that actually made a new high so you have to add that condition to filter too. Status( "LastBarInRange" ) is the same as tool bar setting "Range: 1 recent bar(s)" but just applied via code level. As visual confirmation I have added time frame column. In addition I have replaced New52High with high price array. New52High is a condition (boolean http://en.wikipedia.org/wiki/Boolean_data_type ) that will return 0 (false) or 1 ( true) but not a price. I have kept HHV( C, 52 ) unchanged but you probably want to make equality check with HHV( H, 52 ). So just change to that if so.

Code:
// Set "Periodicity" to "Weekly" in BACKTEST settings of analysis window
// Chart time frame and time frame of analysis are *independent*!

Liquidity = MA ( C * V, 21 );
New52High = High == HHV( C, 52 );

Filter = Liquidity >= 100000 AND New52High AND Status( "LastBarInRange" );
AddTextColumn ( Interval( 2 ), "Time Frame", 1.0 );
AddColumn ( High, "52 High", 1.2 );


image.png
 

Attachments

  • image.png
    image.png
    9.3 KB · Views: 6
Top