Thư viện AFL
Thư viện AFL
Nghiên cứu đột phá phạm vi mở (ORB) có thể kiểm tra lại cho Amibroker

Nghiên cứu đột phá phạm vi mở (ORB) có thể kiểm tra lại cho Amibroker

Thách thức chính với Nghiên cứu ORB cổ điển dành cho Amibroker là nó tạo ra quá nhiều tín hiệu trên biểu đồ trong ngày và việc kiểm tra ngược là không thể thực hiện được với nghiên cứu như vậy. Vấn đề này đã được ông Dinesh Tarte khắc phục bằng cách tinh chỉnh nghiên cứu ORB làm cho mã có thể được kiểm tra lại

Dinesh là Kỹ sư phần mềm chuyên nghiệp và là nhà giao dịch trong thị trường vốn và hàng hóa. Anh ấy nghiên cứu với nhiều phân tích kỹ thuật khác nhau và yêu thích phát triển các chiến lược trong

môi giới môi giới

. Điều đáng chú ý là anh là sinh viên của Marketcalls.

Quy tắc giao dịch ORB

  1. Mua sau 11:15 sáng nếu thị trường vượt qua ORBH (ORB-Cao) và thoát nhật ký với lợi nhuận 150 điểm trong trường hợp có tiền hoặc thoát ra vào khoảng 3:30 chiều hoặc nếu điểm dừng ORBL (ORB-Thấp).

  2. Ngắn sau 11:15 sáng nếu thị trường cắt xuống dưới ORBL (ORB-Thấp) và thoát lệnh bán với lợi nhuận 150 điểm trong trường hợp rút tiền hoặc thoát ra vào khoảng 3:30 chiều hoặc nếu điểm dừng lỗ ORBH (ORB- Cao) chạm

[wp_ad_camp_5]

Mã này làm gì?

Chiến lược ORB mẫu được hiển thị ở trên trên Biểu đồ tương lai tháng 4 của Ngân hàng Nifty. Trong đó mũi tên Xanh và Đỏ biểu thị Tín hiệu Mua và Bán tương ứng. Và Ngôi sao Xanh và Đỏ biểu thị Mua Thoát và Bán Thoát tương ứng.

Nghiên cứu ORB tính toán mức cao (ORBH) và mức thấp (ORBL) trong khoảng hai giờ đầu tiên, tức là từ 9 giờ 15 sáng đến 11 giờ 15 sáng. Nghiên cứu này sẽ đưa ra quyết định tín hiệu khi thị trường vượt qua phạm vi ở một trong hai phía sau 11:15 sáng. Tham số bên dưới trong mã đề cập đến thời gian mở, đóng và tín hiệu của thị trường. Ở đây tín hiệu đột phá sẽ chỉ xảy ra nếu ORBH và ORBL bùng phát sau 11:15 sáng.

Market_Start_Time=091500;

Thị trường_Open_Brakeout=111500;

Market_end_time=151500;

Mã đã được tối ưu hóa cho Bank Nifty và nó cũng mang lại lợi nhuận (giả sử là 150 điểm trong trường hợp Bank Nifty). Tuy nhiên, bạn có thể thay đổi giá trị theo cổ phiếu/chỉ số yêu thích của mình. Đoạn mã sau quyết định điểm mục tiêu

target_point=Tối ưu hóa(“target_point”,150,20,200,1);

Số lần dừng lỗ trong trường hợp có hai điều kiện

  1. Nếu tín hiệu thứ nhất đang hoạt động và thị trường vi phạm mức dừng lỗ, tức là ORBL là mức dừng lỗ trong trường hợp tín hiệu mua đang hoạt động

và ORBH là mức dừng lỗ trong trường hợp tín hiệu bán đang hoạt động

2)Vị thế sẽ đóng vào cuối ngày.

