I occasionally have thoughts of starting an Amibroker resource thread as a place to post code, links, documents etc.
One day
//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"
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 }
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);
Confirmation by T.J.
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.
_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
Thanks GB,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));
_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);
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);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?