Thư viện AFL
Thư viện AFL
Mô-đun mô phỏng giao dịch ảo Phiên bản 1.0 - Mã AFL Amibroker

Mô-đun mô phỏng giao dịch ảo Phiên bản 1.0 - Mã AFL Amibroker

Nghĩ đến việc ra mắt Trình mô phỏng giao dịch ảo đơn giản và thân thiện với người dùng để nghiên cứu/kiểm tra trực giác bên trong của bạn trước khi thực hành trên thị trường trực tiếp. Trình mô phỏng giao dịch ảo đi kèm với các nút điều khiển GUI để đặt tín hiệu ảo và bảng điều khiển giao dịch lãi lỗ để giao dịch lãi/lỗ hiện tại.

Các biến tĩnh liên tục được sử dụng để nắm bắt trạng thái của tín hiệu và sẽ được lưu tự động sau mỗi 30 giây. Nếu trường hợp cần xóa các tín hiệu ảo thì một điều khiển tham số để xóa các biến tĩnh đó sẽ được cung cấp.

Phiên bản Amibroker được hỗ trợ

Khuyến khích sử dụng phiên bản Amibroker 6.21 trở lên

Hiện tại, Tín hiệu được lấy vào lúc đóng nến và tín hiệu tương tự cũng được theo dõi trong Bảng điều khiển PNL. Nếu bất kỳ tín hiệu tương tự liên tiếp được đặt sẽ bị bỏ qua. Mã được thiết kế theo cách mà mọi tín hiệu vào phải được theo sau bởi tín hiệu thoát, nếu không tín hiệu sẽ bị bỏ qua.

Hãy cho tôi biết phản hồi, cải tiến và nhận xét của bạn bên dưới.

Có liên quan

Mã nguồn (.afl)
//Coded by Rajandran R - Founder (Marketcalls)
//Website - www.marketcalls.in / www.openalgo.in
//Coded Date - 15th Mar 2021

_SECTION_BEGIN("Marketcalls - Virtual Trade Simulator Module");

Version(6.25);

SetBarsRequired(-2,-2);
SetOption("StaticVarAutoSave", 30 );
clear = ParamTrigger("Clear Signals","Clear");

bi = BarIndex();
sbi = lastvalue(bi);
buttonclick = "Simulator"+sbi;

function GuiButtonTrigger( ButtonName, x, y, width, Height ) {
	
	global IDset;
	local id, event, clickeven;
	
	if( typeof( IDset ) == "undefined" ) IDset = 0; 

	//_TRACEF( "IDset before: %g", IDset );	
	GuiButton( ButtonName, ++IDset, x, y, width, height, 7 ); 
	//_TRACEF( "IDset after: %g", IDset );
	result = 0;
	id = GuiGetEvent( 0, 0 );// receiving button id
	event = GuiGetEvent( 0, 1 );// receiving notifyflag
	clickevent = event == 1;
	BuyClicked = id == 1 && clickevent;
	SellClicked = id == 2 && clickevent;
	ShortClicked = id == 3 && clickevent;
	CoverClicked = id == 4 && clickevent;
	if( BuyClicked AND StaticVarGet(Name()+GetChartID()+"buyClicked")==0 ) 
	{
		StaticVarSet(buttonclick,1,True);
		Say("Buy Button Clicked");
		result = 1;
		StaticVarSet(Name()+GetChartID()+"buyClicked",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"buyClicked",0);
	}
	if( SellClicked AND StaticVarGet(Name()+GetChartID()+"sellClicked")==0 ) 
	{
		StaticVarSet(buttonclick,-1,True);
		Say("Sell Button Clicked");
		result = -1;
		StaticVarSet(Name()+GetChartID()+"sellClicked",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"sellClicked",0); 
	}
	if( ShortClicked AND StaticVarGet(Name()+GetChartID()+"shortClicked")==0 ) 
	{
		StaticVarSet(buttonclick,-2,True);
		Say("Short Button Clicked");
		result = -2;
		StaticVarSet(Name()+GetChartID()+"shortClicked",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"shortClicked",0); 
	}
	if( coverClicked AND StaticVarGet(Name()+GetChartID()+"coverClicked")==0 ) 
	{
		StaticVarSet(buttonclick,2,True);
		Say("Cover Button Clicked");
		result = 2;
		StaticVarSet(Name()+GetChartID()+"coverClicked",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"coverClicked",0); 
	}
	return result;
	
}

_SECTION_END();

_SECTION_BEGIN("Button Plot and Mouse Click Detection Module");