Hệ thống này hoàn toàn được tối ưu hóa cho ngân hàng tiện lợi và xem xét quy mô lô là 50 (2 lô) trong trường hợp của Ngân hàng Nifty. Mã này có thể được sử dụng với các cổ phiếu có hệ số beta cao như SBI và các cổ phiếu khác và được điều chỉnh theo thời gian đột phá như 1 giờ hoặc ½ giờ đầu tiên tùy thuộc vào phân tích và kinh nghiệm của bạn với nghiên cứu ORB.

Cài đặt Amibroker

Các cài đặt sau đây là bắt buộc để mã này hoạt động bình thường.

Đi tới->

Công cụ->Tùy chọn->Trong ngày

và Đặt thời gian của

thanh đánh dấu bên trong đầu tiên

như hình dưới đây

Tải xuống mã ORB Backtestable cho Amibroker

ORB có thể kiểm tra lại

Mã Amibroker

Lưu ý: Code đã test với phiên bản Amibroker 5.60

Bank_nifty_ORB – Báo cáo Backtest_Tháng 4 (1)

Liên quan

Mã nguồn (.afl)
// Developed by Dinesh R Tarte

_SECTION_BEGIN("Backtestable ORB");

SetBarsRequired(100000,0);

GraphXSpace = 15;

SetChartOptions(0,chartShowArrows|chartShowDates);

SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));

GfxSetBkMode(0); 

GfxSetOverlayMode(1);

SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));

Plot(C,"nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);



_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));



Market_Start_Time=091500;

Market_Open_Brakeout=111500; 

Market_end_time=151500; 

 

//need to consider 60 min insted of 100 //Market_Signal_time=Market_end_time - Market_Open_Brakeout;

Market_Signal_time=033000;

Min_in_signal_time=2190;                



Bars_in_Signal=210/5;

Total_No_Of_Every_Day_Bar=72;





target_point=Optimize("target_point",150,20,200,1);

SetPositionSize(1,spsShares);



//Total_No_Of_Every_Day_Bar=(Market_end_time-Market_Start_Time)/5(Time in Min)

printf("n Bars in the signal is =>" + Bars_in_Signal);

//(for 5 Min Chart divide by 5 AND for 15 Min Charts divide by 15 (Min))

printf("n market singal Time=>"+Market_Signal_time);

SetTradeDelays(1,1,1,1);

ST=MArket_start_time=091500;

BT=brake_out_time=111500; 

Currtime =TimeNum(); 

Currentdate=DateNum(); 

afterbreakout0 = Cross(TimeNum(),BT); 

printf("n Todays date is +" +NumToStr((Currentdate),formatDateTime )); 

Curren_Dae=Day(); 

SetPositionSize(1,spsShares);   

 

//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1 

  //IT will check the condition of the each bar .

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

printf("n Day+starttime  : " + Day() ); 

EndDay = (Day()!= Ref(Day(), 1)); 



printf("n newday Value is=>"+NewDay);

printf("n End day value is =>"+EndDay); 









printf("n EndDay  : " + EndDay ); 

starttime = Cross(TimeNum(),ST);

TimeNum()>ST; 

//it will caluclate the highest and lowest array from the start time 

//.its go on calculating entire array till next Day 

 Exit_Time = TimeNum() > Market_end_time; 



Highest_science = HighestSince(starttime,H,1); 

Lowest_science =LowestSince(starttime,L,1); 

 

