[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Use AFL to create two charts



PureBytes Links

Trading Reference Links

Alex --
I think this is what you had in mind. One program -> two graphs.  
(Doesn't use BackTester.)
I'm assuming your a newbie because I don't recognize your user name on 
the board.

1. Open AB editor and Copy code below thereto.
2. SaveAs with a name.
3. AFL check (icon). Fix any errors.
4. Select an unused sheet.
5. Insert indicator (icon) (twice).
6. You should now see two new graphs on the sheet (probably blank).
7. Right click the top new graph.  Select Parameters->Axis and Grid.
8. Near bottom of new Axis and Grid find 'ChartId' number.
9. Enter number in place of '1486' in code.
10. Enter number+1 in place of '1487' in code.
11. Modify for your system, if that's sorta what you wanted.

|// Trythis.afl
// simple system just to illustrate same code displaying different
// charts on same sheet.
SetTradeDelays(1,1,1,1);
SetBarsRequired(100000,100000);
*Filter* = 0;

// code to go long
*Buy* = Cross(MA(*C*, 10)*0.95, MA(*C*,20));  // I did say 'simple'
*BuyPrice* = *Open*;
LongStop = Ref(*L*, -1);
*Sell* = *L* < LongStop;
*Buy* = ExRem( *Buy*, *Sell* );
*Sell* = ExRem( *Sell*, *Buy* );
*SellPrice* = Min(*Open*, LongStop);

// code to go short
*Short* = Cross(MA(*C*, 20), MA(*C*, 10)*1.05); // still simple
*ShortPrice* = *Open*;
ShortStop = Ref(*H*, -1);
*Cover* = *H* > ShortStop;
*Short* = ExRem( *Short*, *Cover* );
*Cover* = ExRem( *Cover*, *Short* );
*CoverPrice* = Max(*Open*, ShortStop);

// Plot charts
SetChartOptions(1,*chartShowArrows*|*chartShowDates*);
Plot(*C*,"Close",*colorBlack*,*styleCandle*);
 
// Chart for long trades
*if*(GetChartID()==1486){
Plot(LongStop,"LongStop",*colorBlue*,*styleDots*);
//PlotShapes(LongSetup*shapeUpArrow,colorBlack,0,L,-12); // LongSetup 
not defined
PlotShapes(*Buy***shapeUpArrow*,*colorGreen*,0,*L*,-12);
PlotShapes(*Sell***shapeDownArrow*,*colorRed*,0,*H*,-12);
}

// Chart for short trades
*if*(GetChartID()==1487){
Plot(ShortStop,"LongStop",*colorBlue*,*styleDots*);
//PlotShapes(LongSetup*shapeUpArrow,colorBlack,0,L,-12);
PlotShapes(*Cover***shapeHollowUpArrow*,*colorRed*,0,*L*,-12);
PlotShapes(*Short***shapeHollowDownArrow*,*colorGreen*,0,*H*,-12);
}
|

dralexchambers wrote:
>
> Is it possible in the backtester to code in AFL the following:
>
> - Open up two charts (basic price)
>
> - On the top chart, show all long positions. I use this code for my
> long positions:
>
> BUY = {conditions here}
> BuyPrice = xxxxx
> LongStop = Ref(L, -1);
> Sell = L < LongStop;
> Buy = ExRem( Buy, Sell );
> Sell = ExRem( Sell, Buy );
> SellPrice = Min(Open,LongStop);
>
> Plot(LongStop,"LongStop",colorBlue,styleDots);
>
> PlotShapes(LongSetup*shapeUpArrow,colorBlack,0,L,-12);
> PlotShapes(Buy*shapeUpArrow,colorGreen,0,L,-12);
> PlotShapes(Sell*shapeDownArrow,colorRed,0,H,-12);
>
> I would then like to plot similar for short trades on the bottom
> chart.
>
> I already have the code for the BUY/SELL AFL. I am looking for code
> to open two charts and write to each one independently.
>
> Thanks - alex
>
>  

Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.19/663 - Release Date: 2/1/2007 2:28 PM