Thư viện AFL
Thư viện AFL
Hệ thống giao dịch đột phá phạm vi mở đơn giản với thăm dò - Mã AFL Amibroker

Hệ thống giao dịch đột phá phạm vi mở đơn giản với thăm dò - Mã AFL Amibroker

Đây là Hệ thống giao dịch đột phá phạm vi mở chính thức với các biện pháp kiểm soát thăm dò được thiết kế trong Amibroker.

Hệ thống giao dịch đột phá phạm vi mở là gì

?

Phạm vi mở

thường là thước đo mức độ an toàn cao và thấp thường được các nhà giao dịch đột phá theo dõi để đánh giá tâm lý thị trường. Phạm vi cao nhất - thấp nhất trong 15 phút đầu tiên do cổ phiếu/chỉ số tạo ra thường được nhiều nhà giao dịch sử dụng làm tài liệu tham khảo để theo dõi giao dịch đột phá.

Đơn giản

Hệ thống giao dịch đột phá phạm vi mở

chủ yếu hữu ích cho các nhà giao dịch trong ngày đang tìm kiếm sự đột phá về giá từ phạm vi mở cửa. Thông thường, các nhà giao dịch thường sử dụng phạm vi mở cửa 15 phút / 30 phút để theo dõi đột phá với các điểm dừng/mục tiêu được xác định trước.

Đặc điểm của Đột phá phạm vi mở

  1. Nhiều lựa chọn đột phá ORB của sự lựa chọn của nhà giao dịch

2)Giới hạn số lượng tín hiệu vào mỗi ngày

  1. Hệ thống giao dịch trong ngày với các điều khiển tín hiệu thời gian bắt đầu, thời gian kết thúc và thời gian bình phương

4)Phương thức giao dịch: i) Không có chế độ dừng lỗ/mục tiêu, ii)Chế độ dừng/mục tiêu điểm cố định, iii)Chế độ dừng lỗ/mục tiêu theo tỷ lệ cố định.

  1. Khả năng kiểm tra lại

6)Khả năng thăm dò/máy quét

  1. Bảng điều khiển giao dịch theo dõi Tín hiệu và Lãi/Lỗ

Giao dịch đột phá phạm vi mở - Kiểm soát tham số

Đột phá phạm vi mở - Kết quả thăm dò

Mã AFL đột phá phạm vi mở Amibroker

Liên quan

Mã nguồn (.afl)
//Desinging a Simple ORB Based Trading system with Stoploss and Target controls
//Coded by Rajandran R - www.marketcalls.in / www.openalgo.in
//Date : 20th Sep 2022
//Version : 1.00

_SECTION_BEGIN("Simple ORB Based Trading System");

SetPositionSize(1*RoundLotSize,spsShares);

newday = Day() != Ref(Day(),-1);

mins = Param("Breakout(mins)",15,1,60,1);

starttime = ParamTime("Start Time","09:30");
endtime = ParamTime("End Time","14:30");
sqofftime  = ParamTime("Sqoff Time","15:15");

mode = ParamList("Risk Control(Stop/Target)","DISABLED|POINTS|PERCENTAGE");
buffer = Param("Buffer",0,0.05,1000,0.01);
stop = Param("Stoploss",20,0.05,1000,0.01);
target = Param("Target",50,0.05,1000,0.01);

TickSz = Param("Tick Size",0.05,0.0001,1,0.0001);

TradeLimit = Param("Trade Limit Per Day",2,1,10,1);


orbh = ValueWhen(newday,TimeFrameGetPrice("H",in1Minute*mins,0))+buffer;
orbl = ValueWhen(newday,TimeFrameGetPrice("L",in1Minute*mins,0))-buffer;

//removing the values of ORBH and ORBL until the breakoutmeasuretime is reached
orbh = IIf(TimeNum()<starttime,Null,orbh); //redefining the ORBH value
orbl = IIf(TimeNum()<starttime,Null,orbl); //redefining the ORBL value

Plot(orbh,"ORBH",colorYellow,styleThick);
Plot(orbl,"ORBL",colorYellow,styleThick);

//Initialization

Buy =0;
Sell = 0;
Short = 0;
Cover = 0;

longstoplevel = Null;
longtargetlevel = Null;

shortstoplevel = Null;
shorttargetlevel = Null;

//Trading Logic without Stop and Target

orbcondlong = IsNull(Ref(orbh,-1)) AND orbh>0 AND Open < orbh AND High > orbh;
orbcondshort = IsNull(Ref(orbl,-1)) AND orbl>0 AND Open > orbl AND low < orbl;


