面向初學者的 MQL4 語言系列之3——技術指標和內置函數

簡介

這是“面向初學者的 MQL4 語言”系列的第三篇文章。在前兩篇文章中, 我們學習了 MQL4 的基礎知識,它們是進一步開發的基石。現在我們將學習使用內置 函數和用於技術指標的函數。後者對於以後開發你自己的 Expert Advisor 和指標至 關重要。另外,我們將通過一個簡答的例子,解釋如何追蹤進入市場的交易信號, 以及如何正確使用指標。在文章的末尾,你將學到一些關於語言本身的新鮮有趣的內容。



數學函數

讓我們從最簡單但仍在使用且有幫助的數學函數開始。



MathAbs

函數原型:

double MathAbs(double value)

這是非常簡單的函數,返回絕對值(數字模塊)。它的意思是,如果你使用了負數,則會得到一個正數結果。使用示例:

int a=-10;
double b=-20.0;
double c=7.0;
 
a=MathAbs(a); // now a is equal to 10
b=MathAbs(b); // now b is equal to 20.0
c=MathAbs(c); // the value of c will not change, for it was positive


MathCeil、MathFloor 和 MathRound

函數的原型:

double MathCeil(double x)
double MathFloor(double x)
double MathRound(double value)

這三個函數非常類似:它們均將數字圓整爲整數。 但每個都有其獨特性:MathCeil 的圓整方式爲: 即使我們有一個整數的千分之一(例如,1.001),它依然被視爲一個整數。 即數字被向上圓整爲更大的值。例如:

double a;
a=MathCeil(1.001);  // a=2.0, even one thousandth is rounded off to a whole number
a=MathCeil(1.999);  // a=2.0
a=MathCeil(-1.001); // a=-1.0, it is correct, because -1.0 is more than -1.001
a=MathCeil(-1.999); // a=-1.0, it is correct, -1.0 is more than -1.999

MathFloor 跟 MathCeil 類似,但正好相反。即如果需要向下圓整一個正數,則會損失小數部分:

double a;
a=MathFloor(1.999); // a=1.0, no matter how large the fractional part is, it will be taken away
a=MathFloor(1.001); // a=1.0
a=MathFloor(-1.001); // a=-2.0, correct, because -2.0 is less than -1.001
a=MathFloor(-1.999); // a=-2.0, correct, -2.0 is less than -1.999

我們對MathRound 圓整數字的方式較爲熟悉。即如果小數部分較大( 0.5 或以上),則圓整爲 1。如果小數部分較小(小於 0.5),則圓整爲 0,即直接忽略。示例:

double a;
a=MathRound(1.1);   // a=1.0, the fractional part is too small (0.1)
a=MathRound(1.57);  // a=2.0, the fractional part is enough to be rounded off to 1
a=MathRound(-3.1);  // a=-3.0 not enough
a=MathRound(-6.99); // a=-7.0 enough


MathMin

函數的原型:

double MathMax(double value1, double value2)
double MathMin(double value1, double value2)

這兩個函數非常類似。它們接受 2 個參數,相應的返回最大值和最小值。示例:

double a;
a=MathMax(50.0,1.0);  // a=50.0
a=MathMin(10.0,12.0); // a=10.0

函數原型:

double MathPow(double base, double exponent)

該函數允許取底數的冪次方。示例:

double a;
a=MathPow(5.0,2.0);  // a=25.0, 5 to the power 2
a=MathPow(2.0,8.0);  // a=256.0, 2 to the power 8
a=MathPow(25.0,0.5); // a=5.0, you know, a number to the power 0.5 is its square root

函數原型:

double MathSqrt(double x)

使用該函數求平方根。但不要嘗試求負數的平方根。這樣的話,會返回零。示例:

double a;
a=MathSqrt(9.0);    // a=3.0
a=MathSqrt(25.0);   // a=5.0
a=MathSqrt(-256.0); // a=0.0, I explained

函數原型:

double MathLog(double x)

還有人記得什麼是對數嗎?以 b 爲底 a 的對數等於以 b 爲底獲得 a 所需要的冪次方。 廣泛使用的對數是以 e 爲底(歐拉數)的自然對數(lna)和以 10 爲底的常用(布氏)對數(lg a)。 關於對數的更多信息可見於:http://en.wikipedia.org/wiki/Logarithm, 因此,MathLog 用於求數字 x 的自然對數。不要對負數或零求自然對數。這種情況下,會得到 -1。使用函數的示例:

double a;
a=MathLog(10.0);  // a=2.30258509
a=MathLog(0.0);   // a=-1.0, incorrect
a=MathLog(-10.0); // a=-1.0, incorrect

函數原型:

double MathExp(double d)

該函數返回數字 e,取 d次冪。很多人一定已經忘記了這個數字。 e 是數字常數,自然對數的底,無理數和超越數。e = 2,718281828459045…有時候 e 被稱爲歐拉數納皮爾數。 在微分和積分學中起着重要作用。關於歐拉數的更多信息可見於:http://en.wikipedia.org/wiki/Eulerian_number 如果指定一個非常大的度數,則會發生溢出,從而返回零。多大才會導致錯誤呢?爲了找出答案,我們來做一個小實驗:

double exponent=1.0; // here the degree value will be stored
double result=1.0;   // result, returned by the function
int i=0;             // number of cycle iterations
 
while(result!=0.0)   // while the result is not equal to zero (while there is no overflowing)
{
   result=MathExp(exponent); // remember the result
   exponent*=10.0;           // increase the degree
   i++;                      // the next iteration is over
}
MessageBox("i="+i); // result of the experiment

發生以下情形:每次嘗試調用 MathExp 函數,以及每次循環時度數增長了 10 倍,直到最後出現溢出,返回零。我得到以下結果:i=310。這意味着你可以使用 1*10 度數對 309 的乘方運算(想一下長達 309 位的數字!!)。所以,我認爲不需要擔心溢出。



MathMod

函數原型:

double MathMod(double value,double value2)

該函數用來找到除法的餘數。例如,5 除以 2 得 2 餘 1。第一個參數value - 被除數,value2 - 除數。返回餘數。示例:

double a;
 
a=MathExp(5,2); // a=1.0
a=MathExp(10,3); // a=1.0, correct
a=MathExp(50,10); // a=0.0, divided without residue

函數的原型:

int MathRand() void MathSrand(int seed)

MathRand 返回介於 0 和 32767 範圍內的僞隨機整數。這裏你可能會有些疑惑:“僞”是什麼意思? 這個範圍很奇怪,如果我需要 5 到 10 的範圍怎麼辦?爲什麼非得是 32767?答案是:“僞” 意味着數字並非完全隨機,而是取決於某些事情。假設,你已經編寫了一個腳本,返回了 5 個僞隨機數字。例如:

int a=0;
 
while(a<5)
{
   MessageBox(“random=”+MathRand());
   a++;
}

這些數字確實是隨機的,但如果你再次運行腳本,序列始終是相同的。原因在於,存在函數 MathRand 開始排斥的數字。 讓我們稱該數字爲起始數字。爲了改變它,使用另一個函數 - MathSrand。 該函數接受單個參數——起始數字,它決定所有的僞隨機數。假設起始數字爲一粒果實, 則隨機數字就是從中生長的大樹。默認的起始數字爲 1。爲了獲得真正的隨機序列,我們先要給起始數字分配唯一的值。 如何去做呢?還有一個函數 - TimeLocal,它沒有參數,返回自 1970 年 1 月 1 日 00:00 起的秒數。 該函數非常適合,因爲在大多數情況下我們將獲得唯一的數字。是不是開始糊塗了?它看起來如下所示:

