Australian (ASX) Stock Market Forum

Amibroker FAQ

Thanks Trash. Thats pure gold. Very helpful.
Can I ask for a system that buys and sells on open the following day would this be correct

SetOption( "ReverseSignalForcesExit", False);

Also when viewing equity charts is there a setting to view them as compounded or non-compounded equity. Ive seen system results on forums where the equity graph is compounded equity and others are non-compounded. Not sure how that is arrived at.
 
Another thing. I was thinking about how I could use exrem without it affecting the backtester. I thought if I renamed "buy" to plotBuy in the following formula it would plot the signals and remove the unwanted ones. Is there an easier way? I want something where I dont have to remember to remove exrem.

Code:
//Entry & Trigger Bar Conditions


EntryTrigger = 0;                 //Trigger Bar Buy Conditions

ExitTrigger=0;                    // Trigger Bar Sell Conditions

Buy=Ref(EntryTrigger,-1);BuyPrice=Open;                                                             //Buy delay- Buying today on open - signal was yesterday

Sell=Ref(ExitTrigger,-1); SellPrice=Open;                                                           //Sell delay- Selling today on open - signal was yesterday


//---------------------------------------------------------------------------------------------------------------------------------------------------------------

//Plot the signals

GraphXSpace = 5;                                                                                    // create empty space of 5% top AND bottom of chart 

EntryTrigger=ExRem(EntryTrigger,ExitTrigger);                                                       //Removes unwanted trigger signals
ExitTrigger=ExRem(ExitTrigger,EntryTrigger);

PlotBuy=Ref(EntryTrigger,-1);                                                                       //Buy renamed as plotbuy (So that exrem wont effect backtest)                 
PlotSell=Ref(ExitTrigger,-1);

PlotBuy=ExRem(PlotBuy,PlotSell);                                                                    //Remove unwanted buy signals
PlotSell=ExRem(PlotSell,PlotBuy);                                                                   //Remove unwanted sell signals

PlotShapes(IIf(EntryTrigger,shapeSmallCircle,shapeNone),colorGreen,0,L,-15);                        //Plots the Entry Trigger Signals
PlotShapes(IIf(ExitTrigger,shapeSmallCircle,shapeNone),colorBlack,0,H,-15);                         //Plots the Exit Trigger Signals
PlotShapes(IIf(PlotBuy,shapeUpTriangle,shapeNone),colorGreen,0,L,-30);                              //Plots the actual Buy Signals
PlotShapes(IIf(PlotSell,shapeDownTriangle,shapeNone),colorBlack,0,H,-30);                           //Plots the actual Sell Signals
 
Hi guys, quick question, hopefully.

How do I find the HHV between say Jan1 and Jan 30?

EDIT: I think I found it.... "beginvalue/endvalue"
 
Hi guys, quick question, hopefully.

How do I find the HHV between say Jan1 and Jan 30?

EDIT: I think I found it.... "beginvalue/endvalue"

Code:
startDate = ParamDate("Start Date","01/01/2012");
endDate   = ParamDate("End Date","01/30/2012");

dn = DateNum(); 
timecond = dn >= startdate AND dn <= enddate;
firstBarOfRange = dn >= startdate;
firstBarOfRange = firstBarOfRange - Ref(firstBarOfRange, -1);
HighestH = ValueWhen(timecond, HighestSince(firstBarOfrange, H) );
LowestH = ValueWhen(timecond, LowestSince(firstBarOfrange, L) );
Plot(LastValue(HighestH), "High", colorBrightGreen, styleLine);
Plot(LastValue(LowestH), "Low", colorRed, styleLine);
 
Regarding new AA

Don't know if backtester settings are saved in .apx file too

Code:
AB = new ActiveXObject( "Broker.Application" ); // creates AmiBroker object

try 
{ 
    NewA = AB.AnalysisDocs.Open( "C:\\analysis1.apx" ); // opens previously saved analysis project file 
    // NewA represents the instance of New Analysis document/window 

    if ( NewA ) 
    { 
         NewA.Run( 2 ); // starts analysis (asynchronous - returns immediatelly
      // (0-scan, 1- exploration, 2- portfolio backtest, 3- Individual Backtest, 4- optimization, 5- Individual Optimization (not supported yet), 6-walk forward)

         while ( NewA.IsBusy ) WScript.Sleep( 500 ); // check IsBusy every 0.5 second 

         NewA.Export( "test.html" ); // export result list to HTML file

         WScript.echo( "Completed" ); 

         //NewA.Close(); // close new Analysis 
     } 
} 
catch ( err ) 
{ 
     WScript.echo( "Exception: " + err.message ); // display error that may occur
}

Confirmation by T.J.

Hello,

.APX holds everything that .ABS held and more.

.APX project contains everything you need to run (including formula and settings),
so when you load .APX file you don't need to load anything else.

