Australian (ASX) Stock Market Forum

Amibroker FAQ

also can have
signal = Cross(C, ema(c,50) )

The use of indices as additional signals can be automated by designating the indexes in the Symbol-categories window. There is order of precedence of Market - Group - Industry. So if Market is filled in in the categories then groups and industries are ignored, unfortunately. I ahve asked TJ at AB to include ability to call up independantly.

The AFL to get the base index is GetbaseIndex()
so to get this in use

SetForeign(GetbaseIndex());

IndexSignal = Cross(C, ema(c,50) );

RestorePriceArrays();

//then you use it with the rest of the AFL

Buy = YourStockConditions and IndexSignal();


One thing to remember, and this can play a large part of problems. If you use unpadded data and your stock ticker has data gaps (untraded days) then it will ignore that particular date in referencing the foreign symbol. There are no workarounds for this unfortunately. So best to use any foreign as simple raher than crosses


SetForeign(GetbaseIndex());

IndexSignal = C > ema(c,50);

RestorePriceArrays();

Buy = YourStockConditions and IndexSignal();
 
Thanks heaps GP and Kaveman,

If youv'e got a problem with anything agricultural i'd be more than willing to help :)

I was just going to use the symbol rather than the index function but its always good to know.

The purpose being to exit all trades on a given signal and re-commence the system on reverse: a way of avoiding a bear market somewhat.

I think i'll be right for now.
 
I've been trying this to plot the 180 day ema of the close for the xao and the chart still comes up blank
Any ideas?

SetForeign("XAO");

Plot(EMA(C,180),"xao ma",colorBlack,styleLine);

RestorePriceArrays();

Thanks
 
That formula works fine when I try it.

Where are you entering the formula?

GP
 
loakglen said:
I've been trying this to plot the 180 day ema of the close for the xao and the chart still comes up blank
Any ideas?

SetForeign("XAO");

Plot(EMA(C,180),"xao ma",colorBlack,styleLine);

RestorePriceArrays();

Thanks

What background colour do you have, if black the line
colorBlack
will not show
 
GreatPig said:
That formula works fine when I try it.

Where are you entering the formula?

GP

This is the entire formula:

SetForeign("XAO");
cond1=C>EMA( C, 180);

Plot(EMA(C,180),"xao ema180" ,colorBlack,styleLine);

RestorePriceArrays();

Filter= V>5000000;

Buy= Cross(MA(C,180),C) AND Cond1;

BuyPrice= Max(C+ ATR(1),260*1.5);

Sell= Buy=False ;

PositionSize=-20;

Plot(MA (C,180),"xma",colorBlue,styleLine);

PlotShapes( IIf(Buy, shapeUpArrow, shapeNone), colorBrightGreen, layer = 0, yposition = Graph0, offset = -10 );
PlotShapes( IIf(Sell, shapeDownArrow, shapeNone), colorRed, layer = 0, yposition = Graph0, offset = -10 );

Thanks.
 
kaveman said:
What background colour do you have, if black the line will not show

no it's a white background.

if I plot it separate to price action the value for "xao ema180" is "empty" so its not out of range of the chart either.

thanks for trying :D
 
Do you have this on a chart (as an indicator) or are you just running it in an exploration?


loakglen said:
Buy= Cross(MA(C,180),C) AND Cond1;
Regardless of the plot, I think you have the cross back-to-front. This says buy when the MA crosses upward over the price - ie. when the price drops below the MA.


Sell= Buy=False ;
Two problems here that I can see, assuming I understand what you're trying to do. Firstly, comparison requires the double-equals operator (a very common bug in C programming too). So it should say:

Sell = Buy == False;

Secondly, assuming this really is what you mean, then it will generate a sell signal on any day that doesn't have a buy signal. Probably not what you want either. You wouldn't be holding anything for very long :D.

For the plotting problem, I'd have to play around with it to see exactly what it does. I don't have time right at this moment, but I'll take a look later if you don't already have an answer by then.

