Australian (ASX) Stock Market Forum

Amibroker FAQ

Chops code returns true or false for the buy line, not a number.



Optimize should be assigned to a variable to make the code more readable.

Fair enough, but it doesn't change the functionality. He had too many unecessary lines. My code works in a single line.

By the way chops, I know where you're headed with this and there's no edge, unfortunately.
 
I'm trying to create composite index but every time I got error after validating the code in AmiBroker 6.00 for the line 5:
"Error 55. Invalid assignment. The identifier is read-only (constant) and can not be written to."

Code:
Hi = High > Ref(HHV(High,250),-1);
Lo = Low < Ref(LLV(Low,250),-1);
HiLoDifference = Hi - Lo;
Buy = 0;
AddToComposite(HiLoDifference,"~HiLoDifference","X",atcFlagDefaults = 7);
NHNL = Foreign("~HiLoDifference","C",True);
Plot(NHNL, "New high new low index", colorGreen,styleLine);

What is interesting I did everything as on tutorial:
https://www.youtube.com/watch?v=nGiRNbOOjlA

I suppose that something has changed in the newest versions of AmiBroker but not sure.
 
Hi James --

Your code almost works as you posted it. Try this:

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

First to understand what values are being added to the composite.

Your code has these lines:
Hi = High > Ref(HHV(High,250),-1);
Lo = Low < Ref(LLV(Low,250),-1);
HiLoDifference = Hi - Lo;

Hi, as defined, is a series, each value of which is binary. +1 if a new high, 0 otherwise.
Lo is a binary series. +1 if a new low, 0 otherwise.
HiLoDifference is a numeric series. Each element can take on one of three values -- +1, 0, or -1.

Assuming that is what you want.

A HiLo series is computed for each issue in the group being analyzed and added to the Composite. The values that series has depends on how many issues are in the group, and on how often a new high or new low occurs in each. A 600 issue group I tested resulted in values that were usually in the range of -50 to +50, but with excursions beyond those.

------------------
In the main AmiBroker window:
1. Open (or create a new) Analysis pane.
2. Set "Apply to" to whatever group you want to analyze by setting it to "Filter"
3. Choose the group -- say the issues that are constituents of an index.
4. Back on the main chart, load an issue that is meaningful in relation to the composite -- say the index fund corresponding to the group.

Open the formula editor. In Formula Editor
1. Change this:
AddToComposite(HiLoDifference,"~HiLoDifference","X",atcFlagDefaults = 7);
to this:
AddToComposite(HiLoDifference,"~HiLoDifference","X");

2. Click "Verify Syntax" There should be no errors.

3. Using the "Send to Analysis icon", click "scan".

Back in the AmiBroker main program, Select the main chart.
The HiLo series is plotted in the bottom pane.


Best,
Howard
 
I'm trying to create composite index but every time I got error after validating the code in AmiBroker 6.00 for the line 5:
"Error 55. Invalid assignment. The identifier is read-only (constant) and can not be written to."

Code:
Hi = High > Ref(HHV(High,250),-1);
Lo = Low < Ref(LLV(Low,250),-1);
HiLoDifference = Hi - Lo;
Buy = 0;
AddToComposite(HiLoDifference,"~HiLoDifference","X",atcFlagDefaults = 7);
NHNL = Foreign("~HiLoDifference","C",True);
Plot(NHNL, "New high new low index", colorGreen,styleLine);

What is interesting I did everything as on tutorial:
https://www.youtube.com/watch?v=nGiRNbOOjlA

I suppose that something has changed in the newest versions of AmiBroker but not sure.

There has nothing changed. The reason is that the code is simply wrong. The presenter of that video is just a beginner but not a professional. Don't trust what someone else is claiming as being "correct" on the Internet. In the end you have to find out yourself what is correct by gaining knowledge yourself. Otherwise you will always be dependent on what others wanna tell you (no matter if it is nonsense or if it is not BS).

As for why the code is wrong....
atcFlagDefaults is a reserved constant/number and it is equal to 7.

Try this following code and see yourself

Code:
printf( "The type of atcFlagDefaults is: " + typeof( atcFlagDefaults ) );
printf( "\natcFlagDefaults returns following value: %g", atcFlagDefaults );

Save upper two lines as AFL and apply it on chart, then open Interpretation window and you will get following output:

5ZVFBp3.png

"So in the end what does it mean", you may ask. If you write ATCFlagdefaults = 7 then it is equal to writing 7 = 7. But you can not assign a number to a number. You can only assign a number or an array or a string to a variable name (being not reserved one returning some constants).

So correct way(s) would be

Code:
AddToComposite(HiLoDifference,"~HiLoDifference","X", atcFlagDefaults);

or

Code:
AddToComposite(HiLoDifference,"~HiLoDifference","X", 7);

or

Code:
AddToComposite(HiLoDifference,"~HiLoDifference","X", flag = 7);

or

Code:
AddToComposite(HiLoDifference,"~HiLoDifference","X", flag = atcFlagDefaults);

or

Code:
AddToComposite(HiLoDifference,"~HiLoDifference","X", flag7 = 7);

