Perl scripts for Amibroker

milind

Active Member
#1
Hello All,

Java scripts have horrible performance doing anything other than trivial jobs with Amibroker. Besides I am not familiar with the language - but I know Perl. So I started out writing some utilities I needed to manage my Amibroker database. I will post them here as and when I develop them. Hopefully someone will find some use. If you are like me, coming from Unix background, and have some similar Perl scripts for Amibroker, please share. I googled and no hits.

You need to have cygwin installed on your computer, along with Perl and Perl Win32 module.

-- Milind
 

milind

Active Member
#2
This script changes groupIds of the symbols. A textfile is required listing symbols and groupId. Sure, you can do it with organize assignments in Amibroker. But I am learning perl scripting through some simple exercises, right?

#!/bin/perl

use Win32::OLE;
#my $server = Win32::OLE->new('Broker.Application','Quit');
my $server = Win32::OLE->new('Broker.Application','');
my $stocks = $server->Stocks;

# Do a hash of index vs ticker
for ($i=0; $i < $stocks->Count; $i++) {
$ticker = $stocks->Item($i)->Ticker;
$iticker{$ticker} = $i;
$groupId{$ticker} = $stocks->Item($i)->GroupID;
}

# Read file mapping new groupIds
open(FIN,"<bsenseintra.txt");
while (<FIN>) {
split;
$ticker = $_[0];
$ngroupId = $_[1];
if (defined($groupId{$ticker})) {
print "$ticker $groupId{$ticker} $_[1]\n";
$stock = $stocks->Item($iticker{$ticker});
$stock->{GroupID} = $_[1] + 0;
}
else {
print "ticker $ticker notfound\n";
}
}
close FIN;
exit;
 
#3
Hi millind,

Just wondering if you got any further with your work on perl. I'm an intermediate/advance perl coder and am interested in doing some stuff in perl for my mother.

I'm very new to amibroker and would be interested in any other example code that you may have.

Cheers

Stickman77
 

milind

Active Member
#4
Stickman77,

I wrote a few test scripts that time. But later familiarized myself with Visual Basic (there is a free version available from microsoft). I am using that now. So no more perl scripts for amibroker. Of course, if I need to do any serious text processing, I may need to come back to perl.

-- Milind

Hi millind,

Just wondering if you got any further with your work on perl. I'm an intermediate/advance perl coder and am interested in doing some stuff in perl for my mother.

I'm very new to amibroker and would be interested in any other example code that you may have.

Cheers

Stickman77
 

Ajax

Well-Known Member
#5
Hi Milind

Just saw your Market Profile Afl.
Displays nicely

Few queries!
How can we use Alphabets for periods
ANd Value areas (70% of total PO)

Regards

Ajax
 

milind

Active Member
#6
Hi Milind

Just saw your Market Profile Afl.
Displays nicely

Few queries!
How can we use Alphabets for periods
ANd Value areas (70% of total PO)

Regards

Ajax
I tried to do alphabets, but found out that amibroker doesn't display characters nicely for variable scales of the chart. Fontsize, spacing becomes a problem. So I reversed back to something simpler.

Value area - I know the way to do it, just haven't gotten around to it.

-- Milind
 

Ajax

Well-Known Member
#8
I tried to do alphabets, but found out that amibroker doesn't display characters nicely for variable scales of the chart. Fontsize, spacing becomes a problem. So I reversed back to something simpler.

Value area - I know the way to do it, just haven't gotten around to it.

-- Milind
Ok . Will wait for your inputs..

Here in color code for Market Profile.. It displays on 2 days.
Picked from the net. Dont know much about coding
Hope you find it useful....


//................

SetChartOptions(3, chartShowDates);
//SetChartOptions( 0);//3 , chartShowDates ); for y axis

GfxSetOverlayMode( mode = 1 );

nn = StrToNum(ParamList("Days", "1|2|3", 1));
box = Param("step", 10, 1, 100, 1)*TickSize;

NewDay = Day()!= Ref(Day(), -1);
DH = LastValue(HighestSince(NewDay, H, nn));
DL = LastValue(LowestSince(NewDay, L, nn));
Range = DH - DL;
steps = ceil(Range/box); // linage
height = Status("pxheight") - 50; // width of the profile (indention overhand 30 from below 20 pixels)
boxheight = LastValue(height/steps); // size of the box

