Hey so I desparetly need some help with understanding the function of the formulas on amibroker. Its been a week of no progress.. and I cant handle it. Ive ordered a book by Howard Bandy, hopefully it aids in my understanding of formula functions along the way.

So I do not understand what formula I have to use for my momentum strategy (wysiwyg helped me abit but out of embaressment I didnt want to ask him to expand on his example).

I want one of my conditions of entering a trade to be if a new 52 week high occurs. Im assuming i have to use the HHV formula . I understand the first function in the formula is for the number of days to include, for example 250 days. The second part confusws me. Say for example I want to enter after the 2nd or 3rd day if it doesnt go below the 1st days low or close. Is that a completely different formula combined or is that part of the HHV formula.

Also do I have to put a sell function for the program to work? Thank you and sorry for the newbness of the question. I just cant handle a lack of progress and direction.

A learners guide.- AFL Example.
Hope it is of some help.

http://www.amibroker.com/library/det...7&hilite=Cross

Hi,

Perhaps try something like below. If you're going to do backtesting, then yes you need a Buy and Sell statement. The buy below says buy if today's close is greater than the 250 closes before (going back from yesterdays - you don't usually want to include today's close in such a statement). The 2nd part of the buy statement is "buy if close is greater than yesterday's Low).

The sell is a simple "sell if below 20 day moving average of closing price).
You don't really need the first 7 lines, but their an example of how to simulate a maximum of 10 open positions, trading the next day (for buy and sells), and some randomising code for your optimising runs.

Go nuts and play.....!

PS = Optimize( "Postion Score", 1, 1, 1000, 1 );
PositionScore = Random() * PS;

Positions = 10;
SetOption( "InitialEquity", 100000 );
SetOption( "MaxOpenPositions", Positions );
SetTradeDelays( 1, 1, 1, 1 );
SetPositionSize( 100/Positions, spsPercentOfEquity ); //Compounding profits and return

Sell = C<MA(C,20);

Thanks superglue. The problem is I dont fully understand the simple definitions the afl library goves out hence the dilemma.

Thanks newt. Thats perfect. Did you figure the formulas out through trial and error or is their a specific book which gives you examples of each formula as youve clearly done? Or a website?

You gotta read and comprehend just like math or english in school. Then write your thoughts on a piece of paper or type in wordpad. Then look at the various functions in the categorised list of functions, User Guide. Spoon fed learns nothin.
http://www.amibroker.com/guide/h_portfolio.html

OR

Originally Posted by darkhorse70
I understand the first function in the formula is for the number of days to include, for example 250 days. The second part confusws me. Say for example I want to enter after the 2nd or 3rd day if it doesnt go below the 1st days low or close. Is that a completely different formula combined or is that part of the HHV formula.
.
What formula are you talking about?

HHV
- highest high value Lowest/Highest

SYNTAX hhv( ARRAY, periods )
RETURNS ARRAY
FUNCTION Calculates the highest value in the ARRAY over the preceding periods (periods includes the current day). HHV accepts periods parameter that can be constant as well as time-variant (array).
EXAMPLE The formula "hhv( close, 4)" returns the highest closing price over the preceding four periods; "hhv( high, 8)" returns the highest high price over the preceding eight periods.

Originally Posted by darkhorse70
Thanks superglue. The problem is I dont fully understand the simple definitions the afl library goves out hence the dilemma.
If you mean the AFL users library (codes made by AB users) then you should read what AmiBroker have written at the top of each formula there.

Originally Posted by AmiBroker
DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
So you should rather contact or comment to the author of each code.

You should probably start to read the AB guide first and read things like this one
www.amibroker.com/guide/h_understandafl.html

If you build a house you probably don't start with the roof too but instead you go to the bottom where it gets more dirty first.

Thanks trash. All I meant was the few words that explain what the formula does for example the HHV formula isnt clear enough for me.

Thanks for the link by the way.