if(mode=="DISABLED")
{


//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong)  AND TimeNum()>=starttime AND TimeNum()<=endtime;
Sell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND TimeNum()<=endtime;
Cover = Cross(High,orbh) OR TimeNum()>=sqofftime;

//Removing Excessive Signals only for Entry
Buy = ExRem(Buy,Sell);
Short = ExRem(Short,Cover);

//removing excessive signals for the day
Buy = Buy AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
short = short AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;

//Remove Excessive Entry and Exit Signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

BuyPrice = ValueWhen(Buy,orbh);
SellPrice = ValueWhen(Sell,IIf(Cross(orbl,Low),orbl,Close));

ShortPrice = ValueWhen(Short,orbl);
CoverPrice = ValueWhen(Cover,IIf(Cross(High,orbh),orbh,Close));

buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);

}

if(mode=="POINTS")
{
//Trading Logic with Stop and Target (points)

//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong)  AND TimeNum()>=starttime AND TimeNum()<=endtime;
iSell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND TimeNum()<=endtime;
iCover = Cross(High,orbh) OR TimeNum()>=sqofftime;

//Removing Excessive Signals only for Entry
Buy = ExRem(Buy,iSell);
Short = ExRem(Short,iCover);

//removing excessive signals for the day
Buy = Buy AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
short = short AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;

//Calculate the Entry Price
BuyPrice = ValueWhen(Buy,orbh);
ShortPrice = ValueWhen(Short,orbl);

longstoplevel = BuyPrice - stop;
longtargetlevel = BuyPrice + target;

shortstoplevel = shortPrice + stop;
shorttargetlevel = shortPrice - target;

//Exit signal can happen due to 1)Negative Crossover 2)Stophit 3)Targethit
Sell = isell OR Cross(longstoplevel,Low) OR Cross(High,longtargetlevel);
Cover = icover OR Cross(High,shortstoplevel) OR Cross(shorttargetlevel,Low);

//Remove Excessive Entry and Exit Signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

//Long Exit Price
SellPrice = IIf(isell,ValueWhen(isell,orbl),
				IIf(Cross(longstoplevel,Low),longstoplevel,
					IIf(Cross(High,longtargetlevel),longtargetlevel,null)));
					
//Short Exit Price
CoverPrice = IIf(icover,ValueWhen(icover,orbh),
				IIf(Cross(High,shortstoplevel),shortstoplevel,
					IIf(Cross(shorttargetlevel,Low),shorttargetlevel,null)));

buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);

Plot(IIf(buycontinue,longstoplevel,Null),"BuyStop Level",colorRed,styleDashed);
Plot(IIf(buycontinue,longtargetlevel,Null),"BuyTarget Level",colorgreen,styleDashed);

Plot(IIf(shortcontinue,shortstoplevel,Null),"ShortStop Level",colorRed,styleDashed);
Plot(IIf(shortcontinue,shorttargetlevel,Null),"ShortTarget Level",colorgreen,styleDashed);


}

