AmiBroker formula Language

Hi to all! I'm new in this forum and I'll would to greetings to you!

I have a problem with a spunky indicator... :) I got already some advice but i feel that I can't do it by myself... :confused:
So I want to make a so simple thing...I want to put a fixed 30 min timeframe pricechart below two different timeframe stochastic indicator.... a 4 hour and a 1 day stoch...so the price chart have to stay in 30 min timeframe...
so thank your help...bye

pikk-pak

----------------

I made it...

So the 4 hourly looks like ---

TimeFrameSet(4*inHourly);
lassu= StochD(5,3,3);
gyors=StochK(5,3);
Plot (gyors, "Stoch 5,3,", colorBlue);
Plot (lassu, "Stoch 5,3,3", colorRed);

------------------

now i have another question
the 4 hourly scrolling faster than the daily...and it is not too good for me...I want that how so will be as the attachment...the bottom stock nice flat..

yesss...I made it :)

TimeFrameSet(4*inHourly);
_SECTION_BEGIN("stochastic 4 oras");
lassu= StochD(5,3,3);
gyors=StochK(5,3);
Plot(TimeFrameExpand(lassu, 4*inHourly),"Stoch 5,3,3", colorRed);
Plot(TimeFrameExpand(gyors, 4*inHourly), "Stoch 5,3", colorBlue);
_SECTION_END();

:D
 

Attachments

Last edited:
hello all,

i know nothing about programming and i'm trying to code a simple AFL system by modifying an existing one.

but it does not work, i dont know why. will very much appreciate if you can help me figure out the coding mistakes, thanks!:)


The function of this simple afl-script is simply to simultaneously place 2 set of orders (1 buy and 1 sell Bracket Orders) according to "previousclose", "inputvalue", "profittarget" and "trailstop" when initiated. it send order through InteractiveBrokers TWS.


SCRIPT:


InputValue1 = 50;
InputValue2 = 50;
profitTarget = 50;
trailStop = 50;
PreviousClose = 17000;

TodaysOpen = 17500;
OpenTime = 94500; //hhmmss (hh-hour, mm-minute, ss-sec->always00)


//param trigger button to reset status
resetStatus = ParamTrigger("resetStatus","resetStatus");
//START

DateNumNow = Now(3);

DN = DateNum();
TN = TimeNum();


/*





//TodaysOpen = StaticVarGet("TodaysOpen");
//if(IsEmpty(TodaysOpen))
{
for( i = 0; i < BarCount; i++ )
{
if(DN==DateNumNow AND TN==OpenTime)
{
StaticVarSet("TodaysOpen",Open);
}
}
}

TodaysOpen = StaticVarGet("TodaysOpen");
*/


//check if order placed
OrderPlaced = StaticVarGet("OrderPlaced");

if(resetStatus)
{
StaticVarSet("OrderPlaced",0);
}

OrderPlaced = StaticVarGet("OrderPlaced");



//display info
Title = WriteIf(NOT IsEmpty(TodaysOpen), "Today's Open is"+NumToStr(TodaysOpen,1.0), "")
+" PreviousClose is"+NumToStr(PreviousClose)
+"\n\nCurrentSetting:\nprofitTarget is "+NumToStr(profitTarget)
+" trailStop is"+NumToStr(trailStop)
+"\n\n"+WriteIf( (IsEmpty(OrderPlaced) OR OrderPlaced==0),"Order Not Created", "Order Created");