HHV( parameter1, parameter2 ) means Highest High Value as the help defines it. So it outputs just what the name says ... it outputs the HHV of an inserted array within a defined period. HHV result is an array too. Now first param can be whatever array of your choice or own creation while prameter2 (the period) may be a number like 20 bars or an array like BarsSince( Month() != Ref(Month(), -1) ) etc.

Simply plot a price graph and a graph plotting HHV in same chart pane then you will understand better. For HHV plot use styleLine.

Thanks trash. Will try to plot it tonight. My trading is basically at a halt till I can test my strategy.

So while I wait for my book to come on Thursday to clarify a few things I have a few more questions.
Can you customize your back tester settings even further using specific formulas or is it limited to the setting standards?

One last question also. One of my conditions for entering a long trade would be an intermediate to primary upward trend. In the AFL code wizard I don't think that function is available. Is it possible to create your own customized formula? If so, im assuming it would be hard? Would the only way to get your hands on some thing like that through sharing? If so, any one mind giving me the formula for an upward trend?

Ps, the last thing I want is to be spoon fed. Im just a little lost but im sure ill get the jist of things soon enough.

Most AA (Auto-analysis) settings can be used via code level via SetOption() function.

The only ones not being usable via setoption are

THE FOLLOWING SETTINGS CANNOT BE SET PROGRAMMATICALLY VIA AFL AND SHOULD BE CHECKED IN AA SETTINGS:
// Reference symbol (Pad and align)
// Risk-free rate Sharpe
// Risk-free rate UPI
// Walk forward mode and data parameters
// Optimization target

Some other settings are only accessible via setoption but not in AA settings like

Code:
```SetOption(	"WorstRankHeld",	1 );	// Not in settings
SetOption(	"PriceBoundChecking",	False	);	// Not in settings,
SetOption(	"UsePrevBarEquityForPosSizing",	False	);	// Not in settings,
SetOption(	"UseCustomBacktestProc",	False	);	// Not in settings,
SetOption(	"DisableRuinStop",	False	);	// Not in settings
SetOption(	"EveryBarNullCheck",	False	);	// Not in settings
SetOption(	"HoldMinBars",	0	);	// Not in settings, disables exits for this number of bars
SetOption(	"HoldMinDays",	0	);	// Not in settings, disables exits for this number of days
SetOption(	"EarlyExitBars",	0	);	// Not in settings
SetOption(	"EarlyExitDays",	0	);	// Not in settings
SetOption(	"EarlyExitFee",		0	);	// Not in settings
SetOption(	"SeparateLongShortRank",	False	);	// Not in settings
SetOption(	"MaxOpenLong",	0	);	// Not in settings, number of max open long positions
SetOption(	"MaxOpenShort",		0	);	// Not in settings, number of max open short positions
SetOption(	"RefreshWhenCompleted",	False	);	// Not in settings when set to TRUE, it will perform View->Refresh All```

Also backtest mode can only be set via code level

Code:
```//:::::::::::::::::::::::::::::::::::::::::::: Backtest Mode Selection start :::::::::::::::::::::::::::::::::::::::::::::::
// default, as in 4.90, regular, signal-based backtest, redundant signals are removed
//SetBacktestMode( backtestRegular );

// SetBacktestMode( backtestRegularRaw );
// signal-based backtest, redundant (raw) signals are NOT removed, only one position per symbol allowed

// SetBacktestMode( backtestRegularRaw2 )
// for custom backtester users only, the same as backtestRegularRaw, but redundant exit signals are also kept.
// AVOID this mode - it requires lots of memory AND slows everything down.
// The difference between backtestRegularRaw and backtestRegularRaw2
// is JUST this single thing (Raw2 mode keeps ALL Sell signals, while Raw mode keeps only Sell Signal
// for symbols that generated a Buy before).

// SetBacktestMode( backtestRegularRawMulti );
// signal-based backtest, redundant (raw) signals are NOT removed,
// MULTIPLE positions per symbol will be open if BUY/SHORT signal is "true" for more than one bar and there are free funds
// Sell/Cover exit all open positions on given symbol, Scale-In/Out work on all open positions of given symbol at once.

// SetBacktestMode( backtestRegularRaw2Multi )
// for custom backtester users only, same as backtestRegularRawMulti,
// but redundant exit signals are also kept. AVOID this mode - it requires lots of memory AND slows everything down.

// SetBacktestMode( backtestRotational );
//:::::::::::::::::::::::::::::::::::::::::::: Backtest Mode Selection end :::::::::::::::::::::::::::::::::::::::::::::::::```