WriteIf (IsNan(Highest_science) , "higest_scinece value is = 

"+Highest_science+"  ","")+"n"+ 

 

 

//it will calculate the high and low value of the BT time 

 

ORBH = ValueWhen(afterbreakout0,Highest_science,1); 

ORBL = ValueWhen(afterbreakout0,Lowest_science,1); 

 

 

//Plots ORB High and Low Line 

Plot(ORBH,"",colorGreen,styleDots); 

Plot(ORBL,"",colorBlue,styleDots); 

Buy=IIf(Cross(C,ORBH) AND (Currtime>BT) ,True,Null); 

Short =IIf((Cross(ORBL,C) AND (Currtime>BT)) ,True,Null); 

Shortflag=-99;

BarsToday = 1 + BarsSince( Day() != Ref(Day(), -1));

Buy_Bar_count=ValueWhen(Buy,BarsToday,1);

Short_bar_Count=ValueWhen(Short,BarsToday,1);



printf("n Buy signal coming at the bar => "+Buy_Bar_count);



printf ("n Today's date is =>"+ Date()); 

printf ("Bar is =>"+BarsToday); 





ReminingBarinDay=ReminingBarinDay_short=60;



Buy=ExRemSpan(Buy,ReminingBarinDay);

Short=ExRemSpan(Short,ReminingBarinDay_short) ;



//this is for when buy is active and short signal is coming

sellflag_short=IIf(Short==1,   True,0);

//Shortflag=Buyflag=IIf(NewDay == 1 ,2,Null);



//this is for when short is active and Buy signal is coming



Coverflag_buy=IIf(Buy==1,True,0);



// to set the flag when buy condition is true



 IIf(Buy==1,Buyflag=1,0);



BuyPrice1=ValueWhen(Buy,C,1);

SellPrice1=BuyPrice1+target_point; 



printf("n before sell signal coming SellPrice:-" +SellPrice1);

Sell_Cond=Cross(H,SellPrice1);

//Sell_Cond=IIf(H >=SellPrice1,True,False);

printf("n DD->Sell  Cond Value is =>"+Sell_Cond);



//short flag is used to close the condition when buy condition is active at the same time short is also active (in short when the buy signal is active short signal is coming so closing the position of buy @short price);



printf("n Buy flag value is =>"+BuyFlag);

printf("n Sell_flag_short value is =>"+Sellflag_short);





//Shortflag=Close the existing position when Short Signal arrived

//End Day:-close the open position at the end of the day 

    Sell=IIf(((BuyFlag==1) AND  ((Sell_Cond==1) OR (EndDay==1))),True ,Null);



//this is for when buy is active and short signal is coming

       Sell=IIf(((BuyFlag==1) AND (Sellflag_short==1 ) ),True ,Sell);













Shortflag=Buyflag=IIf(NewDay == 1  ,2,Null);



Sell=ExRem(Sell,Buy);







printf("n Buy Verible value is =>"+Buy);

printf("n Sell Verible value is =>"+Sell);



SellPrice=ValueWhen(Sell,H,1);

printf("n  sellsell price is :-" +SellPrice); 



ShortPrice=ValueWhen(Short,C,1); 



//Setting the flag when short condition is active



 IIf(Short==1,Shortflag=1,0);

 

printf("Short flag value is =>"+Shortflag);



printf("n short sell flag value is =>" +Sellflag_short);



ShortPrice1=ValueWhen(Short,C,1);



//Cover the Condition Of the Lower point



CoverPrice1=ShortPrice1-target_point;



printf ("Short price is for price1 is =>"+ ShortPrice1);

printf ("CoverPrice is for price1 is =>"+ CoverPrice1);

 

Cover_cond= IIf(L<=CoverPrice1,True,False); 

printf("n Cover Cond Value is =>"+Cover_Cond);



//Cover the position when Short is active AND Current price(L) is Less then Condition price OR Close the position end Of the Day  



Cover=IIf((ShortFlag==1) AND (Cover_Cond==1 OR EndDay==1),True,Null) ;



//this is for covering the position when buy signal is appering when short signal is active .clsoing the existing short position



Cover=IIf((ShortFlag==1) AND (Coverflag_buy==1),True,Cover);



printf("n Cover value is =>"+Cover);



CoverPrice=ValueWhen(Cover,C,1);



printf("n Cover price is ->"+CoverPrice);



Cover=ExRem(Cover,Short);



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(IIf(Sell, shapeStar, shapeNone),colorGreen, 0, H, Offset=-70); 

PlotShapes(IIf(Cover, shapeStar, shapeNone),colorBlue , 0, L, Offset=-70);

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.