the last three ones are correct because the variable name "flag" or "flag7" are not reserved to some number or anything else within AB universe.

The reason why in the AB manual there is written i.e. atcFlagDefaults = 7 ...
it is just trying to say that both are the same.


So in upper code examples I have shown to you one way how you can find out yourself why it's this and why it is that.
Again don't trust anyone's claims. Not my ones or some other ones. Make sure yourself. Or go to AmiBroker themselves. They are the only ones knowing for sure in regards to AB.
 
There has nothing changed.

Hey James, Howard and Trash - thank you! James for raising it, and Howard and Trash because I've benefited from the great work that you do, many times.

I've taken the video down (made it private/unsearchable), and will fix it up this weekend with the things you all noted.

I'm running Amibroker 5.5 at the moment, and the code actually works straight as copied and pasted from James' post. So, maybe things have been simplified in the latest Amibroker version, and it is certainly my fault for not updating (yes, it is on my New Years to-do list).

As for your other comment, Trash you are correct. I'm not a coder. I just try and figure things out, and then write about them so perhaps other people can benefit too. I'm also a little slow on the uptake, so I figure if I can understand something, then anyone else can, too. And it's good advice you've given on the Amibroker support (which is excellent) and, of course, not to trust someone's claims on the internet. I try to live by this advice too.

Thanks again guys,

Dave McLachlan
 
No problem.

For the record there is nothing wrong in being a beginner. Everyone has been a beginner at some stage.

But care must be taken about what is stated especially in forums or youtube. Many people take it for granted if someone else takes care of thinking for others.

As for why in 5.6 and before you could do the way you did… there was no restriction implemented that would prevent users from doing it wrong.

Also my previous post was not precious enough. Yes, you can not assign a number to a number. But in previous versions you could assign different return values to reserved variables like atcFlagDefaults or colorBlack etc. (already holding some constant value). So you could overwrite them.

For example you could overwrite them with some array etc.:

Code:
atcFlagDefaults = Close;

And that is not a correct way.

According to release notes it has been implemented in version 5.64. Since then they are read only and if you try to overwrite them then Error 55 shows up.
 
Can someone point me to coding to identify Dow Theory trend, ie higher high, higher low [uptrend] and the reverse downtrend
 
Basing on example from AmiBroker page https://www.amibroker.com/guide/h_pyramid.html
I would like to create DCA (Dollar Cost Average) simple test to buy first trading day of month index for fixed amount. I used code from above page and added some settings as in example below but every time backtester is opening only one position (the first entry) and no more buying.

Code:
SetBacktestMode( backtestRegularRaw ); 
SetOption("MaxOpenPositions", 100 );
SetTradeDelays(0,0,0,0);
FixedDollarAmount = 10000;
PositionSize = FixedDollarAmount;

MonthBegin = Month() != Ref( Month(), -1 );

FirstPurchase = Cum( MonthBegin ) == 1;

Buy = IIf( MonthBegin, sigScaleIn, 0 ); // each month increase position
Sell = 0; // we do not sell

BuyPrice=SellPrice = O;
 
I would like to create DCA (Dollar Cost Average) simple test to buy first trading day of month index for fixed

edited

SetBacktestMode( backtestRegularRaw );
SetOption("MaxOpenPositions", 100 );
SetTradeDelays(0,0,0,0);
SetOption("InitialEquity", 200000 ); //<<
//FixedDollarAmount = 10000;
PositionSize = 10000;// can also use Positionsize = -10 ie. 1/10th of available capital

MonthBegin = Month() != Ref( Month(), -1 );

FirstPurchase = Cum( MonthBegin ) == 1;

Buy = IIf( MonthBegin, sigScaleIn, 0 ); // each month increase position
Sell = 0; // we do not sell

BuyPrice=SellPrice = O;
 
edited

SetBacktestMode( backtestRegularRaw );
SetOption("MaxOpenPositions", 100 );
SetTradeDelays(0,0,0,0);
SetOption("InitialEquity", 200000 ); //<<
//FixedDollarAmount = 10000;
PositionSize = 10000;// can also use Positionsize = -10 ie. 1/10th of available capital

MonthBegin = Month() != Ref( Month(), -1 );

FirstPurchase = Cum( MonthBegin ) == 1;

Buy = IIf( MonthBegin, sigScaleIn, 0 ); // each month increase position
Sell = 0; // we do not sell

BuyPrice=SellPrice = O;

Thanks but the result is almost this same. There was opened only one position (the first) and no more.
 
I see.

Try Settings>report>detailed log to see where the money is going.
Thanks a lot. Now I've noticed in detailed log that transactions were made in correct days. I was misguided by that there was present in "Trade list" view only one record but in "Detailed log" there is information about every trade.
 
Thanks a lot. Now I've noticed in detailed log that transactions were made in correct days. I was misguided by that there was present in "Trade list" view only one record but in "Detailed log" there is information about every trade.

Trade list shows just one row because Sell is set to false in that code.

Btw, trade list view can be set via code level too.. See SetOption().
 
Top