Best regards,
Tomasz Janeczko
amibroker.com
 
Code:
startDate = ParamDate("Start Date","01/01/2012");
endDate   = ParamDate("End Date","01/30/2012");

dn = DateNum(); 
timecond = dn >= startdate AND dn <= enddate;
firstBarOfRange = dn >= startdate;
firstBarOfRange = firstBarOfRange - Ref(firstBarOfRange, -1);
HighestH = ValueWhen(timecond, HighestSince(firstBarOfrange, H) );
LowestH = ValueWhen(timecond, LowestSince(firstBarOfrange, L) );
Plot(LastValue(HighestH), "High", colorBrightGreen, styleLine);
Plot(LastValue(LowestH), "Low", colorRed, styleLine);


Trash, it turns out I actually posed the question incorrectly. I appreciate the time you took to do that, and just wonder if you might be able to have another shot. No plotting is necessary.

How to find the HHV of the last 30 days, but excluding the last 7 days.
 
One week does have 5 business days.
hhvcustom = ref(hhv(H, 25), -5);

well, but if you want to exclude 7 days then
hhvcustom = ref(hhv(H, 23), -7);
 
Can someone please help me to code the following:

When MACD crosses Signal line, flip/mirror MACD & price chart & change background color to blue
When Signal line crosses MACD it reverts back to normal.


This is my attempt at coding the above obviously without much success:

IIf (MACD() < Signal() , GraphXSpace = -100, SetChartBkColor( colorBlue ));
IIf (MACD() > Signal() , GraphXSpace = 100, SetChartBkColor( colorBlack ));

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

Original code (got it from Amibroker Yahoo) for Flipping Chart:


// Flip price chart

Plot(C,"",colorRed,64);

if(ParamToggle("Upside Down?","No|Yes"))
GraphXSpace = -100;
--------------------------------------

This seems silly, but my brain seems to be working only in one direction ie. when the market is trending up.
 

Attachments

  • Flip Mirror Chart.jpg
    Flip Mirror Chart.jpg
    135.7 KB · Views: 3
  • Normal Chart.jpg
    Normal Chart.jpg
    206.9 KB · Views: 3
Can someone please help me to code the following:

When MACD crosses Signal line, flip/mirror MACD & price chart & change background color to blue
When Signal line crosses MACD it reverts back to normal.


This is my attempt at coding the above obviously without much success:

IIf (MACD() < Signal() , GraphXSpace = -100, SetChartBkColor( colorBlue ));
IIf (MACD() > Signal() , GraphXSpace = 100, SetChartBkColor( colorBlack ));

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

Original code (got it from Amibroker Yahoo) for Flipping Chart:


// Flip price chart

Plot(C,"",colorRed,64);

if(ParamToggle("Upside Down?","No|Yes"))
GraphXSpace = -100;
--------------------------------------

This seems silly, but my brain seems to be working only in one direction ie. when the market is trending up.

Try this

Code:
_SECTION_BEGIN("Conditional Chart Background");
cond = LastValue(MACD(12,26)) < LastValue(Signal(12,26,9));
bgmode = ParamToggle("Single Background Color","YES|NO", 1);
if(cond)
{
   bgcolor =  ParamColor("Background Color Top 1", colorBlue);
   GraphXSpace = -100; 
} 
else {
   bgcolor =  ParamColor("Background Color Top 2", colorRed);   
}

if(bgmode)
  SetChartBkGradientFill( bgcolor, ParamColor("Background Color Bottom", colorWhite), bgcolor );
else
  SetChartBkGradientFill( bgcolor, bgcolor, bgcolor );

SetChartOptions(0, chartShowArrows|chartShowDates);
SetChartBkColor( ParamColor("Background Color Axes", colorBlack) ); 

Colortitle  = ParamColor("Color of Title", colorWhite);
_N(Title = StrFormat(EncodeColor(Colortitle) + Name() + " - {{INTERVAL}} - {{DATE}}  {{VALUES}}"  ));
_SECTION_END();

_SECTION_BEGIN("MACD");
Plot( MACD( 12, 26 ), _DEFAULT_NAME(), ParamColor( "Color MACD", colorRed ), ParamStyle("Style MACD") ); 
Plot( Signal( 12, 26, 9 ), _DEFAULT_NAME(), ParamColor( "Color Signal", colorBlack ), ParamStyle("Style Signal") ); 
_SECTION_END();
 
Morning everyone
If anyone can help: I have begun amibroker programming and got stuck in the following:
I want to put a stop condition on a system following a buy: let's say
sell if share price is 10% below [purchase price or highest reached since purchase]
a kind of 1 way lock...
How do you retrieve the purchase price to backtest your system?
can you store the purchase price in an array variable and retrieve it?
as a programmer, I would use purPrice[asxname]=$xx.xx and retrieve it later on in the next pass
But a bit stuck and could not find anything in my search
this is a very common simple need so I must not be looking at the right place

