誠邀您參加全球知名外匯經紀商OANDA的自營交易(Prop Trader)
報名OANDA自營交易(Prop Trader),並通過我們的考核,您就可以使用OANDA提供的資金進行交易,獲得高達90%的交易利潤分成。
優化了挑戰塞交易規則
無最低交易天數限制等優化了挑戰賽的交易規則。
500,000美元交易資金
您可以使用最高500,000美元的資金進行交易。
豐富的交易商品
您可以交易包括外匯、黃金、原油、股票指數等多種商品。
運用MQL程式語言 在圖表中繪製按鈕的方法
使按下按鈕的過程更加順暢
在「運用MQL程式語言在圖表中新增按鈕的方法」中,進行了新增按鈕、安裝切換顯示/隱藏符號的功能。參考文章:運用MQL程式語言在圖表中新增按鈕的方法
接下來將定義一項DrawArrow函數,並書寫可在其中繪製箭頭的程式。
雖然與繪製start函數箭頭的內容相同,但若使用同一文法,便可能在後續修正時出現錯誤,因此需統整來使用函數。DrawArrow函數將如同以下所示進行定義。
//+——————————————————————+定義DrawArrow函數之後,將放置於start函數的位置。
//| Draw function |
//+——————————————————————+
void DrawArrow()
{
int limit = MathMin(Bars – 1, BARS);
ObjectsDeleteAll(0, “3RCI_Sign_”);
for(int i = limit; i >= 0; i–) {
if (!ObjectGetInteger(0, “Button”, OBJPROP_STATE)) continue;
bool upNow = RCI0[i] > RCI1[i] && RCI1[i] > RCI2[i];
bool upPre = RCI0[i + 1] > RCI1[i + 1] && RCI1[i + 1] > RCI2[i + 1];
bool dnNow = RCI0[i] < RCI1[i] && RCI1[i] < RCI2[i];
bool dnPre = RCI0[i + 1] < RCI1[i + 1] && RCI1[i + 1] < RCI2[i + 1];
if (upNow && !upPre) {
string name = “3RCI_Sign_” + (string)i;
ObjectCreate(0, name, OBJ_ARROW, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_TIME, 0, Time[i]);
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, Low[i]);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_TOP);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 2);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrRed);
ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 233);
}
if (dnNow && !dnPre) {
string name = “3RCI_Sign_” + (string)i;
ObjectCreate(0, name, OBJ_ARROW, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_TIME, 0, Time[i]);
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, High[i]);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_BOTTOM);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 2);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrDodgerBlue);
ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 234);
}
}
}
int start()接下來將以此設定按下按鈕時的動作。
{
int counted_bars = IndicatorCounted();
//—- check for possible errors
if(counted_bars < 0) return -1;
//—- last counted bar will be recounted
if(counted_bars > 0) counted_bars–;
int limit = MathMin(Bars – 1, BARS);
for(int i = limit; i >= 0; i–) {
RCI0[i] = iRCI(NULL, 0, PERIOD_S, i);
RCI1[i] = iRCI(NULL, 0, PERIOD_M, i);
RCI2[i] = iRCI(NULL, 0, PERIOD_L, i);
}
DrawArrow();
return 0;
}
//+——————————————————————+如此一來,按下按鈕時的動作將更加順暢,並能在按下的瞬間切換顯示/隱藏箭頭。
//| ChartEvent function |
//+——————————————————————+
void OnChartEvent(const int id, // Event identifier
const long& lparam, // Event parameter of long type
const double& dparam, // Event parameter of double type
const string& sparam) // Event parameter of string type
{
//— the left mouse button has been pressed on the chart
if(id== CHARTEVENT_OBJECT_CLICK) {
if (sparam == “Button”) {
DrawArrow();
}
}
}
原始碼
本次製作的原始碼如以下所示。//+——————————————————————+
//| 3RCI_Sign |
//| HT FX |
//| http://htfx.blog.fc2.com/ |
//+——————————————————————+
#property copyright “HT FX”
#property link “http://htfx.blog.fc2.com/”
#property description “Copyright (C) 2020 HT FX All Rights Reserved.\n”
#property description “http://htfx.blog.fc2.com/\n”
#property description “htfxjp@gmail.com”
#property version “1.00”
#property strict
#property indicator_separate_window
#property indicator_maximum 1
#property indicator_minimum -1
#property indicator_buffers 3
#property indicator_plots 3
#property indicator_color1 clrWhite
#property indicator_color2 clrYellow
#property indicator_color3 clrRed
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_SOLID
//+——————————————————————+
//| Input parameters |
//+——————————————————————+
input int BARS = 500; // 計算K線數量
input int PERIOD_S = 10; // 短期
input int PERIOD_M = 20; // 中期
input int PERIOD_L = 50; // 長期
//— indicator buff
double RCI0[], RCI1[], RCI2[];
//+——————————————————————+
//| Custom indicator initialization function |
//+——————————————————————+
int init()
{
IndicatorSetInteger(INDICATOR_DIGITS, 6);
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(0, RCI0, INDICATOR_DATA);
SetIndexBuffer(1, RCI1, INDICATOR_DATA);
SetIndexBuffer(2, RCI2, INDICATOR_DATA);
SetIndexLabel(0, “RCI(” + (string)PERIOD_S + “)”);
SetIndexLabel(1, “RCI(” + (string)PERIOD_M + “)”);
SetIndexLabel(2, “RCI(” + (string)PERIOD_L + “)”);
string name = “RCI(” + (string)PERIOD_S + “,” + (string)PERIOD_M + “,” + (string)PERIOD_L + “)”;
IndicatorSetString(INDICATOR_SHORTNAME, name);
ButtonCreate(0, “”Button””, ChartWindowFind(), 0, 15);
return 0;
}
//+——————————————————————+
//| Custom indicator deinitialization function |
//+——————————————————————+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, “3RCI_Sign_”);
if (reason == REASON_PARAMETERS || reason == REASON_RECOMPILE || reason == REASON_REMOVE)
ObjectDelete(“Button”);
}
//+——————————————————————+
//| Custom indicator iteration function |
//+——————————————————————+
int start()
{
int counted_bars = IndicatorCounted();
//—- check for possible errors
if(counted_bars < 0) return -1;
//—- last counted bar will be recounted
if(counted_bars > 0) counted_bars–;
int limit = MathMin(Bars – 1, BARS);
for(int i = limit; i >= 0; i–) {
RCI0[i] = iRCI(NULL, 0, PERIOD_S, i);
RCI1[i] = iRCI(NULL, 0, PERIOD_M, i);
RCI2[i] = iRCI(NULL, 0, PERIOD_L, i);
}
DrawArrow();
return 0;
}
//+——————————————————————+
//| Draw function |
//+——————————————————————+
void DrawArrow()
{
int limit = MathMin(Bars – 1, BARS);
ObjectsDeleteAll(0, “3RCI_Sign_”);
for(int i = limit; i >= 0; i–) {
if (!ObjectGetInteger(0, “Button”, OBJPROP_STATE)) continue;
bool upNow = RCI0[i] > RCI1[i] && RCI1[i] > RCI2[i];
bool upPre = RCI0[i + 1] > RCI1[i + 1] && RCI1[i + 1] > RCI2[i + 1];
bool dnNow = RCI0[i] < RCI1[i] && RCI1[i] < RCI2[i];
bool dnPre = RCI0[i + 1] < RCI1[i + 1] && RCI1[i + 1] < RCI2[i + 1];
if (upNow && !upPre) {
string name = “3RCI_Sign_” + (string)i;
ObjectCreate(0, name, OBJ_ARROW, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_TIME, 0, Time[i]);
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, Low[i]);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_TOP);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 2);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrRed);
ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 233);
}
if (dnNow && !dnPre) {
string name = “3RCI_Sign_” + (string)i;
ObjectCreate(0, name, OBJ_ARROW, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_TIME, 0, Time[i]);
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, High[i]);
ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_BOTTOM);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 2);
ObjectSetInteger(0, name, OBJPROP_COLOR, clrDodgerBlue);
ObjectSetInteger(0, name, OBJPROP_ARROWCODE, 234);
}
}
}
//+——————————————————————+
//| ChartEvent function |
//+——————————————————————+
void OnChartEvent(const int id, // Event identifier
const long& lparam, // Event parameter of long type
const double& dparam, // Event parameter of double type
const string& sparam) // Event parameter of string type
{
//— the mouse has been clicked on the graphic object
if(id==CHARTEVENT_OBJECT_CLICK) {
if (sparam == “Button”) {
DrawArrow();
}
}
}
//+——————————————————————+
//| Create the button |
//+——————————————————————+
bool ButtonCreate(const long chart_ID=0, // chart’s ID
const string name=”Button”, // button name
const int sub_window=0, // subwindow index
const int x=0, // X coordinate
const int y=0, // Y coordinate
const int width=40, // button width
const int height=24, // button height
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text=”Sign”, // text
const string font=”Arial”, // font
const int font_size=10, // font size
const color clr=clrBlack, // text color
const color back_clr=C’236,233,216′, // background color
const color border_clr=clrNONE, // border color
const bool state=true, // pressed/released
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 the button
if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
{
Print(__FUNCTION__,
“: failed to create the button! Error code = “,GetLastError());
return(false);
}
//— set button coordinates
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//— set button size
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//— set the chart’s corner, relative to which point coordinates are defined
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//— 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 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);
//— set button state
ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
//— enable (true) or disable (false) the mode of moving the button 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);
}
將EA自動程式交易應用於外匯與差價合約交易中
我們以圖文形式詳細介紹有關EA自動程式交易的基本知識,以及在MT4/MT5平台上的安裝、參數設定方法、編碼等等內容。另外,對持有OANDA帳戶的客戶,還可以免費使用我們的獨有EA與指標工具。
誠邀您參加全球知名外匯經紀商OANDA的自營交易(Prop Trader)
報名OANDA自營交易(Prop Trader),並通過我們的考核,您就可以使用OANDA提供的資金進行交易,獲得高達90%的交易利潤分成。
優化了挑戰塞交易規則
無最低交易天數限制等優化了挑戰賽的交易規則。
500,000美元交易資金
您可以使用最高500,000美元的資金進行交易。
豐富的交易商品
您可以交易包括外匯、黃金、原油、股票指數等多種商品。