BuyTrigger = GuiButtonTrigger( "Long Entry", 0, 100, 200, 30 );
SellTrigger = GuiButtonTrigger( "Long Exit", 0, 100+50, 200, 30);
ShortTrigger = GuiButtonTrigger( "Short Entry", 200, 100, 200, 30 );
coverTrigger = GuiButtonTrigger( "Short Exit", 200, 100+50, 200, 30 );
GuiSetColors( 1,1, 2, colorgreen, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 
GuiSetColors( 2,2, 2, colororange, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 
GuiSetColors( 3,3, 2, colorred, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 
GuiSetColors( 4,4, 2, colorBlue, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 

//initializing
Buy = Sell = Short = Cover = 0;

for(i=0; i< BarCount-1;i++)
{
sig = StaticVarGet("Simulator"+i);
if(sig == 1) Buy[i] = true;
if(sig == -1) Sell[i] = true;
if(sig == -2) Short[i] = true;
if(sig == 2) Cover[i] = true;

}

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

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

//Buy at Next Bar Open, Trade Delay is already given at 
BuyPrice=ValueWhen(Buy,close);
SellPrice=ValueWhen(Sell,Close);
ShortPrice=ValueWhen(Short,Close);
CoverPrice=ValueWhen(Cover,Close);

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


if(clear)
{


StaticVarRemove("Simulator*");


}


_SECTION_END();


_SECTION_BEGIN("Plot Buy and Sell Signals");

/* Plot Buy and Sell Signal Arrows */
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); //x-Axis will be plottted
//plot the candles
Plot(Close,"Close",colorDefault,GetPriceStyle() | styleNoTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
_SECTION_END();


_SECTION_BEGIN("Signal Dashboard");

showMsgBoard = ParamToggle("Message Board", "Hide|Show", 1);

if ( showMsgBoard == 1 )
{
Long=Flip(Buy,Sell); 
Shrt=Flip(Short,Cover); 
Relax = NOT Long AND NOT Buy AND NOT shrt AND NOT Short AND NOT Sell AND NOT Cover;
BarsSincebuy = BarsSince( Buy ); 
BarsSinceshort = BarsSince( Short ); 
LastSignal = IIf( BarsSincebuy < BarsSinceshort, 1, -1 ); 

GfxSelectFont( "BOOK ANTIQUA", 12, 100 );
GfxSetBkMode( 1 ); 
GfxSetTextColor( colorWhite ); 

//if ( SelectedValue( LastSignal ) == 1 )
if ( SelectedValue( Long ) == 1 ) 
{ 
	GfxSelectSolidBrush( colorDarkGreen ); 
} 
else if ( SelectedValue( Shrt ) == 1 )
{ 
	GfxSelectSolidBrush( colorDarkRed ); 
} 
else
{ 
	GfxSelectSolidBrush( colorDarkGrey ); 
} 

pxHeight = Status( "pxchartheight" ) ; 
xx = Status( "pxchartwidth"); 
Left = 1100; 
width = 310; 
x = 5; 
x2 = 300; 
y = pxHeight; 
y2 = y;

GfxSelectPen( colorWhite, 1); // border color 
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ; 
GfxTextOut( ( "Virtual Simulator V1.0"),13,y-93);

y2 = y2-70;
GfxTextOut( ("" + WriteIf(Buy, "Buy @ "+ BuyPrice, "")), 13, y2); 
GfxTextOut( ("" + WriteIf(Short, "Short @ "+ ShortPrice,"")), 13, y2); 
GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Long @ "+(BuyPrice),"")), 13, y2); 
GfxTextOut( ("" + WriteIf (shrt AND NOT Short, "Short @ "+(ShortPrice),"")), 13, y2); 
GfxTextOut( ("" + WriteIf (Relax, "No Trade Zone - Wait!","")), 13, y2); 


y2 = y2+20;
GfxTextOut( ("" + WriteIf (Long AND NOT Buy, "Current P/L: "+NumToStr((C-BuyPrice),1.2)+" Points","")), 13, y2); 
GfxTextOut( ("" + WriteIf (shrt AND NOT Short, "Current P/L: "+NumToStr((ShortPrice-C),1.2)+" Points","")), 13, y2); 

y2 = y2-20;
GfxTextOut( ("" + WriteIf (Sell AND NOT Short, "Exit Long @ "+ SellPrice ,"")), 13, y2);
GfxTextOut( ("" + WriteIf (Cover AND NOT Buy, "Exit Short @ "+ CoverPrice,"")), 13, y2);

y2 = y2+20;
GfxTextOut( ("" + WriteIf (Sell AND NOT Short, "P/L : "+NumToStr((SellPrice-BuyPrice),1.2)+" Points","")), 13, y2); 
GfxTextOut( ("" + WriteIf (Cover AND NOT Buy, "P/L : "+NumToStr((ShortPrice-CoverPrice),1.2)+" Points","")), 13, y2); 
}
_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.