Originally Posted by darkhorse70
One last question also. One of my conditions for entering a long trade would be an intermediate to primary upward trend. In the AFL code wizard I don't think that function is available. Is it possible to create your own customized formula? If so, im assuming it would be hard? Would the only way to get your hands on some thing like that through sharing? If so, any one mind giving me the formula for an upward trend?
Code wizard is for beginners and does just basic stuff.

On the other hand in the formula editor you can code anything you can imagine.

Originally Posted by darkhorse70
Thanks trash. All I meant was the few words that explain what the formula does for example the HHV formula isnt clear enough for me.

Thanks for the link by the way.

Once you get into the language reference, search on HHV, select a topic, then read away.

HHV
- highest high value Lowest/Highest

SYNTAX hhv( ARRAY, periods )
RETURNS ARRAY
FUNCTION Calculates the highest value in the ARRAY over the preceding periods (periods includes the current day). HHV accepts periods parameter that can be constant as well as time-variant (array).
EXAMPLE The formula "hhv( close, 4)" returns the highest closing price over the preceding four periods; "hhv( high, 8)" returns the highest high price over the preceding eight periods.

References:
The HHV function is used in the following formulas in AFL on-line library:

Pivots And Prices And Swing Volume
% B of Bollinger Bands With Adaptive Zones
10-20 Indicator
30 Week Hi Indicator - Calculate
52 Week New High-New Low Index
Adaptave Zones O/B & O/S Oscillator
AFL Example
AFL Example - Enhanced
Against all odds

Thanks trash for the clarification.

Newt call me stupid, ive read that definition a few times. The part I get confused about is the -1 after the 250day period . If the afl library had 2 or 3 detailed examples it would make it so much easier.

Howard bandy book will hopefully arrive tomorrow and im hoping it has alot of examples to give me a better picture of the whole thing.

Thanks for the feed back felllas. Goes a long way

I can break it down for you.

C > Ref(HHV(H, 250), -1)

C = Close Price this bar (most recent)
> = Greater Than
Ref = Reference (previous period defined by -1 in this example)
( = Parenthesis
HHV = Highest High Value in the defined array (H or High in this example) and period (250 in this example)
( = Parenthesis
H = High Price for the Highest High Value
, = comma
250 = Period for HHV
) = Parenthesis
, = comma
-1 = Period of reference to check the array HHV(H, 250) which is the bar before today (one period before most recent)
) = Parenthesis

I am a tradesman and programming language is not one of my interests but I can tell you that the secret isn't in the formula, it is in the knowledge and experience. Both of which I am still processing. Amibroker has helped me understand the market gyrations much better. It is a longer road than I thought it would be. For some reason I can't get synchronised with Mr. Market and his cronies.

Trust this will help.

Thanks wysiwig. Now I get what that -1 means haha.
screen shotted that explanation. Even though I shouldnt be trading I still have a position or two live. I just got stopped out on one and the other is close to.

I want to test my strategy asap so I can get some sort of picture of what my systems potential is or if its garbage.

Seems like most arnt in synch with the markets. Haha

Thanks wysi

So I guess you haven't had the time yet to follow the advice of simply plotting HHV variable or Ref( HHV(...), -x ) variable with price plot and to play around with values so that you would understand by yourself what it is actually doing, right?

Instead every little detail has to be brought to you on a silver plate.

Just FYI but Ref() (just like every other function) also has a function reference to be found in the documentation.

And BTW if you are confused by brackets/braces then in the new editor you can just mark (or leftclick right before or after) each one and it will auto-highlight the corresponding beginning/ending bracket/brace.