width = (Status("pxwidth")-110)/3; // offset of the profiles

bars = Highest(BarsSince(NewDay));
ColorStep = LastValue(185/bars);

//
L = IIf(C > Ref(C, -1) AND L > Ref(C, - 1) AND NOT NewDay, Ref(C, -1), L);
H = IIf(C < Ref(C, -1) AND H < Ref(C, - 1) AND NOT NewDay, Ref(C, -1), H);

function GetDayPrice( fild, shift)
{
DayPrice = LastValue(TimeFrameGetPrice(fild, inDaily, -shift));
return DayPrice;
}

function pixlev(price)
{
result = 30 + (DH - price)/box * boxheight;
return result;
}

procedure PlotProfile(DH, DL, begini, endi, disp)
{
m = 0;
for(j = DH; j > DL; j = j-box)
{
n = 0;
for(i = begini; i < endi; i++)
{
if(H >= j AND L <= j)
{
GfxSelectPen( colorBlack, 1, 0);
GfxSelectSolidBrush(ColorHSB((i-begini)*ColorStep, 255, 255));
GfxRectangle( disp+n*boxheight, 30+m*boxheight, disp+(n+1)*boxheight, 30+(m+1)*boxheight);
n++;
}
}
m++;
}
}

procedure PlotLine(x1, y1, x2, y2, Color)
{
GfxSelectPen(Color, 1, 0);
GfxPolyline( x1, y1, x2, y2);
}

procedure PlotRect(x1, y1, x2, y2, Color)
{
GfxSelectPen(Color, 0, 5);
GfxSelectSolidBrush(Color);
GfxRectangle(x1, y1, x2, y2);
}

procedure PlotPrice(Text, FontName, FontSize, Color, x, y, yAlign, xAlign)
{
GfxSetBkMode(1);
GfxSetTextColor(Color);
GfxSetTextAlign( xAlign|yAlign);
GfxSelectFont(FontName, FontSize, 600); // dont work orientation
GfxTextOut(Text, x, y);
}
//
for(q = nn; q > 0; q--)
{
begini = LastValue(ValueWhen(NewDay, BarIndex(), q));
endi = LastValue(IIf(q == 1, BarCount, ValueWhen(NewDay, BarIndex(), q-1)));
PlotRect(50 + width*(nn-q), pixlev(GetDayPrice("H", q-1)), // day range
50 + width*(nn-q+1), pixlev(GetDayPrice("L", q-1)), colorLightYellow);
PlotRect(50 + width*(nn-q), pixlev(GetDayPrice("O", q-1)), // open-close range
50 + width*(nn-q+1), pixlev(GetDayPrice("C", q-1)),
IIf(GetDayPrice("O", q-1) > GetDayPrice("C", q-1), ColorHSB(15, 40, 255),
ColorHSB(80, 40, 255)));
PlotLine(50 + width*(nn-q), pixlev(GetDayPrice("C", q-1)), // close line
50 + width*(nn-q+1), pixlev(GetDayPrice("C", q-1)),
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), colorRed, colorGreen));
PlotProfile(DH, DL, begini, endi, 50 + width*(nn-q));
PlotLine(50 + width*(nn-q), height+40, 50 + width*(nn-q), 0, colorBlack); // vertical line
PlotPrice( " close " + NumToStr(GetDayPrice("C", q-1))+" ", "Tahoma", 10, // plot close price
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), colorRed, colorGreen),
50+width*(nn-q+1), pixlev(GetDayPrice("C", q-1)),
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), 0, 8), 2);
PlotPrice( " open " + NumToStr(GetDayPrice("O", q-1))+" ", "Tahoma", 10, // plot open price
colorBlack, 50+width*(nn-q+1), pixlev(GetDayPrice("O", q-1)),
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), 8, 0), 2);
PlotPrice( " "+NumToStr(GetDayPrice("H", q-1)), "Tahoma", 10, // plot high price
colorBlack, 50+width*(nn-q), pixlev(GetDayPrice("H", q-1)), 8, 0);
PlotPrice(" "+NumToStr(GetDayPrice("L", q-1)), "Tahoma", 10, // plot low price
colorBlack, 50+width*(nn-q), pixlev(GetDayPrice("L", q-1)), 0, 0);
}

//...............

Ajax:cool:
 

Similar threads