GP
 
makes more sense, as the info provided before plotted fine

due to the extreme differences inthe plot values you will only get one showing the other will either be off screen or condensed to miniscule line

change one, always the second plot to include styleLeftAxisScale

Plot(MA (C,180),"xma",colorBlue,styleLine|styleLeftAxisScale);

if you want the share to be the main Y axis values then move the XAO to after the stock plot, then havce the styleLeftAxisScale in the XAO plot line

The Y axis always uses the first Plot statement to set the scale, all other plots may vary the scale slightly, sometimes with horrendous results like the plotting of values of 4000 against 10.

You will not see any scale for the secondary plot that uses styleLeftAxisScale, but all plots with styleLeftAxisScale will use the same unseen scale. eg you may wnat to add other EMA plots of XAO.
 
maybe to have finding answersd easier later we could have separate queries in their own thread. Just start each thread with "Amibroker - query title"
so the last query could be
Amibroker - plot foreign on stock chart

Otherwise we could end up with a single thread 100 pages long and not be able to find the answers to tie to a question

just a suggestion
 
If there are enough AmiBroker users here, perhaps we should have an AmiBroker section - or a general programming/backtesting section for all flavours of charting software.

GP
 
loakglen said:
hi guys,

still havn't had any luck getting that foreign file thingy to work.
please help :cry:

are you getting any error messages?
Have you selected a base stock with data in it?

have you provided the full code you are using?

have you tried just plotting the foreign part without the rest?

did you have your weeties this morning? :banghead:
 
Loakglen,

Okay, here's what I get with your formula applied to TEN. I had to make three changes first though: swapping the Cross order and the double equals I mentioned earlier, and a scale adjustment so both plots overlay properly.

The exact code I'm using, cut and pasted straight from the indicator window, is:

//*********************************************************
SetForeign("XAO");
cond1=C>EMA( C, 180);

Plot(EMA(C,180),"xao ema180" ,colorBlack,styleLine);

RestorePriceArrays();

Filter= V>5000000;

Buy= Cross(C,MA(C,180)) AND Cond1;

BuyPrice= Max(C+ ATR(1),260*1.5);

Sell= Buy==False ;

PositionSize=-20;

Plot(MA (C,180),"xma",colorBlue,styleLine|styleOwnScale);

PlotShapes( IIf(Buy, shapeUpArrow, shapeNone), colorBrightGreen, layer = 0, yposition = Graph0, offset = -10 );
PlotShapes( IIf(Sell, shapeDownArrow, shapeNone), colorRed, layer = 0, yposition = Graph0, offset = -10 );
//*********************************************************

The "styleOwnScale" on the second plot ensures that it isn't tied to the scale of the first plot, since the values are miles apart.

The reason there is so much red above the line is because the sell condition signals every day that doesn't have a buy, which is most days. So nearly every day has a down red arrow on it.

And the reason it breaks in mid 2001 is because my XAO data only goes back that far. For some reason, float.com.au where I get my data from has share prices from 1997 but index data only from mid-2001.

As an indicator, the Filter and PositionSize variables don't do anything (that I'm aware of). They're for explorations and backtests. And the BuyPrice variable isn't normally set, as it indicates the current buy price in a backtest. For the last three parameters of the Plot function, you just need to specify the values, not the "layer =", "yposition = " and "offset = " parts, although that doesn't seem to stop it working.

I don't understand what you're trying to achieve with the BuyPrice equation either. Firstly I don't understand why you're setting it, and secondly why you'd set it to a constant value (260*1.5 = 390) if that was greater than the close+ATR(1) value.

I plotted this by adding it as an indicator using the indicator builder. If you want to run it as an exploration, you'll need to add at least one column for the display. You could add Close and Volume as follows:

AddColumn(Close, "Close", 1.3);
AddColumn(Volume, "Volume", 1.0);

Note though that for an exploration it is the Filter value that triggers a match, not the buy and sell signals. So as you have it, any day with volume over 5 million will generate a match.