//check if order is triggered, place order if condition fullfiled
if( (IsEmpty(OrderPlaced) OR OrderPlaced==0) )
{

//Long side, place order
ibc = GetTradingInterface("IB");
IBcStatus = ibc.IsConnected();

if( IBcStatus )
{
StaticVarSet("OrderPlaced",1);
LimitBuy = PreviousClose+inputvalue1;
parentID = ibc.PlaceOrder(Name(), "BUY", 1, "LMT", LimitBuy, 0, "DAY", False );
ibc.PlaceOrder(Name(), "SELL", 1, "LMT", LimitBuy+profitTarget, 0, "DAY", False, 1, "", parentID );
ibc.PlaceOrder(Name(), "SELL", 1, "TRAIL", trailStop, trailStop, "DAY", True, 1, "", parentID );

}
//short side, place order
ibc = GetTradingInterface("IB");
IBcStatus = ibc.IsConnected();

if( IBcStatus )
{
StaticVarSet("OrderPlaced",-1);
LimitSell = PreviousClose+inputvalue2;
parentID = ibc.PlaceOrder(Name(), "SELL", 1, "LMT", LimitSell, 0, "DAY", False );
ibc.PlaceOrder(Name(), "BUY", 1, "LMT", LimitSell-profitTarget, 0, "DAY", False, 1, "", parentID );
ibc.PlaceOrder(Name(), "BUY", 1, "TRAIL", trailStop, trailStop, "DAY", True, 1, "", parentID );

}
}
 
Hi seniors,
i found a post in this forum by satya where he posted a program to calculate support resistance etc.
below is his post
Code:
Pivot, Support , Resistance Calculator 

--------------------------------------------------------------------------------

Friends,

just try this tool developed by me. It calculates automatically all the R3, R2, R1, Pivot , S1, S2, S3 points for the next day.

The input for this application is a flat file with stock quotes.
the zip files has 2 files

1. Pivot.exe the executable file you should run
2. stock.ini file, where you can store your favourite stocks(e.g infosys,hinlev,icici,wipro,satcom)

the names should match with the names in flat file.

let me know, if it works fine.
Satya
what i wanted is to plot the same using Amibroker AFL. is there any way to do it??
or else where can i find theory regarding the method to calculate R1, R2 etc..

regards
ashutosh

Sorry just read your post. Had such an afl completed just two days ago. The afl code for conventional (floor type) pivot/support/resistance points is as follows:


Code:
/*Pivot Points (floor type)*/

/*Graph section*/
pp=((H+L+C)/3);
r1=((2*pp)-L);
r2=(pp+(H-L));
r3=(H+(2*(pp-L)));
s1=((2*pp)-H);
s2=((pp-H)+L);
s3=(L-(2*(H-pp)));
Plot(pp,"Pivot point",ParamColor("Pivot Point",colorGold),styleNoLine);
Plot(r1,"R1",ParamColor("R1",colorRed),styleDots+styleNoLine);
Plot(r2,"R2",ParamColor("R2",colorRed),styleDots+styleNoLine);
Plot(r3,"R3",ParamColor("R3",colorRed),styleDots+styleNoLine);
Plot(s1,"S1",ParamColor("S1",colorLime),styleDots+styleNoLine);
Plot(s2,"S2",ParamColor("S2",colorLime),styleDots+styleNoLine);
Plot(s2,"S2",ParamColor("S3",colorLime),styleDots+styleNoLine);

/*Exploration section*/
Filter=V>0;
AddColumn(r3,"R3",1.2,colorBlack,colorGold);
AddColumn(r2,"R2",1.2,colorBlack,colorGold);
AddColumn(r1,"R1",1.2,colorBlack,colorGold);
AddColumn(pp,"Pivot",1.2,colorBlack,colorLavender);
AddColumn(s1,"S1",1.2,colorBlack,colorLime);
AddColumn(s2,"S2",1.2,colorBlack,colorLime);
AddColumn(s3,"S3",1.2,colorBlack,colorLime);

/*

Usage Notes:
1. To overlay the pivot point and support/resistance levels over price chart, just drag and drop.
2. To calculate pivot point and support/resistance levels in a tabulated form, just run an exploration. 

*/
 
Another thing that might work for BAV :-
...
PlotOHLC(H, H+20, H, H+20,,, styleLine)
...
Plot functions take arrays and plot them for all the bars(0 through BarCount-1). Hence the above mentioned step wont help, I guess.

Problem is Ami doesn't have a generic DRAW function.
Yes, and its surprising.

Also i suspect the built-in data arrays that are normally used in PLOT are actually (internally) 2-dimensional arrays in the form (BarIndex, ArrayValue) However i don't know if user-defined 2-D arrays can be used in Ami (probably not).
Plot takes One-dimentional arrays only. The index is taken internally from 0 to BarCount-1. All manipulations in Amibroker are in 1-D arrays.

