AmiBroker formula Language

kkseal

Well-Known Member
Ami doesn't support default values for parameters of user-defined functions/procedures. That is to say the in-built MACD(fpd=12, spd=26) works, but an user-defined KMACD(fpd=12, spd=26) does not.


This may help!

function KMACD(IP1,IP2)
{
if(IP1=null and IP2=null)
{IP1=____;
IP2=____;// default value here;
}
.................................
return result;
}

Hope this could help!
Tried that route (and also the IsNull function) but when you call the function - like in Plot(KMACD(),...) - it gives a 'Missing Arguments' error. (Actually the value-checking code is within the function whereas the argument check is done at the Call level itself; so doesn't work)

BTW, should use IP1 == null and IP2 == null or else Null will be assigned to args IP1 & IP2 irrespective of values passed.

Regards,
Kalyan.
 
Last edited:

kkseal

Well-Known Member
Can u please try function with "No parameters passed"

ie: function KMACD()
{if(IP1==0....
........
}

Arguments can be passed with universal variables!
When i use Plot(KMACD(),...) with no values within the parenthesis it's the same as calling the function with "No parameters/argument (values) passed" This as i said generates a " Missing Arguments" error. If i exclude the parenthesis and just use KMACD then it will be treated as an undefined identifier.

I had thought of the global variable route as well. Suppose i have an AFL called K_defaults.afl where all the default values are declared/defined. Let's say the defaults for the KMACD are def_fpd = 12 & def_spd = 26. Now i include this file everywhere i want to use the KMACD (a hassle in itself). Even then when i want to use the default values i'll have to use the function call as KMACD(def_fpd, def_spd). So no advantage. I might as well simply use KMACD(12,26) (saving me the first hassle).

Anyways, as i said, no big deal. And thanks for your suggestion.

Regards,
Kalyan.
 
hi to all,
i m new and i need:
today volume is greater than yesterday volume by 20 or 30%
to day price is greater than yesterday price
i want to create a corelation between price and volume
thnx to all for gr8 contribution
sharad
 
Hi all , can someone help me

How do i plot
1) A Sell arrow "when K% Cross down D% and it above 75% level"
2) A buy arrow " when K% Cross up D% and it below 25% level"

_SECTION_BEGIN("Slow Stochastic");
/*Slow Stochastic and Trendlines
for Indicator Builder,
by Dimitris Tsokakis*/
D1=14;
MaxGraph=8;
ST3=StochK(D1);
ST33=StochD(D1);
Graph0=ST3;
Graph1=ST33;
Title=Name()+" - %K="+WriteVal(st3,FORMAT=1.2)+", %D="+
WriteVal(ST33,FORMAT=1.2)+
WriteIf(Cross(st3,st33)," POSITIVE CROSS"," ")+
WriteIf(Cross(ST33,ST3)," NEGATIVE CROSS","");
x = Cum(1);
per = 0.1;
s1=st33;
s11=st33;
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
Graph6 = IIf(x>startt-1 AND TRENDLINES>0 AND TRENDLINES<100,trendlineS,-1e10);
Graph6Style = 1;
Graph6Color = 1;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
Graph7 = IIf(x>startT1-1 AND TRENDLINER>0 AND
TRENDLINER<100,trendlineR,-1e10);
Graph7Style = 1;
Graph7Color = 1;
PlotGrid( 75, colorGreen );
PlotGrid( 25, colorGreen );
_SECTION_END();
 
:) Hi Kalyan i am new the alf progamming so please
help me to write the amiborker formula
I want to filter the data condition is below

advance price =movingaverage(close,10)
decline price =movingaverage(close,10)
x=advance price/decline price
if x>.75 then conditionl=true
if x<.50 then conditionl=false
if conditionl=true and rsi(close,8) crosses above 30 then buy on close
if rsi(close,8) crosses below 65 then exitlong on close
if conditionl=false then exitlong on close
 
Last edited:

kkseal

Well-Known Member
:) Hi Kalyan i am new the alf progamming so please
help me to write the amiborker formula
I want to filter the data condition is below

advance price =movingaverage(close,10)
decline price =movingaverage(close,10)
x=advance price/decline price
if x>.75 then conditionl=true
if x<.50 then conditionl=false
if conditionl=true and rsi(close,8) crosses above 30 then buy on close
if rsi(close,8) crosses below 65 then exitlong on close
if conditionl=false then exitlong on close
From the pseudo-code you've provided x will always be equal to 1.

