Amibroker-OLE-Interface
view release on metacpan or search on metacpan
t/test_afl.afl view on Meta::CPAN
RequestTimedRefresh( 1, onlyvisible = False );
/*-----------Editable section----------------------*/
LOT_SIZE=1000;
STOCK_NAME="ADANIPORTS";
/*-------------------------------------------------*/
//========== OPTIMIZING SECTION ================================================
OPD = 6.8;
PTR = 38;
//=======================================================
FirstTradeTime = 115500;
LastTradeTime = 151000;
Exclude = FirstTradeTime >= LastTradeTime;
ApplyStop(stopTypeProfit,stopModePoint,4,True,True);
//=========== BACKTESTIN PARAMETERS =====================
/* BackTesting Parameters */
BROKERAGE = 100;
function WithoutMargin() {
PositionSize = MarginDeposit =1;
PointValue = LOT_SIZE;
}
function backtest_settings() {
SetOption("InitialEquity", 100000 );
SetOption("AllowPositionShrinking", True);
SetOption("FuturesMode", True);
SetOption("PriceBoundChecking", False);
SetOption("ReverseSignalForcesExit",False);
SetOption("CommissionMode", 2);
SetOption("CommissionAmount", BROKERAGE);
SetOption("RefreshWhenCompleted",True);
WithoutMargin();
}
// ENABLE OR DISABLE AutoTrading facility
AutoTradingControl = ParamList("AUTO-TRADING", "Yes|No", 0);
if(AutoTradingControl == "No") {
GfxSelectFont("Courier", 35, 800, True, True, 0 );
GfxSetBkMode( colorRed );
GfxSetTextColor( colorRED );
GfxTextOut("AUTO TRADING IS DISABLED", 80 , 110 );
}
else {
GfxSelectFont("Times New Roman", 24, 600, True );
GfxSetBkMode( colorRed );
GfxSetTextColor( colorWhite );
GfxTextOut(STOCK_NAME, 280 , 40 );
}
// Summary: Plot buy and sell spots on the graph for visual display
// Does not return anything
function plot_buy_sell_signals(type, upturn, downturn) {
// Filling the entire background color to black...Default is black + Grey
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorBlack));
if(type == "Long") {
// To Plot Buy signal and box around it
PlotShapes(IIf(upturn, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-30);
PlotShapes(IIf(upturn, shapeSquare, shapeNone),colorGreen, 0,L, Offset=-40);
PlotShapes(IIf(upturn, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-35);
// To Plot Sell signal and box around it
PlotShapes(IIf(downturn, shapeSquare, shapeNone),colorWhite, 0, L, Offset=-30);
PlotShapes(IIf(downturn, shapeSquare, shapeNone),colorWhite, 0,L, Offset=-40);
PlotShapes(IIf(downturn, shapeUpArrow, shapeNone),colorRed, 0,L, Offset=-35);
}
else {
// To Plot Short signal and box around it
PlotShapes(IIf(downturn, shapeSquare, shapeNone),colorRed, 0, H, Offset=30);
PlotShapes(IIf(downturn, shapeSquare, shapeNone),colorRed, 0,H, Offset=40);
PlotShapes(IIf(downturn, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-35);
// To Plot Cover signal and box around it
PlotShapes(IIf(upturn, shapeSquare, shapeNone),colorYellow, 0, H, Offset=30);
PlotShapes(IIf(upturn, shapeSquare, shapeNone),colorYellow, 0,H, Offset=40);
PlotShapes(IIf(upturn, shapeDownArrow, shapeNone),colorBlue, 0,H, Offset=-35);
}
}
// Summary: Function to draw the chart on the screen
// Does not return anything
function draw_chart() {
SetChartOptions (0, chartShowArrows|chartShowDates); //set/clear/overwrite defaults for chart pane options
SetChartBkColor(colorDarkGrey); // Sets chart background to user-defined colour
// Plot the price chart
Plot( Close, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot( EMA( Close, 7 ), "", colorYellow, ParamStyle("Style", styleThick | styleLine | styleNoLabel ) | styleNoRescale );
Plot( EMA( Close, 30 ), "", colorWhite, ParamStyle("Style", styleThick | styleLine | styleNoLabel ) | styleNoRescale );
TimeFrameRestore(); // To get back to original interval
}
_SECTION_BEGIN("Trading Terminal");
draw_chart();
backtest_settings();
Factor=OPD;
Pd=PTR;
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
for (i = 1; i <BarCount-1; i++) {
TrendUp[i] = Null;
TrendDown[i] = Null;
trend[i]=1;
if (Close[i]>Up[i-1]) {
trend[i]=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close[i]<Dn[i-1]) {
trend[i]=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend[i]=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
}
if (trend[i]<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}
if (trend[i]>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}
if (trend[i]>0 && Dn[i]<Dn[i-1]) {
Dn[i]=Dn[i-1];
}
if (trend[i]<0 && Up[i]>Up[i-1]) {
Up[i]=Up[i-1];
}
( run in 2.192 seconds using v1.01-cache-2.11-cpan-d8267643d1d )