if(mode=="PERCENTAGE")
{
//Trading Logic with Stop and Target (Percentage)

//Trading Logic with Stop and Target (points)

//Entry Logic
Buy = (Cross(High,orbh) OR orbcondlong)  AND TimeNum()>=starttime AND TimeNum()<=endtime;
iSell = Cross(orbl,Low) OR TimeNum()>=sqofftime;
Short = (Cross(orbl,Low) OR orbcondshort) AND TimeNum()>=starttime AND TimeNum()<=endtime;
iCover = Cross(High,orbh) OR TimeNum()>=sqofftime;

//Removing Excessive Signals only for Entry
Buy = ExRem(Buy,iSell);
Short = ExRem(Short,iCover);

//removing excessive signals for the day
Buy = Buy AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;
short = short AND Sum(Buy OR Short,BarsSince(newday)+1)<=TradeLimit;

//Calculate the Entry Price
BuyPrice = ValueWhen(Buy,orbh);
ShortPrice = ValueWhen(Short,orbl);

longstoplevel = BuyPrice*(1 - stop/100);
longtargetlevel = BuyPrice * (1+target/100);

//Round it of to nearest Tick Size
longstoplevel = TickSz * round(longstoplevel/TickSz);
longtargetlevel = TickSz * round(longtargetlevel/TickSz);

shortstoplevel = shortPrice * (1 + stop/100);
shorttargetlevel = shortPrice * (1-target/100);

//Round it of to nearest Tick Size
shortstoplevel = TickSz * round(shortstoplevel/TickSz);  
shorttargetlevel = TickSz * round(shorttargetlevel/TickSz);

//Exit signal can happen due to 1)Negative Crossover 2)Stophit 3)Targethit
Sell = isell OR Cross(longstoplevel,Low) OR Cross(High,longtargetlevel);
Cover = icover OR Cross(High,shortstoplevel) OR Cross(shorttargetlevel,Low);

//Remove Excessive Entry and Exit Signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

//Long Exit Price
SellPrice = IIf(isell,ValueWhen(isell,orbl),
				IIf(Cross(longstoplevel,Low),longstoplevel,
					IIf(Cross(High,longtargetlevel),longtargetlevel,null)));
					
//Short Exit Price
CoverPrice = IIf(icover,ValueWhen(icover,orbh),
				IIf(Cross(High,shortstoplevel),shortstoplevel,
					IIf(Cross(shorttargetlevel,Low),shorttargetlevel,null)));

buycontinue = Flip(Buy,Sell);
shortcontinue = Flip(Short,Cover);

Plot(IIf(buycontinue,longstoplevel,Null),"BuyStop Level",colorRed,styleDashed);
Plot(IIf(buycontinue,longtargetlevel,Null),"BuyTarget Level",colorgreen,styleDashed);

Plot(IIf(shortcontinue,shortstoplevel,Null),"ShortStop Level",colorRed,styleDashed);
Plot(IIf(shortcontinue,shorttargetlevel,Null),"ShortTarget Level",colorgreen,styleDashed);


}

_SECTION_END();

_SECTION_BEGIN("Trading Signals");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(Sell * shapestar, colorBrightGreen, 0, High, 12);
PlotShapes(Cover * shapestar, colorRed, 0, Low, -12);

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();



//Dashboard Controls.


_SECTION_BEGIN("Trading Dashboard");



strg_name = ParamStr("Strategy Name","ORB Trading System");
fontsize = Param("Font Size",14,12,36,1);

GfxSelectFont("BOOK ANTIQUA", fontsize, 400);
GfxSetBkMode(1);  //Transparent Mode
GfxSetTextColor(colorWhite);

//build dyanmic dashboard colors based on the ongoing trades
color = IIf(buycontinue,colorGreen,IIf(shortcontinue,colorRed,colorGrey40));

GfxSelectPen(colorWhite);
GfxSelectSolidBrush(SelectedValue(color));

width = Status("pxchartwidth"); //output will be in terms of number of pixels
height = Status("pxchartheight");

//GfxRoundRect(20,height-150,320,height-30,15,15);

GfxGradientRect(20,height-150,320,height-30,SelectedValue(color),colorBlack);

sigstatus = WriteIf(buycontinue,"Buy Signal",WriteIf(shortcontinue,"Short Signal","No Trade - Relax"));
PNL =  IIf(buycontinue,Close-buyprice,IIf(shortcontinue,ShortPrice-close,Null));
GfxTextOut(strg_name,30,height-130);
GfxTextOut(sigstatus+" : "+IIf(buycontinue,BuyPrice,IIf(shortcontinue,ShortPrice,Null)),30,height-110);
GfxTextOut("Profit/Loss : "+SelectedValue(Prec(PNL,2)),30,height-90);


_SECTION_END();

_SECTION_BEGIN("Exploration Module");

EntryPrice = IIf(Buy,BuyPrice, IIf(Short,ShortPrice,Null));
ExitPrice = IIf(Sell,SellPrice, IIf(Cover,CoverPrice,Null));
StopPrice = IIf(Buy,longstoplevel, IIf(Short,shortstoplevel,Null));
TargetPrice = IIf(Buy,longtargetlevel, IIf(Short,shorttargetlevel,Null));
isignal = IIf(Buy,'B',IIf(Sell,'X', IIf(Short,'S',IIf(Cover,'C',Null))));

Filter = Buy OR Sell OR Short OR Cover;

AddColumn(EntryPrice,"Entry Level",1.2);
AddColumn(ExitPrice,"Exit Level",1.2);
AddColumn(StopPrice,"Stop Level",1.2);
AddColumn(TargetPrice,"Target Level",1.2);
AddColumn(isignal,"Signal Status",formatChar);

SetSortColumns(-2); //sort with the time (recent signals at the top)



_SECTION_END();

Hướng dẫn: Copy đoạn mã trên, mở AmiBroker Formula Editor, dán vào và lưu lại với tên tương ứng.