in AB language, how do you retrieve the B price (or index) in an AB Array for back testing analysis?

Any help very welcome
 
Morning everyone
If anyone can help: I have begun amibroker programming and got stuck in the following:
I want to put a stop condition on a system following a buy: let's say
sell if share price is 10% below [purchase price or highest reached since purchase]
a kind of 1 way lock...
How do you retrieve the purchase price to backtest your system?
can you store the purchase price in an array variable and retrieve it?
as a programmer, I would use purPrice[asxname]=$xx.xx and retrieve it later on in the next pass
But a bit stuck and could not find anything in my search
this is a very common simple need so I must not be looking at the right place

in AB language, how do you retrieve the B price (or index) in an AB Array for back testing analysis?

Any help very welcome

Purchase price will be in line with your buy conditions. eg. Buy = Cross(c,MA(C,5));
Or you can stipulate Buyprice = Open (or close).
Or you can define a buy price intraday, eg. Buyprice = O+(.05*O);

You'd use a trailing stop to sell.

Sell = false;
Applystop(Stoptypetrailing, stopmodepercent, optimize("trail", 1,1,20,1));
 
Purchase price will be in line with your buy conditions. eg. Buy = Cross(c,MA(C,5));
Or you can stipulate Buyprice = Open (or close).
Or you can define a buy price intraday, eg. Buyprice = O+(.05*O);

You'd use a trailing stop to sell.

Sell = false;
Applystop(Stoptypetrailing, stopmodepercent, optimize("trail", 1,1,20,1));
Thanks GB,
I had no problem with the B part and it seems to work when I run on the last 20y, but I exit too quickly as I reach my Sell on C<HHV(C,various nb of days)
as discussed, I am really looking not a set nb of day but the nb of day since purchase

I believe the applystop is what I was looking,
My apologies for the novice question: I purchased AB this wek end and just read the manual on sunday so all brand new
Have a nice day
the applystop is probably what I am missing
 
QLD frog, remember if you want to sell on C<HHV, you have to reference the previous day like this:

sell = C<Ref(HHV(C,10),-1); or
sell = Cross(Ref(HHV(C,10),-1),C);

otherwise it won't trigger, due to the fact that HHV includes the current day.

Selling on days since purchase looks like this:

Sell = false;
Applystop(stoptypenbar, stopmodebars, 1);

I can only answer the easy qu's, btw. :)
 
Is anyone able to tell me what to write for the buy and sell in this formula so that a buy means the angle of the sloping line is greater than 5 Degrees up.
Sell is the opposite. Ive looked at lots of linear Regression formulas but just cant work it out.

Thank you

HTML:
_SECTION_BEGIN("52 Period Linear Regression Line");
// 52 period linear regression line
x = Cum(1); //
Daysback = Param("Days Back",52,5,500,1);
lastx = LastValue( x );  aa = LastValue( LinRegIntercept( Close, Daysback) );
bb = LastValue( LinRegSlope( Close, Daysback ) );
y = Aa + bb * ( x - (Lastx - DaysBack) ); 
Plot( IIf( x >= (lastx - Daysback), y, -1e10 ), "LinReg", colorBlack );


_SECTION_END();

Buy = 0; 
Sell = 0;



Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);




PlotShapes(shapeUpArrow*Buy,colorGreen,0,L, -30);
PlotShapes(shapeDownArrow*Sell,colorRed,0,H, -30);
 
Hi Art --

What is your definition of the angle? It is important that it be unaffected by a change in scale of the chart or split of the stock price.

Howard
 
One possibilty is to Buy when C rises above the linear regression line and sell when it drops below:

Buy = Cross( C, y );
Sell = Cross( y, C );

Is anyone able to tell me what to write for the buy and sell in this formula so that a buy means the angle of the sloping line is greater than 5 Degrees up.
Sell is the opposite. Ive looked at lots of linear Regression formulas but just cant work it out.

Thank you

HTML:
_SECTION_BEGIN("52 Period Linear Regression Line");
// 52 period linear regression line
x = Cum(1); //
Daysback = Param("Days Back",52,5,500,1);
lastx = LastValue( x );  aa = LastValue( LinRegIntercept( Close, Daysback) );
bb = LastValue( LinRegSlope( Close, Daysback ) );
y = Aa + bb * ( x - (Lastx - DaysBack) ); 
Plot( IIf( x >= (lastx - Daysback), y, -1e10 ), "LinReg", colorBlack );


_SECTION_END();

Buy = 0; 
Sell = 0;



Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);




PlotShapes(shapeUpArrow*Buy,colorGreen,0,L, -30);
PlotShapes(shapeDownArrow*Sell,colorRed,0,H, -30);
 
Top