Hope this helps.

Cheers,
GP
 

Attachments

  • Test_GP1.gif
    Test_GP1.gif
    8.7 KB · Views: 524
Trading The SPI

I just quickly coded the system that Brent Penfold has in his book "Trading the SPI". I don't quite get the same results as Brent, the same maximum and average profit though. I just seem to get more trades and more losses. I think it could be the difference in data providers and the way the contracts are stitched together. Not a bad system but trades too rarely to use much. It has only had one trade so far this year, but to be fair it was just a worked example to show the process of designing a mechanical system. Anyway the code

MIT
*********************************************************
/*************************************************
SPI Pivot System - Based On Brent Penfold's
Trading the SPI ...
**************************************************/

SetOption("InitialEquity", 10000 );
SetOption("FuturesMode", True);
SetOption("Allowsamebarexit", True );
SetOption("CommissionMode",2); // $ per trade
SetOption("CommissionAmount",0); //$10 per side

RoundLotSize = 1;
MarginDeposit = -1;
SetPositionSize( 25, spsShares );

WeekH = TimeFrameGetPrice("H", inWeekly, -1); // last weeks high
WeekL = TimeFrameGetPrice("L", inWeekly, -1); // low
WeekC = TimeFrameGetPrice("C", inWeekly, -1); // close

WPP = ( WeekH + WeekL + WeekC ) / 3; // Weekly pivot point
DPP = (Ref(H,-1) + Ref(L,-1) + Ref(C,-1)) / 3; // Daily pivot
DRange = (Ref(H,-1) - Ref(L,-1)); // High Low Range
DR1 = DPP + DRange / 2; // Resistance point
TR = Max(Ref(H,-1),Ref(C,-2))-Min(Ref(C,-2),Ref(L,-1));

Buy = O < WPP // Lower than weekly pivot point
AND O > DR1 // Higher than Daily High
AND H > O + TR / 2; // Range expansion
BuyPrice = O + TR / 2;

StoppedOut = Buy==1 AND (BuyPrice-L) > 0.01 * Ref(C,-1); // Stopped out at 1% of yesterdays close
NormalSell = Ref(Buy,-1) == 1; // Sell today if bought yesterday

Sell = StoppedOut OR NormalSell;
SellPrice = IIf(StoppedOut, BuyPrice - 0.01 * Ref(C,-1), O ); // Sell on open if not stopped out

Short = Cover = 0; // Long only system
 
Can anyone please provide me examples of code that shows how Ami 4.7 can scale in and out of positions. I've read the examples from the help section, but I'm yet to get my head around it. All I'm really after is some code that will buy another portion, equal to the first portion, when the price has increased, say 20% from the original buy price.

I'm currently working on a system that trades sub 20c stocks using a custom variation of SAR and some other tid-bits. It's based on the entire market, with the only filters being stocks less than 20c with StrLen(Name())==3 to filter out options and warrents etc.

I'm not going to paste the code because I believe the results is a based on picking a few lucky outliers, but here are the basic results. I intend to test over different time periods to see if the results can be reproduced without those outliers or if picking 'outliers' is a common occurance.

System is based on starting with $20k - something within the reach of most. Uses all data back to '97 - only an average of 34 trades per year and an ave. holding time of 13 days.

Edit: I should stress that this is something that I've only been looking at for an hour or two. Like tech's recent short term system, there's likely going to be something exceptionally wrong with it.
 

Attachments

  • th_smallCap1.gif
    th_smallCap1.gif
    36.8 KB · Views: 499
Sorry for the beginner question but am wondering whether Amibroker has trade scanners where you can put in your search requirements and it will find the setup you're looking for.

Thanks in advance.
 
It does, provided you can articulate what you're searching for in its internal scripting language.
 
DTM said:
am wondering whether Amibroker has trade scanners
Yes, it can do scans, explorations, and backtests.

But as Doctorj says, as long as you can program them in the scripting language.

GP
 
Top