int a=0;
MathSrand(TimeLocal()); // assign a unique value to the beginning number
 
while(a<5)
{
   MessageBox(“random=”+MathRand());
   a++;
}

現在每次我們都會得到一個新的序列。讓我們繼續。從 0 到 32767。爲什麼是 32767? 原因在於:int 能夠接受的最大值是 2 的 16 次方(因爲在不考慮符號時,int 變量值在計算機內存中佔了 16 位),即 32768,因爲我們從零計數,所以需要減去 1。這樣就得到 32767 。爲了得到任意的必要範圍,使用運算符 % - 除法中的餘數。例如,如果需要得到 0 到 5 範圍的隨機數字:

int a=0;
MathSrand(TimeLocal());
while(a<5)
{
   MessageBox(“random=”+MathRand()%6);
   a++;
}

請注意,我們寫入 MathRand()%6 而非 MathRand()%5 - 我們的範圍從開始,需要加 1。現在假設我們需要得到 5 到 10 範圍內的隨機數字:

MessageBox(“random=”+MathRand()%6+5); // just add the necessary shift

當需要包括負數的範圍時,例如 -5 到 5,方法一樣。

MessageBox(“random=”+MathRand()%11-5);

如果只需要負數,將結果乘以 -1。例如,我們需要 -10 到 -20 的範圍:

MessageBox(“random=”+(MathRand()%11+10)*(-1));

如果需要得到非整數,例如在 0.0 到 1.0 範圍內,且精確到千分位,使用以下代碼:

MessageBox(“random=”+MathRand()%1001/1000.0);

我們先創建一個 0 到 1000 範圍的隨機數字,然後除以 1000.0。注意,必須除以 1000.0(帶一個浮點),而不是 1000(整數)。 否則會得到零,因爲會被圓整。



三角函數和反三角函數

三角函數是基於角度的數學函數。它們在分析週期性過程時非常重要。與之密切相關的是反三角函數。 更多信息可見於:http://en.wikipedia.org/wiki/Trigonometric_function http://en.wikipedia.org/wiki/ArcSin在 MQL4 中,所有這些函數接受以弧度而非度數表示的參數。即,如果要求 20 度的正弦,必須先將 20 度轉換爲弧度。例如:

MathSin(20.0*3.14159/180.0);

即 1 度 = pi / 180。如果你經常使用三角函數,則在程序開始時聲明並使用該常數較爲方便。

#define PI 3.1415926535897


MathSin、MathCos、MathTan、MathArcsin、MathArccos 和 MathArctan

函數的原型:

double MathSin(double value) double MathCos(double value) double MathTan(double x) double MathArcsin(double x) double MathArccos(double x) double MathArctan(double x)

讓我們對部分函數的特性深入探討一下。MathTan 接受 -263 到 263 範圍內的值,如果超過限值,數字將變爲不確定。MathArcsin 和 MathArccos 接受 -1 到 1 範圍內的值,否則會得到 0 和 EA 日誌內的相應信息。MathArctan 如果接受 0 則返回 0。



顯示信息的新函數

目前你僅知道一個顯示信息的函數 - MessageBox。現在你將學習另外三個非常相似但各具特性的函數。



Alert

函數原型:

void Alert(...)

顯示包含你的信號(信息)的對話框。調用該函數時,會聽到特殊的信號,可以在終端設置中更改或禁用:Service -> Settings -> tab Events.窗口外觀如下:

可以更改窗口的尺寸,以便於查看大量信息。另外,可以始終查看函數的最新調用,因爲他們不會被刪除。還可以進行連續多次調用,將會得到具有活動的最新信號的窗口,不需要每次都點擊“確定”。可以使用類似 MessageBox 的函數:

Alert(“signal type:”+signalType); Alert(“random=”+MathRand()%1001);

儘管目的不同。你應該直接列舉輸入的參數,用逗號分隔。即類似於上例,但使用 “,”代替“+”。我建議使用第二種。

Alert(“signal type:”,signalType); Alert(“random=”,MathRand()%1001);


Comment

函數原型:

void Comment(...)

相似的函數,用法一致,在圖表左上角顯示信息。這裏你不需要點擊任何區域即可執行代碼。使用該函數以顯示當前狀態等。示例:

Comment(“some usefull information”);

 

Print

函數原型:

void Print( ...)

又一個類似的函數,在 Expert Advisor 的日誌中顯示信息:

Print(“processing...”);

另外,日誌在電腦上 MetaTrader 4\experts\logs 文件夾內的相應文件(文件名稱跟日期對應)中保存所有的信息:

還應該對三個函數進行註釋。無法顯示數組,只能像參數一樣指示。它們應該按元素逐個進行顯示,例如:

for(int a=0;a<100;a++) Alert("Close[",a,"]=",Close[a]);

每個函數最多可以顯示 64 個參數。每次調用 Alert 函數也會寫入 Expert Advisor 日誌。double 類型將顯示精確到小數點後 4 位數字。



技術指標

幾乎所有的 Expert Advisor 都使用技術指標。如果看一下安裝文件(MACD Sample)中包含的簡單 EA,可以看到它使用了技術指標。現在你將學習如何獲取所有可用技術指標的值。每一個技術指標都有一個對應的函數,可以計算任何可用證券和時間範圍上的數值。不必擔心指標是否已在圖表上打開。這無所謂。

現在讓我們查看技術指標的函數的參數細節。實際上其中大多數是重複的。例如,我們要講解的所有函數都有相似的 2 個第一參數1 個最後參數以計算技術指標的值。

  • 交易品種 – 定義應該用於計算技術指標值的金融證券(貨幣對)的第一個參數。即技術指標應該用於什麼圖表。要在當前圖表上使用指標,使用常量 NULL(或 0)。此處的當前圖表指的是將運行腳本(Expert Advisor,指標)的圖表。如果需要另一個證券,可以使用其名稱作爲字符串(“EURUSD”、“GBPUSD”等等)。
  • 時間範圍 – 第二個參數,定義應使用指標的時間範圍。如果需要當前圖表上使用的時間範圍,使用 0(零)。如果需要其他時間範圍,使用預定義的常量之一:
    • PERIOD_M1 - 1 分鐘
    • PERIOD_M5 - 5 分鐘
    • PERIOD_M15 - 15 分鐘
    • PERIOD_M30 - 30 分鐘
    • PERIOD_H1 - 1 小時
    • PERIOD_H4 - 4 小時
    • PERIOD_D1 - 1 天
    • PERIOD_W1 - 1 周
    • PERIOD_MN1 - 1 月
  • 偏移 – 定義應該使用指標的柱的最後一個參數。記住第一篇文章:要找到最後一根柱的收盤價,我們使用了從零開始的指數。即 Close [0] - 最後一根柱的收盤價,Close[1] - 倒數第二根柱,以此類推。該參數跟數組中的索引工作方式類似。要找到最後一根柱上的指標數值,偏移必須等於 0,倒數第二個柱爲 1,以此類推。