As far as I know there are no 2-D arrays in Amibroker.

One (albeit imperfect) soln could be making x1 fractionally smaller (assuming float types are allowed) than x2.
The x co-ordinates in LineArray refers to the index of Bars. Hence float(fractions) are impossible.

Praveen.
 

kkseal

Well-Known Member
Plot functions take arrays and plot them for all the bars(0 through BarCount-1). Hence the above mentioned step wont help, I guess.
This is assuming BAV wants the vertical line for each bar (probably not as in that case he could simply use a band)

Yes, and its surprising.
More so when you know that such a function is used internally or we wouldn't be able to draw anything on the chart.


Plot takes One-dimentional arrays only.
Yes externally so, but i don't think it's the same internally as in that case it couldn't have taken linearray which has 2 distinct 2-D sets of values (x0,y0) & (x1,y1). As you see this in keeping with the general 2-D format (BarIndex, Value)

The index is taken internally from 0 to BarCount-1. All manipulations in Amibroker are in 1-D arrays.
Yes, the pre-defined arrays are 1D. It would be terribly inefficient to store the BarIndex value within each array. The BarCount can be accessed anytime from stack and once you have it the barindices will simply range from 0 to (Barcount-1).

The x co-ordinates in LineArray refers to the index of Bars. Hence float(fractions) are impossible.
Yes, i went through the function ref and saw it was indeed so. If 2-D arrays were usuable then we could have still tried defining an array with same X (BarIndex) but different Y and then tried feeding it to PLOT. But unfortunately it's not possible.

Regards,
Kalyan.
 
Yes externally so, but i don't think it's the same internally as in that case it couldn't have taken linearray which has 2 distinct 2-D sets of values (x0,y0) & (x1,y1). As you see this in keeping with the general 2-D format (BarIndex, Value)
Its again 1-D array. Linearray takes four 1-D array. There are no 2-D arrays, as far as I know.
 
Although its off-topic, its ok.

We can simulate 2-D arrays in Amibroker(AFL) using the following method, posted somewhere in Amibroker Yahoo groups.

Desired access to tablename[x][y] can be implemented as follows
using VarSet / VarGet (note that this is only ONE OF MANY possible
ways)

Example use:

Set2DimTable( "blabla", 2, 3, High[ 0 ] );

This actually shows how VarSet/VarGet can be used to implement
"equivalent of doubly dimensioned arrays i.e. tables in pure AFL".

*/

function Set2DimTable( tablename, x, y, value )
{
VarSet( tablename + StrFormat("%05.0f%05.0f", x, y ), value );
}

function Get2DimTable( tablename, x, y )
{
return VarGet( tablename + StrFormat("%05.0f%05.0f", x, y ) );
}
You can of course create any dimension "array" you want by using this
scheme.

Caution though, these operations are not very fast, so for limited
size "arrays" they aer ok, but for computation heavy operations they
are not well suited.
 

kkseal

Well-Known Member
Its again 1-D array. Linearray takes four 1-D array. There are no 2-D arrays, as far as I know.
In that case all 4 array elements would be Y(price or price derivative) values like as in PLOT(C) or PLOT(EMA(C,5)); but in the case of Linearray x0 & x1 correspond to barindices.

The only difference in the 2 cases is that in the case of predefined arrays (like C, H) the BarIndices are implicit while in the case of Linearray it's explicitly passed, the basic format for the parameter in both cases being (BarIndex, Y-Value).

Anyway these are just academic musings Doesn't solve BAVs problem.

Regards,
Kalyan.
 
Last edited:

kkseal

Well-Known Member
Although its off-topic, its ok.

We can simulate 2-D arrays in Amibroker(AFL) using the following method, posted somewhere in Amibroker Yahoo groups.
This is confirmation of the fact that 2D arrays cannot be defined & used in Ami the normal way.

It's also useless for our purpose as the 2 'array' elements are tied to a string and (above all) not being a true 2-D array will be unacceptable to PLOT.

Regards,
Kalyan.
 

Similar threads