程式交易教學

誠邀您參加全球知名外匯經紀商OANDA的自營交易(Prop Trader)

報名OANDA自營交易(Prop Trader),並通過我們的考核,您就可以使用OANDA提供的資金進行交易,獲得高達80%的交易利潤分成。



限時優惠代碼
在購買鈦金挑戰賽時輸入“TITANIUM30”,即獲得30%的折扣(優惠截止日期為2024年4月30日)。

優化了挑戰塞交易規則
無最低交易天數限制等優化了挑戰賽的交易規則。

500,000美元交易資金
您可以使用最高500,000美元的資金進行交易。

豐富的交易商品
您可以交易包括外匯、黃金、原油、股票指數等多種商品。



EDIT物件的參數定義與設定方法

定義製作新檔案時的表格位置等等

在本章內容中,將一邊製作「EDIT元件」的工具、一邊說明計算數據的方法。

參考文章:使用EDIT物件繪製週間計算表格的方法

EDIT物件原本是MT5專用的物件,在 MT4中亦能透過版本升級加以使用;該物件由矩形與文字組成,類似於文字框一樣,並且只能藉由程式製作而成。

本次將計算週一~週五的陽線、陰線、十字線數量,並將其計算結果製成表格。指定計算範圍的數值為「年」;該指定項目可從圖表上的EDIT物件進行變更。

首先開啟MT5列表中「工具」後再選擇「MetaQuotes語言編輯器」,創建新文檔選擇自訂指標建立「UpDownTable_DOW」檔案,並以參數先行定義表格位置。

顯示EDIT元件的X位置(橫向位置)為「POSX」、初始值為「0」;Y位置(縱向位置)為「POSY」、初始值為「15」;排列年與星期的標題列幅度為「WIDTH_TITLE」、初始值為「80」;排列陽線、陰線、十字線等數據的標題列幅度為「WIDTH_DATA」、初始值為「150」;高度為「HEIGHT」、初始值為「30」。

如此設定之下,表格將由排列星期的1列標題、3列數據(陽線、陰線、十字線)等共4列所構成。

MQL

由於本次將使用「OnChartEvent」,因此在「客製化指標的事件處理程序」中,僅需勾選「OnChartEvent」。如此即完成了檔案的準備工作。

OnChartEvent

設定EDIT的參數

可從MQL4幫助檔中取得EDIT物件的範例編碼。點擊MQL4相關參考的選單中的「Constants, Enumerations and Structures」→「Objects Constants」→「Object Types」,即可看見物件一覽表;從中選擇「OBJ_EDIT」,並複製該頁面內的下列編碼,再貼上至「ChartEvent function」下方。

//+——————————————————————+

//| Create Edit object |

//+——————————————————————+

bool EditCreate(const long chart_ID=0, // chart’s ID

const string name=”Edit”, // object name

const int sub_window=0, // subwindow index

const int x=0, // X coordinate

const int y=0, // Y coordinate

const int width=50, // width

const int width=50, // width

const string text=”Text”, // text

const string font=”Arial”, // font

const int font_size=10, // font size

const ENUM_ALIGN_MODE align=ALIGN_CENTER, // alignment type

const bool read_only=false, // ability to edit

const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring

const color clr=clrBlack, // text color

const color back_clr=clrWhite, // background color

const color border_clr=clrNONE, // border color

const bool back=false, // in the background

const bool selection=false, // highlight to move

const bool hidden=true, // hidden in the object list

const long z_order=0) // priority for mouse click

{

//— reset the error value

ResetLastError();

//— create edit field

if(!ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0))

{

Print(__FUNCTION__,

“: failed to create \”Edit\” object! Error code = “,GetLastError());

return(false);

}

//— set object coordinates

ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

//— set object size

ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);

ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);

//— set the text

ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

//— set text font

ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

//— set font size

ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

//— set the type of text alignment in the object

ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align);

//— enable (true) or cancel (false) read-only mode

ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only);

//— set the chart’s corner, relative to which object coordinates are defined

ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);

//— set text color

ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//— set background color

ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);

//— set border color

ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);

//— display in the foreground (false) or background (true)

ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//— enable (true) or disable (false) the mode of moving the label by mouse

ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//— hide (true) or display (false) graphical object name in the object list

ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//— set the priority for receiving the event of a mouse click in the chart

ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//— successful execution

return(true);

}

關於參數的排列,可將欲設定的部分置於前方、維持初始設定的部分則移至後方以利辨認。同時,本次的文字大小應變更為「14」、字體為「Meiryo」、文字顏色為「白色」、背景顏色為「黑色」、線條顏色為「白色」。如此即完成了參數的設定。

bool EditCreate(string name = “Edit”, // object name

const int x = 0, // X coordinate

const int y = 0, // Y coordinate

const int width = 50, // width

const int height = 18, // height

const string text = “Text”, // text

const bool read_only = true, // ability to edit

const color clr = clrWhite, // text color

const color back_clr = clrBlack, // background color

const color border_clr = clrWhite, // border color

const long chart_ID = 0, // chart’s ID

const int sub_window = 0, // subwindow index

const string font = “メイリオ”, // font

const int font_size = 14, // font size

const ENUM_ALIGN_MODE align = ALIGN_CENTER, // alignment type

const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring

const bool back = false, // in the background

const bool selection = false, // highlight to move

const bool hidden = true, // hidden in the object list

const long z_order = 0) // priority for mouse click

將EA自動程式交易應用於外匯與差價合約交易中

EA

我們以圖文形式詳細介紹有關EA自動程式交易的基本知識,以及在MT4/MT5平台上的安裝、參數設定方法、編碼等等內容。另外,對持有OANDA帳戶的客戶,還可以免費使用我們的獨有EA與指標工具。

誠邀您參加全球知名外匯經紀商OANDA的自營交易(Prop Trader)

報名OANDA自營交易(Prop Trader),並通過我們的考核,您就可以使用OANDA提供的資金進行交易,獲得高達80%的交易利潤分成。



限時優惠代碼
在購買鈦金挑戰賽時輸入“TITANIUM30”,即獲得30%的折扣(優惠截止日期為2024年4月30日)。

優化了挑戰塞交易規則
無最低交易天數限制等優化了挑戰賽的交易規則。

500,000美元交易資金
您可以使用最高500,000美元的資金進行交易。

豐富的交易商品
您可以交易包括外匯、黃金、原油、股票指數等多種商品。