技術指標通常用於計算多個柱上的平均值。即它們取多個柱上的不同價格(開盤價、收盤價等),使用確定的方法找到平均值。也經常使用偏移。在參數當中,可以發現以下:

  • applied_price – 定義應該使用什麼價格類型以獲取平均值。對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • ma_method – 定義一種用於接收平均值的方法。對於選擇一種方法,有以下預定義的常量:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • period – 定義將使用多少柱獲取平均值。
  • ma_shift – 柱內中線的偏移。如果偏移爲正,則線右移。相反,如果偏移爲負,則線左移。

以上描述的參數會經常出現。所以,當你看到這種參數,應該瞭解該函數使用平均值進行數值計算。爲了瞭解數值究竟如何計算以及平均值到底扮演了什麼角色,使用每個函數的簡短描述後面的鏈接。還有一個重要的注意事項:所有這些指標(函數)可以分爲兩類:

  • 簡單 – 一個指標只有一個值。例如:加速/減速(AC)指標、累積/派發(A/D)指標、DeMarker(DeM)指標等等,即指標只有一條線/一個柱形圖,其數值在調用適當的函數時返回。以下是一個圖表上使用多個簡單指標的示例:

  • 複雜 – 一個指標有多個值(線)。例如:鱷魚指標、平均方向性運動指標(ADX)、布林帶指標(BB)、指數平滑移動平均線指標(MACD)等等。此時需要指明指標應該返回什麼值(線)。爲此,在所有複雜指標的函數中均使用 mode 參數。使用某些常量需要指明應該返回什麼。以下是一個圖表上使用多個複雜指標的示例:

每個函數描述配以描述性圖片、使用示例(使用不同的顏色以更好的查看哪部分對應哪部分)和帶有指標描述的鏈接(如何在交易中使用、指標的含義)。你應該熟悉指標並在實踐中使用。我建議閱讀本文中對函數的描述,以理解如何使用並查看示例。但爲了日後記住每個參數的分配,使用 MetaEditor 中的“幫助”。使用熱鍵 Ctrl+T 打開工具箱 窗口,前往幫助選項卡。在這裏,你會發現對每個參數的描述,以及所有函數的快捷列表,可以輕鬆找到所需要的函數。“幫助”中的語言可以使用查看 ->語言菜單更改。之後重啓 MetaEditor



加速/減速(AC)指標

加速/減速(AC)指標用於更改價格變動的速度(加速、減速)。http://ta.mql4.com/indicators/bills/acceleration_deceleration

函數原型:

double iAC(string symbol, int timeframe, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • shift – 定義應該使用指標的柱。

使用示例:



double ac;
 
ac=iAC(0,0,0);
// acceleration of the last bar on the active chart and timeframe 

ac=iAC(0,0,1);
// acceleration of the last but one bar on the active chart and timeframe 

ac=iAC("GBPUSD",PERIOD_M30,0);
// acceleration of the last bar on the chart GBPUSD, timeframe - 30 minutes

累積/派發(A/D)指標

累積/派發(A/D)指標通過交易量計算確認價格變動。http://ta.mql4.com/indicators/volumes/accumulation_distribution 函數原型:

double iAD(string symbol, int timeframe, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • shift – 定義應該使用指標的柱。

使用示例:



double ad;
 
ad=iAD(0,0,0);
// accumulation on the last bar on the current chart and period 

ad=iAD(0,0,Bars-1);
// accumulation on the first available bar, active chart and period 

ad=iAD("GBPUSD",PERIOD_M5,5);
// accumulation on the 6th last bar on GBPUSD, period - 5 minutes

鱷魚指標

鱷魚指標是三根移動平均線的組合,使用分形幾何和非線性動力學。http://ta.mql4.com/indicators/bills/alligator 函數原型:

double iAlligator( string symbol, int timeframe, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int ma_method, int applied_price, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • jaw_period - 鱷魚下顎平均週期(藍線)
  • jaw_shift - 藍線相對偏移量
  • teeth_period - 鱷魚牙齒平均週期(紅線)
  • teeth_shift - 紅線相對偏移量
  • lips_period - 鱷魚嘴脣平均週期(綠線)
  • lips_shift - 綠線相對偏移量
  • ma_method – 定義一種用於接收平均值的方法。對於選擇一種方法,有以下預定義的常量:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • mode – 定義要返回的數據(下顎、牙齒或嘴脣)。對於選擇使用常量之一:
    • MODE_GATORJAW - 鱷魚的下顎線(藍色)
    • MODE_GATORTEETH - 鱷魚的牙齒線(紅色)
    • MODE_GATORLIPS - 鱷魚的嘴脣線(綠色)
  • shift – 定義應該使用指標的柱。

在圖表上使用鱷魚指標時,注意函數參數代表的功能。這種類比將幫助你:

使用模式參數,定義應返回內容:

使用示例:


double jaw;
double teeth;
double lips;
 
jaw=iAlligator(0,0,13,8,8,5,5,3,MODE_SMA,PRICE_MEDIAN,MODE_GATORJAW,0);
// find the values of "jaws" (blue line) on the current chart and period.  
// Here simple moving average is used, price – average. Periods 
// of averaging for jaws, teeth and lips – 13, 8 and 8 accordingly. Shift: 
// 5, 5 and 3 accordingly. The value is taken for the last bar.
 
teeth=iAlligator(EURUSD,PERIOD_H1,128,96,64,0,0,0,MODE_EMA,PRICE_TYPICAL,MODE_GATORTEETH,1);
// find the values of "teeth" (red line) on an hour chart EURUSD. 
// Exponential moving average and typical price are used. 
// Periods of averaging: 128, 96 and 64. Shift is not used. The value
// is taken for the last but one bar.
 
lips=iAlligator(GBPUSD,PERIOD_D1,21,18,13,5,3,0,MODE_SMMA,PRICE_WEIGHTED,MODE_GATORLIPS,5);
// find the values of "lips" (green line) on a daily chart GBPUSD. 
// Uses smoothed moving average and weighted close price.
// Periods of averaging: 21, 18 and 13. Shift: 5, 3 and 0. The value 
// is taken for the 5th last bar.

平均方向性運動指標(ADX)

平均方向性運動(ADX)指標用於確定價格趨勢的出現。http://ta.mql4.com/indicators/trends/average_directional_movement 函數原型:

double iADX(string symbol,int timeframe,int period,int applied_price,int mode,int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • 週期 – 柱的數量,用於得出平均值。
  • 模式 – 選擇一條線,其數值將會被接收。使用以下預定義的常量:
    • MODE_MAIN - 主線
    • MODE_PLUSDI - +DI 線
    • MODE_MINUSDI - –DI 線
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double main;    // main line
double plusDi;  // line +DI
double minusDi; // line -DI
 
main=iADX(0,0,3,PRICE_CLOSE,MODE_MAIN,0);
// find the value of the main line on the active chart and period on the last bar. 
// Uses averaging on 3 bars, uses close price.
 
plusDi=iADX(USDCAD,PERIOD_M1,6,PRICE_OPEN,MODE_PLUSDI,1);
// find the value of line +DI on the minute chart USDCAD on the second last bar. 
// Uses averaging on 6 bars, uses open price.
 
minusDi=iADX(AUDUSD,PERIOD_H1,10,PRICE_HIGH,MODE_MINUSDI,5);
// find the value of line -DI on the hour chart AUDUSD on the 6th last bar. 
// Uses averaging on 10 bars, uses maximal price.

平均真實波動範圍指標(ATR)

平均真實波動範圍(ATR)指標用於確定市場波動性。http://ta.mql4.com/indicators/oscillators/average_true_range 函數原型:

double iATR(string symbol,int timeframe,int period,int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • 週期 – 柱的數量,用於得出平均值。
  • shift – 定義應該使用指標的柱。

使用示例:


double atr;
 
atr=iATR(0,0,15,0);
// volatility of the last bar on the active chart and period. 
// Uses 15 bars to get the mean value. 

atr=iATR(EURUSD,PERIOD_M15,5,1);
// volatility of the last but one bar on a 15 minute chart EURUSD. 
// Uses 5 bars to get the mean value.
 
atr=iATR(USDCAD,PERIOD_H1,32,0);
// volatility of the last bar on an hour chart USDCAD. 
// Uses 32 bars to get the mean value.

比爾·威廉姆的動量震盪指標(AO)

比爾·威廉姆動量震盪(AO)指標用於確定市場動力。http://ta.mql4.com/indicators/bills/awesome 函數原型:

double iAO( string symbol, int timeframe, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • shift – 定義應該使用指標的柱。

使用示例:


double ao;
 
ao=iAO(0,0,0);
// moving force of the last bar on the active chart and period 

ao=iAO(EURUSD,PERIOD_M5,0);
// moving force of the last bar on 5-minute chart EURUSD 

ao=iAO(EURAUD,PERIOD_W1,1);
// moving force of the last but one bar on a weekly chart EURAUD

熊市力量

熊市力量指標用於評估“熊市”力量的平衡。http://www.fibo-forex.ru/pages.php?page=1799 函數原型:

double iBearsPower(string symbol,int timeframe,int period,int applied_price,int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double bp;
 
bp=iBearsPower(0,0,5,PRICE_OPEN,0);
// balance of the last bar on the active chart and period. Use 5 bars for averaging and opening prpice. 

bp=iBearsPower("EURUSD",PERIOD_M5,32,PRICE_CLOSE,1);
// balance of the last but one bar on 5-minute chart EURUSD. Use 32 bars for averaging and close price. 

bp=iBearsPower("EURGBP",PERIOD_D1,51,PRICE_MEDIAN,0);
// balance of the last bar on a daily chart EURGBP. Use 51 bars for averaging and average price.

保力加通道技術指標(BB)

保力加通道技術(BB)指標用於確定價格波動正常範圍的上限和下限。http://ta.mql4.com/indicators/trends/bollinger_bands 函數原型:

double iBands( string symbol, int timeframe, int period, int deviation, int bands_shift, int applied_price, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • deviation – 與主線的偏差。
  • bands_shift - 價格偏移量。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • mode – 選擇一條線,將會找到它的值。使用以下預定義的常量:
    • MODE_UPPER - 上面線
    • MODE_LOWER - 下面線
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double bb;
 
bb=iBands
(0,0,20,2,0,PRICE_LOW,MODE_LOWER,0);
// lower limit of the last bar on the active chart and period. 
// Use 20 bars for averaging, and the minimal price.
// Deviation from the main line is 2, shift is not used.
 
bb=iBands("EURUSD",PERIOD_H1,13,2,3,PRICE_HIGH,MODE_UPPER,1);
// upper limit of the last but one bar on an hour chart EURUSD. 
// Use 13 bars for averaging, and the maximal price.
// Deviation from the main line is 2, shift is 3 bars. 

bb=iBands("EURGBP",PERIOD_D1,21,3,4,PRICE_HIGH,MODE_UPPER,0);
// upper limit of the last bar on a daily chart EURGBP. 
// Use 21 bars for averaging, and the maximal price.
// Deviation from the main line is 2, shift is 4 bars.

牛市力量

牛市力量指標用於評估“牛市”力量的平衡。http://www.forexdealer.net/help/bul_hlp.htm 函數原型:

double iBullsPower(string symbol, int timeframe, int period, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double bp;
 
bp=iBullsPower(0,0,10,PRICE_CLOSE,1);
// balance of the last but one bar on the active chart and period. Use 10 bars for averaging
// and close price. 

bp=iBullsPower("EURGBP",PERIOD_M1,21,PRICE_HIGH,1);
// balance of the last bar on a minute chart EURGBP. Use 21 bars for averaging and the maximal price. 

bp=iBullsPower("EURUSD",PERIOD_H1,33,PRICE_MEDIAN,0);
// balance of the last bar on an hour chart EURUSD. Use 33 bars for averaging and the average price.

順勢指標(CCI)

順勢指標(CCI)用於測量價格偏離其平均統計價格的水平。http://ta.mql4.com/indicators/trends/commodity_channel_index 函數原型:

double iCCI( string symbol, int timeframe, int period, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double cci;
   
cci=iCCI(0,0,14,PRICE_TYPICAL,0);
// index of the last bar on the active chart and period.
// Use 14 bars for finding the mean value and
// typical price. 

cci=("EURUSD",PERIOD_M1,21,PRICE_HIGH,1);
// index of the last but one bar on a minute chart EURUSD.
// Use 21 bars for finding the mean value and
// maximal price.
 
cci=iCCI("EURGBP",PERIOD_D1,7,PRICE_CLOSE,0);
// index of the last bar on a daily chart EURGBP.
// Use 7 bars for finding the mean value and
// close price.

DeMarker (DeM)

DeMarker(DeM)指標是根據歷史柱的價格差異預測價格拐點。http://ta.mql4.com/indicators/oscillators/DeMarker 函數原型:

double iDeMarker( string symbol, int timeframe, int period, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • shift – 定義應該使用指標的柱。

使用示例:


double dm;
   
dm=iDeMarker(0,0,13,0);
// DeMarker value of the last bar on the current chart and period.
// Use 13 bars to find the mean value. 

dm=iDeMarker("EURJPY",PERIOD_H4,51,1);
// DeMarker value of the last but one bar on 4-hour chart EURJPY.
// Use 51 bars to find the mean value. 

dm=iDeMarker("USDCAD",PERIOD_M30,21,0);
// DeMarker value of the last bar on 30-minutes chart USDCAD.
// Use 21 bars to find the mean value.

包絡線

包絡線是基於兩條移動平均線確定價格波動的極限值。http://ta.mql4.com/indicators/oscillators/envelopes 函數原型:

double iEnvelopes( string symbol, int timeframe, int ma_period, int ma_method, int ma_shift, int applied_price, double deviation, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • ma_period - 柱的數量,用於獲取主線。
  • ma_method – 定義用於找到平均值的方法。以下預定義的常量用於選擇方法:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • ma_shift – 柱內指標線的偏移。如果偏移爲正,則指標線右移。相反,如果偏移爲負,則線左移。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • deviation – 與主線的偏差,以百分比表示。例如,如果寫入 0.1,則表示 10%,0.25 則表示 25%,以此類推。
  • mode – 選擇一條線,將會找到它的值。使用以下預定義的常量:
    • MODE_UPPER - 上面線
    • MODE_LOWER - 下面線
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double e;
   
e=iEnvelopes(0,0,21,MODE_SMA,0,PRICE_CLOSE,0.05,MODE_LOWER,0);
// lower limit of the last bar on the active chart and period.
// Use 21 bars and close price for finding the value of simple moving 
// average. Shift is not used. Deviation from the main 
// line: 5%.
 
e=iEnvelopes("EURUSD",PERIOD_H1,13,MODE_SMMA,3,PRICE_MEDIAN,0.15,MODE_UPPER,1);
// upper limit of the last but one bar on an hour chart EURUSD.
// Use 13 bars and average price for finding the value of smoothed moving 
// average. Shift: 3 bars. Deviation from the main line: 15%. 

e=iEnvelopes("EURAUD",PERIOD_D1,7,MODE_EMA,2,PRICE_CLOSE,0.20,MODE_LOWER,0);
// lower limit of the last bar on a daily chart EURAUD.
// Use 7 bars and close price for finding the value of exponential 
// moving average. Shift: 2 bars. Deviation from the main 
// line: 20%.

強力指數(FRC)

強力指數(FRC)指標用於測量每次上漲時的“牛市”力量以及每次下跌時的“熊市”力量。http://ta.mql4.com/indicators/oscillators/force_index 函數原型:

double iForce( string symbol, int timeframe, int period, int ma_method, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • ma_period - 柱的數量,用於獲取主線。
  • ma_method – 定義一種用於獲取平均值的方法。選擇一種方法有以下預定義的常量:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double f;
   
f=iForce(0,0,13,MODE_SMA,PRICE_CLOSE,0);
// force index of the last bar on the active chart and period. Period
// of averaging: 13 bars. Method of averaging: simple moving average.
// Use close price.
 
f=iForce("EURGBP",PERIOD_M5,21,MODE_LWMA,PRICE_HIGH,1);
// force index of the last but one bar on 5-minute chart EURGBP. Period
// of averaging: 21 bars. Method of averaging: linearly-weighted moving average.
// Use maximal price. 

f=iForce("EURUSD",PERIOD_M1,32,MODE_SMMA,PRICE_MEDIAN,0);
// force index of the last bar on a minute chart EURUSD. Period
// of averaging: 32 bars. Method of averaging: smoothed moving average.
// Use average price.

分形指標

分形指標是比爾·威廉姆交易系統的五大指標之一,用於檢測價格圖的底部和頂部。分形並不出現在所有柱上。如果分形未出現在柱上,函數返回零。http://ta.mql4.com/indicators/bills/fractal 函數原型:

double iFractals( string symbol, int timeframe, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • mode – 選擇一條線,將會收到它的值。會使用以下預定義的常量:
    • MODE_UPPER - 上分形
    • MODE_LOWER - 下分形
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double f;
 
f=iFractals(0,0,MODE_UPPER,0);
// upper fractal of the last bar on the active chart and
// period.
 
f=iFractals("USDCAD",PERIOD_M5,MODE_LOWER,1);
// lower fractal of the last but one bar on 5-minute chart
// USDCAD. 

f=iFractals("USDJPY",PERIOD_D1,MODE_UPPER,0);
// upper fractal of the last bar on a daily chart USDJPY.

加多擺動指標

加多擺動指標基於鱷魚指標之上構建,用於測量平衡線的收斂或發散程度。http://ta.mql4.com/indicators/bills/gator 函數原型:

double iGator( string symbol, int timeframe, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int ma_method, int applied_price, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • jaw_period - 鱷魚下顎平均週期(藍線)
  • jaw_shift - 藍線相對偏移量
  • teeth_period - 鱷魚牙齒平均週期(紅線)
  • teeth_shift - 紅線相對偏移量
  • lips_period - 鱷魚嘴脣平均週期(綠線)
  • lips_shift - 綠線相對偏移量
  • ma_method – 定義一種用於獲取平均值的方法。選擇一種方法有以下預定義的常量:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • mode – 定義要返回的數據(下顎、牙齒或嘴脣)。對於選擇使用常量之一:
    • MODE_UPPER - 上柱形圖
    • MODE_LOWER - 下柱形圖
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double g;
 
g=iGator(0,0,13,8,8,0,0,0,MODE_SMA,PRICE_CLOSE,MODE_UPPER,0);
// upper histogram of the last bar on the active chart and period. Periods of 
// averaging for jaw, teeth and lips accordingly: 13,8,8. Shift is not used. 
// For averaging use close price and the method of a simple moving average. 

g=iGator("EURGBP",PERIOD_M1,21,13,9,4,3,2,MODE_SMMA,PRICE_OPEN,MODE_LOWER,1);
// lower histogram of the last but one bar on a minute chart EURGBP. Periods of 
// averaging for jaw, teeth and lips accordingly: 21,13,9. Shifts accordingly:
// 4,3 and 2. For averaging use open price and the method of smoothed 
// moving average.
 
g=iGator("USDCAD",PERIOD_D1,51,21,13,8,5,4,MODE_EMA,PRICE_MEDIAN,MODE_UPPER,0);
// upper histogram of the last bar on a daily chart USDCAD. Periods of
// averaging for jaw, teeth and lips accordingly: 51,21,13. Shifts accordingly: 8,5 and 4.
// For averaging use average price and the method of exponential moving average.

一目平衡表指標

一目平衡表指標用於定義趨勢、支撐和阻力位,以及買賣信號。http://ta.mql4.com/indicators/oscillators/ichimoku 函數原型:

double iIchimoku( string symbol, int timeframe, int tenkan_sen, int kijun_sen, int senkou_span_b, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • tenkan_sen - 轉折線平均週期。
  • kijun_sen - 基準線平均週期。
  • senkou_span_b - 先行下線平均週期。
  • mode - 定義要尋找的值。對於選擇使用常量之一:
    • MODE_TENKANSEN - 轉折線
    • MODE_KIJUNSEN - 基準線
    • MODE_SENKOUSPANA - 先行上線
    • MODE_SENKOUSPANB - 先行下線
    • MODE_CHINKOUSPAN - 延遲線
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double i;
 
i=iIchimoku(0,0,13,21,53,MODE_KIJUNSEN,0);
// the value of the line Kijun-sen on the last bar on the current security and period.
// Periods for finding mean values for Tenkan Sen, Kijun Sen and Senkou Span B
// accordingly: 13,21 and 53.
 
i=iIchimoku("EURUSD",PERIOD_M5,21,53,96,MODE_TENKANSEN,1);
// the value of the line Tenkan-sen on the last but one bar on 5-minute chart EURUSD.
// Periods for finding mean values for Tenkan Sen, Kijun Sen and Senkou Span B
// accordingly: 21,53 and 96.

i=iIchimoku("USDCAD",PERIOD_D1,3,5,9,MODE_CHINKOUSPAN,0);
// the value of the line Chinkou Span on the last bar on a daily chart USDCAD.
// Periods for finding mean values for Tenkan Sen, Kijun Sen and Senkou Span B
// accordingly: 3,5 and 9.

市場促進指數(BW MFI)

市場促進指數(BW MFI)指標用於測量一次價格變動的價格。http://ta.mql4.com/indicators/bills/market_facilitation_index 函數原型:

double iBWMFI( string symbol, int timeframe, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • shift – 定義應該使用指標的柱。

使用示例:


double mfi;
 
mfi=iBWMFI(0,0,0);
// index of market facilitation of the last bar on the active chart and period. 

mfi=iBWMFI("EURUSD",PERIOD_H1,1);
// index of market facilitation of the last but one bar on an hour chart EURUSD. 

mfi=iBWMFI("EURGBP",PERIOD_D1,0);
// index of market facilitation of the last bar on a daily chart EURGBP.

動量索引指標

動量索引指標用於測量一段時期內價格的變動量。http://ta.mql4.com/indicators/oscillators/momentum 函數原型:

double iMomentum( string symbol, int timeframe, int period, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 開盤價格
    • PRICE_OPEN - 收盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double m;
 
m=iMomentum(0,0,12,PRICE_CLOSE,1);
// momentum of the last but one bar on the active chart and period. Use 
// 12 bars and close price for finding a mean value. 

m=iMomentum("EURUSD",PERIOD_D1,21,PRICE_OPEN,0);
// momentum of the last bar on a daily chart EURUSD. Use 
// 21 bars and open price for finding a mean value. 

m=iMomentum("USDCAD",PERIOD_H1,7,PRICE_MEDIAN,1);
// momentum of the last but one bar on an hour chart USDCAD. Use 
// 7 bars and average price for finding a mean value.

資金流量指數(MFI)

資金流量指數(MFI)指標用於測量投資強度。http://ta.mql4.com/indicators/volumes/money_flow_index 函數原型:

double iMFI( string symbol, int timeframe, int period, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • shift – 定義應該使用指標的柱。

使用示例:


double mfi;
 
iMFI(0,0,14,1);
// intensity of investments of the last but one bar on the current chart and period.
// Use 14 bars to find the mean value. 

iMFI("EURGBP",PERIOD_H4,32,0);
// intensity of investments of the last bar on 4-hour chart EURGBP.
// Use 32 bars to find the mean value. 

iMFI("EURUSD",PERIOD_W1,9,1);
// intensity of investments of the last but one bar on a weekly chart EURUSD.
// Use 9 bars to find the mean value.

移動平均線(MA)

移動平均線(MA)指標顯示一段時期內的平均價格。http://ta.mql4.com/indicators/trends/moving_average 函數原型:

double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • ma_shift – 柱內線的偏移。如果偏移爲正,則線右移。相反,如果偏移爲負,則線左移。
  • ma_method – 定義一種用於獲取平均值的方法。選擇一種方法有以下預定義的常量:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double ma;
 
ma=iMA(
0,0,13,0,MODE_SMA,PRICE_CLOSE,0);
// moving average of the last bar on the active chart and period.
// Use 13 bars and close price for finding simple moving average.
// Shift is not used. 

ma=iMA("GOLD",PERIOD_M15,21,6,MODE_LWMA,PRICE_LOW,1);
// moving average of the last but one bar on 15-minute chart GOLD.
// Use 21 bars and minimal price for finding linearly-weighted moving average.
// Shift: 6 bars.

ma=iMA("EURCHF",PERIOD_D1,18,4,MODE_SMMA,PRICE_TYPICAL,0);
// moving average of the last bar on a daily chart EURCHF.
// Use 18 bars and typical price for finding smoothed moving average.
// Shift: 4 bars.

指數平滑移動平均線(MACD)

指數平滑移動平均線(MACD)指標用於根據兩條移動平均線的關聯追蹤趨勢。http://ta.mql4.com/indicators/oscillators/macd 函數原型:

double iMACD( string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • fast_ema_period - 柱的數量,用於計算快速移動平均線。
  • slow_ema_period - 柱的數量,用於計算慢速移動平均線。
  • signal_period - 柱的數量,用於計算信號線。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • mode - 定義要尋找的值。要進行選擇,使用以下常量之一:
    • MODE_MAIN - 主線
    • MODE_SIGNAL - 信號線
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double ma;
 
ma=iMACD(0,0,9,21,9,PRICE_CLOSE,MODE_MAIN,0);
// value of the main line for the last bar on the active chart and period.
// Bars, used to find mean values of a fast, slow and signal 
// moving average accordingly: 9,21 and 9. Use close price. 

ma=iMACD("EURUSD",PERIOD_H1,21,52,18,PRICE_HIGH,MODE_SIGNAL,1);
// value of the signal line for the last but one bar on an hour chart EURUSD.
// Bars, used to find mean values of a fast, slow and signal 
// moving average accordingly: 21,52 and 18. Use maximal price. 

ma=iMACD("USDCAD",PERIOD_D1,7,13,7,PRICE_MEDIAN,MODE_MAIN,1);
// value of the main line for the last but one bar on a daily chart USDCAD.
// Bars, used to find mean values of a fast, slow and signal 
// moving average accordingly: 7,13 and 7. Use average price.

移動平均震盪指標(OsMA)

移動平均震盪指標(OsMA)用於測量指數平滑移動平均線指標(MACD)的主線和信號線之間的差異。http://ta.mql4.com/indicators/oscillators/macd_oscillator 函數原型:

double iOsMA( string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • fast_ema_period - 柱的數量,用於計算快速移動平均線。
  • slow_ema_period - 柱的數量,用於計算慢速移動平均線。
  • signal_period - 柱的數量,用於計算信號線。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double osma;
 
osma=iOsMA(0,0,12,26,9,PRICE_CLOSE,0);
// difference of the last bar on the active chart and period. Bars, used 
// to find mean values for the fast, slow and signal 
// moving average accordingly: 12,26 and 9. Use close price. 

osma=iOsMA("EURUSD",PERIOD_M1,7,13,6,PRICE_OPEN,1);
// difference of the last but one bar on a minute chart EURUSD. Bars, used 
// to find mean values for the fast, slow and signal 
// moving average accordingly: 7,13 and 6. Use open price. 

osma=iOsMA("EURAUD",PERIOD_H1,21,48,18,PRICE_TYPICAL,0);
// difference of the last bar on an hour chart EURAUD. Bars, used 
// to find mean values for the fast, slow and signal 
// moving average accordingly: 21,48 and 18. Use typical price.

能量潮指標(OBV)

能量潮指標(OBV)將交易量跟伴隨該交易量的價格變動相關聯。http://ta.mql4.com/indicators/volumes/on_balance_volume 函數原型:

double iOBV( string symbol, int timeframe, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double obv;
 
obv=iOBV(0,0,PRICE_OPEN,0);
// Balance volume of the last bar on the current chart and period. Use open price 

obv=iOBV("GBPCHF",PERIOD_M30,PRICE_CLOSE,1);
// Balance volume of the last but one bar on 30-minutes chart GBPCHF. Use close price. 

obv=iOBV("GBPJPY",PERIOD_H4,PRICE_MEDIAN,0);
// Balance volume of the last bar on 4-hour chart GBPJPY. Use average price.

拋物線狀止損和反轉指標(Parabolic SAR)

拋物線狀止損和反轉指標(Parabolic SAR)用於分析趨勢市場和定義退出點。http://ta.mql4.com/indicators/trends/parabolic_sar 函數原型:

double iSAR( string symbol, int timeframe, double step, double maximum, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • step - 止損水平的增量,通常爲 0.02。
  • maximum - 最大止損水平,通常爲 0.2。
  • shift – 定義應該使用指標的柱。

使用示例:


double sar;
 
sar=iSAR(0,0,0.02,0.2,0);
// indicator value for the last bar on the current chart and period.
// Step of stop level increment: 0.02. Maximal stop level: 0.2. 

sar=iSAR("EURUSD",PERIOD_M1,0.03,0.18,1);
// indicator value for the last but one bar on a minute chart EURUSD.
// Step of stop level increment: 0.03. Maximal stop level: 0.18. 

sar=iSAR("EURCHF",PERIOD_H1,0.01,0.15,0);
// indicator value for the last bar on an hour chart EURCHF.
// Step of stop level increment: 0.01. Maximal stop level: 0.15.

相對強弱指標(RSI)

相對強弱指標(RSI)用於預測價格拐點。http://ta.mql4.com/indicators/oscillators/relative_strength_index 函數原型:

double iRSI( string symbol, int timeframe, int period, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double rsi;
 
rsi=iRSI(0,0,14,PRICE_CLOSE,0);
// indicator value for the last bar on the active chart and period. 
// Use 14 bars and close price to find the mean value. 

rsi=iRSI("USDCAD",PERIOD_M1,9,PRICE_OPEN,1);
// indicator value for the last but one bar on a minute chart USDCAD. 
// Use 9 bars and close price to find the mean value. 

rsi=iRSI("EURAUD",PERIOD_H1,25,PRICE_TYPICAL,0);
// indicator value for the last bar on an hour chart EURAUD. 
// Use 25 bars and typical price to find the mean value.

相對活力指數指標(RVI)

相對活力指數指標(RVI)用於確定買賣信號。建議結合上一個指標使用以評估不確定性。http://ta.mql4.com/indicators/oscillators/relative_vigor_index 函數原型:

double iRVI( string symbol, int timeframe, int period, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • mode - 定義要尋找的值。對於選擇使用常量之一:
    • MODE_MAIN - 主線
    • MODE_SIGNAL - 信號線
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double rvi;
 
rvi=iRVI(0,0,12,MODE_MAIN,1);
// value of the main line of the last but one bar on the active chart and period. 
// Use 12 bars to find the mean value.
 
rvi=iRVI("EURUSD",PERIOD_D1,21,MODE_SIGNAL,0);
// value of the signal line on the last bar on a daily chart EURUSD. 
// Use 21 bars to find the mean value.
 
rvi=iRVI("GBPJPY",PERIOD_H1,19,MODE_MAIN,1);
// value of the main line on the last but one bar on an hour chart GBPJPY. 
// Use 19 bars to find the mean value.

標準離差指標

標準離差指標用於測量市場波動性。http://ta.mql4.com/indicators/trends/standard_deviation 函數原型:

double iStdDev( string symbol, int timeframe, int ma_period, int ma_shift, int ma_method, int applied_price, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • ma_period - 柱的數量,用於獲取指標線。
  • ma_shift – 柱內指標線的偏移。如果偏移爲正,則線右移。相反,如果偏移爲負,則線左移。
  • ma_method – 定義一種用於獲取平均值的方法。選擇一種方法有以下預定義的常量:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • applied_price – 定義要使用的價格(要進行平均的價格)對於選擇使用的價格,有以下預定義的常量:
    • PRICE_CLOSE - 收盤價格
    • PRICE_OPEN - 開盤價格
    • PRICE_HIGH - 最高價格
    • PRICE_LOW - 最低價格
    • PRICE_MEDIAN - 平均價格,(最高價+最低價)/2
    • PRICE_TYPICAL - 典型價格,(最高價+最低價+收盤價)/3
    • PRICE_WEIGHTED - 加權收盤價格,(最高價+最低價+收盤價+收盤價)/4
  • shift – 定義應該使用指標的柱。

使用示例:


double sd;
 
sd=iStdDev(0,0,10,0,MODE_SMA,PRICE_CLOSE,1);
// deviation of the last but one bar on the active chart and period. 
// Use 10 bars and close price to find simple 
// moving average. Shift is not used.
 
sd=iStdDev("EURUSD",PERIOD_D1,21,3,MODE_SMMA,PRICE_MEDIAN,0);
// deviation of the last bar on a daily chart EURUSD. 
// Use 21 bars and average price to find smoothed 
// moving average. Shift: 3 bars.
 
sd=iStdDev("USDCAD",PERIOD_H4,17,2,MODE_EMA,PRICE_OPEN,1);
// deviation of the last but one bar on 4-hour chart USDCAD. 
// Use 17 bars and open price to find exponential
// moving average. Shift: 2 bars.

隨機震盪指標

隨機震盪指標用於確定買賣信號。http://ta.mql4.com/indicators/oscillators/stochastic 函數原型:

double iStochastic( string symbol, int timeframe, int %Kperiod, 
                    int %Dperiod, int slowing, int method, 
                    int price_field, int mode, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • %K period - 柱的數量,用於生成 %K 線。
  • %D period - 柱的數量,用於生成 %D 線。
  • slowing - 滾動值。
  • method - 定義一種用於獲取平均值的方法。選擇一種方法有以下預定義的常量:
    • MODE_SMA - 簡單移動平均線
    • MODE_EMA - 指數移動平均線
    • MODE_SMMA - 平滑移動平均線
    • MODE_LWMA - 線性加權移動平均線
  • price_field – 定義什麼價格應該用於計算。價格選擇有以下預定義的值:
    • 0 - 最低價/最高價
    • 1 - 收盤價/收盤價
  • mode - 定義要尋找的值。要進行選擇,使用以下常量之一:
    • MODE_MAIN - 主線
    • MODE_SIGNAL- 信號線
  • shift – 定義應該使用指標的柱。

使用 mode 參數,定義應返回的內容:

使用示例:


double s;
 
s=iStochastic(0,0,10,6,6,MODE_SMA,0,MODE_MAIN,0);
// value of the main line for the last bar on the current chart and period. 
// Bars used to calculate lines %K, %D and slowing 
// accordingly: 10, 6 and 6. Method of averaging: simple moving average. 
// Use prices: Low/High.
 
s=iStochastic("EURUSD",PERIOD_M1,6,3,3,MODE_SMMA,1,MODE_SIGNAL,1);
// value of the signal line for the last but one bar on a minute chart EURUSD.
// Bars used to calculate lines %K, %D and slowing 
// accordingly: 6, 3 and 3. Method of averaging: smoothed moving average. 
// Use prices: Close/Close.
 
s=iStochastic("EURGBP",PERIOD_M5,9,7,7,MODE_EMA,0,MODE_MAIN,0);
// value of the main line for the last bar on 5-minute chart EURGBP.
// Bars used to calculate lines %K, %D and slowing 
// accordingly: 9, 7 and 7. Method of averaging: exponential moving average.
// Use prices: Low/High.

威廉指標(%R)

威廉指標(%R)用於確定市場是否超買/超賣。http://ta.mql4.com/indicators/oscillators/williams_percent 函數原型:

double iWPR( string symbol, int timeframe, int period, int shift)

參數:

  • 交易品種 – 定義應該用於技術指標值計算的金融證券(貨幣對)。如果你需要當前(活動)的證券(圖表),則使用 NULL(或 0)。
  • 時間範圍 – 定義應該使用指標的時間範圍(時長)。對當前時期使用 0 或以下常量之一(PERIOD_M1、PERIOD_M5、PERIOD_M15、PERIOD_M30、PERIOD_H1、PERIOD_H4、PERIOD_D1、PERIOD_W1、PERIOD_MN1)。
  • period – 柱的數量,用於獲取平均值。
  • shift – 定義應該使用指標的柱。

使用示例:


double wpr;
 
wpr=iWPR(0,0,14,1);
// overbought: the last but one bar on the active chart and period.
// Use 14 bars to get the mean value.
 
wpr=iWPR("USDCHF",PERIOD_D1,9,0);
// overbought: The last bar on a daily chart USDCHF.
// Use 9 bars to get the mean value.
 
wpr=iWPR("GBPJPY",PERIOD_H1,23,1);
// overbought: the last but one bar on an hour chart GBPJPY.
// Use 23 bars to get the mean value.

技術指標函數的正確使用

爲了正確使用這些函數,你必須確切瞭解指標是如何工作的以及如何使用它(交易信號)。當然,它們應該用於你自己的 Expert Advisor 或指標。作爲家庭作業,你應該嘗試編寫一個腳本,可以根據任一指標(自行選擇)信號通知進場點。作爲示例,我們來編寫一個家庭作業示例,將基於隨機震盪指標的交易信號顯示進場點。我們使用以下規則進入市場:如果主線上升高於信號線,則買進。如果主線下跌低於信號線,則賣出。圖片中圈出了進入點。

首先,我們來聲明幾個變量,用於存儲信號值和當前以及之前柱的主線。


double mainLine;
double prevMainLine;
double signalLine;
double prevSignalLine;

現在讓我們找到這幾個變量的值:


mainLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);
prevMainLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
signalLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
prevSignalLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1);

可以看出,我們將自己限於最後和倒數第二個柱。現在來檢查是否有買賣信號:


if(prevMainLine<prevSignalLine && mainLine>signalLine)
   Alert("Signal to buy");
// if the main line was under the signal one and rised over it,
// this is a signal to buy
         
if(prevMainLine>prevSignalLine && mainLine<signalLine)
   Alert("Signal to sell");         
// if the main line was over the signal one and fell bellow it,
// this is a signal to sell

我們使用比較運算符邏輯運算符 &&。嘗試對其適當瞭解。現在我們將其置入循環,檢查上百個最後的柱。


for(int a=0;a<100;a++)
{
   mainLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_MAIN,a);
   prevMainLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_MAIN,a+1);
   signalLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,a);
   prevSignalLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,a+1);
 
   if(prevMainLine<prevSignalLine && mainLine>signalLine)
      Alert("Signal to buy");
         
   if(prevMainLine>prevSignalLine && mainLine<signalLine)
      Alert("Signal to sell");         
}

看到了嗎?我們直接從循環添加了計數器,可以檢驗柱。爲了簡便,我們不用一百,而是聲明一個常量 BARS_TO_ANALYSE,來定義要分析的最後柱的個數。以下是腳本的最終版本:


//+------------------------------------------------------------------+
//|                                        showStochasticSignals.mq4 |
//|                                    Antonuk Oleg Copyright © 2007 |
//|                                                   [email protected] |
//+------------------------------------------------------------------+
#property copyright "Antonuk Oleg Copyright © 2007"
#property link      "[email protected]"
 
#define BARS_TO_ANALYSE 100
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
   double mainLine;
   double prevMainLine;
   double signalLine;
   double prevSignalLine;
      
   for(int a=0;a<BARS_TO_ANALYSE;a++)
   {
      mainLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_MAIN,a);
      prevMainLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_MAIN,a+1);
      signalLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,a);
      prevSignalLine=iStochastic(0,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,a+1);
 
      if(prevMainLine<prevSignalLine && mainLine>signalLine)
         Alert("Signal to buy. Time: ",TimeToStr(Time[a]));
         
      if(prevMainLine>prevSignalLine && mainLine<signalLine)
         Alert("Signal to sell. Time: ",TimeToStr(Time[a]));
   }
   return(0);
}

在腳本中,以下小段代碼一定看起來很陌生(如果是的話,說明你一定是個成功的學生):

TimeToStr(Time[a])

該函數接受自 1970 年 1 月 1 日起的秒數,返回帶有該日期的字符串。預定義數組 Time[] 返回跟應用至所選柱相同的秒數。這是一個理想的配對。作爲子任務,嘗試添加一個長期移動平均線(200-500 的週期),按照以下方法過濾掉不必要的信號:如果價格高於中線,則不賣。如果價格低於中線,則不買。好了,你是否完成了呢?沒有?那麼,再給你提供一些信息。



關於變量聲明的新內容

通常我們這樣聲明變量:


double maxPrice;
double minPrice;
double lastPrices[100];
 
int maxIndex;
int minIndex;
int levels[10];

不要再那樣做了。而是這樣做:


double maxPrice,
       minPrice,
       lastPrices[100];
 
int maxIndex,
    minIndex,
    levels[10];

也就是說,先指示類型,然後逗號分隔變量(數組)名稱。儘管我們避免了不必要的操作,其實沒有區別。初始化也一樣:


int value1=10,
    value2=12,
    matrix[2][2]={1,2,
                  3,4};

返回多個值的函數

是否有這種函數?當然,你可以自己編寫。讓我們看看你的能耐吧。最簡單的函數返回一個值:

int func()
{
   return(100);
}

如果我們需要同時返回多個不同類型的值,該怎麼辦?請看以下:


void SuperFunc(int& valueForReturn1,double& valueForReturn2,string& valueForReturn3)
{
   valueForReturn1=100;
   valueForReturn2=300.0;
   valueForReturn3="it works!!";
}

現在我們來試着調用“amazing”函數:

int value1=0;
double value2=0.0;
string value3="";
 
SuperFunc(value1,value2,value3);
MessageBox("value1="+value1+" value2="+value2+" value3="+value3);

結果如下:

該函數跟簡單的函數有一個普遍的差異:當我們聲明時,在參數後面放置 ampersand 字符(&)。如果對參數如此處理,可以更改它在函數內的值,且在調用後結果保持不變。這種對參數的處理被稱爲按引用傳遞參數。這樣可以返回足夠多的不同類型的變量。嘗試忽略以上代碼中的 & 字符並查看結果:



註釋的新類型

你知道如何對一個命令行註釋:

// it is a one string comment

但有時候爲了將其暫時禁用,註釋一個代碼塊更加有用。上述方法不便於對 20-30 個字符串進行註釋。這裏我們可使用多行註釋:


/*
   it is a multi-line comment.
   Very convenient, try it.
*/

總結

今天你學習了很多新內容。我們已經分析了數學和三角函數,以及使用技術指標運算的函數。通過簡單的例子你看到了如何正確的追蹤交易信號。儘管在腳本中使用它們不太方便,而且它們也並非爲此而生,在後續課程你很快就會看到如何在你自己的指標和 Expert Advisor 中使用它們。那時你將看到它們是多麼有用。


原文鏈接:https://www.mql5.com/zh/articles/1496

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章