Seemingly, what you want is a MA for the UP days & a MA for the DN days. (Pretty much what the RSI does with the momentum, only it doesn't stop there)
However this needs confirmation from your side.

Regards,
Kalyan.
 
Last edited:
Hi kalyan thnx for quick response
the formula describe in "Trading Secrets of Inner cirlcle" by Andrew Goodwin book which is

Market Breadth Filtered 8 day RSI:
Rules:
1) Calculate the 10 day simple moving average of the number of advancing issues on
the NYSE. This number is available from most quote services, brokers and financial
television tickers. A ten day moving average is calculated by adding the last
ten days of advances and dividing this sum by 10.
2) Calculate the 10 day simple moving average of the number of declining issues on
the NYSE. Follow the same procedure that you did to calculate the 10 day moving
average of advances.
12 Trading Secrets of the Inner Circle
3) Divide the 10 day average of advances by the 10 day average of declines.
4) If the value of the division is greater than .75 or 75% then our market breadth filter
is considered positive.
5) If the value of the division is less than .50 then our market breadth filter is considered
negative.
6) If the breadth filter is positive then buy the S&P 500 contracts on the close of the
day when the 8 day RSI crosses from below to above 30.
7) Exit your long position if the 8 day RSI crosses from above to below 65.
8) Also exit your long position if the market breadth filter changes from positive to
negative.
Results and discussion of the Breadth Filtered 8 day RSI
This system adds a trend filter designed to get us out of the trade if market breadth
deteriorates while we are in the trade, but the 8 day RSI fails to provide us with an exit.
This technological advance allows us to get out of bad trades more quickly than we
would if we were trading the 8 day RSI system. Profit factor rises to 4.55 from the 3.29
of the basic system. Our net profit increases by $28,000 and our maximum drawdown
shrinks by nearly 65%. This system clearly improves the result of the basic system and
gives us a safer way to trade. However, the W/L ratio is still too low at .71. So let us
move to the "Market Wizard" version.
Treasury Note and Treasury Bill Filtered 8 day RSI:
These filters were adapted from a concept discussed by the great S&P trader, Marly
Schwartz who was interviewed in the trading book "Market Wizards." Schwartz suggests
trading S&P futures when both bonds and short paper are above their moving
averages. This model draws on Schwartz's concept, but we have added our own twist.
Market Wizard Filter 13
Rules:
1) Each Friday, record the close of the CBOT's ten-year note future. When the
Friday close of the ten-year note is greater than its 40 week moving average then
the note filter is positive. If Friday is a holiday, use whatever close is the last close
of the trading week.
2) Each Friday, record the close of the Treasury bill future. When Friday's closing
T'bill future price is greater than its 40 week moving average, then the short paper
filter is positive.
3) If the note filter and the bill filter are both positive then the interest rate component
is positive.
4) If the note filter and the bill filter are both negative then the interest rate composite
is negative.
5) If either the note filter or the bill filter is positive while the other is negative, the
last reading of the interest rate composite stays the same. A change in the reading
is only possible if both the note and the bill filter are above or below their moving
averages simultaneously at Friday's close.
6) If the interest rate composite is bullish, buy on the close of the day when the 8 day
RSI crosses from below to above the 40 buy line.
7) Exit your long trade if the 8 day RSI crosses from above to below the 75 sell line.
8) Exit your long trade if the interest rate composite changes from positive to negative
even if RSI has not given an exit signal yet.
 

kkseal

Well-Known Member
Mishphar, now that you have everything for the coding try doing it on your own (or else tomorrow you may come across another 'secret' & cry help for the coding)

Look up the following in Ami Help

Functions : AdvIssues, DecIssues, Cross

Reserved variables : Buy, Sell, Filter

Cut out all the fluff (colouring,shapes etc.) and just concentrate on the basic code. Not all that difficult.

Regards,
Kalyan.
 
Yes Kalyan u r correct but I am completely new for this programming it is not that I will grasp in one day everything I am trying at my best and reading now all the alf functions so it will take some time just u write the code once then i will try to practice next.
thnx for ur encouraging word.
 

Similar threads