# MQL4 作为交易者的工具, 还是高级技术分析

21 一月 2016, 10:56
0
1 672

### 进行统计

```bool isBlack(int shift)
{
if(Open[shift] > Close[shift])
return (true);
return (false);
}
//+------------------------------------------------------------------+
bool isWhite(int shift)
{
if(Open[shift] < Close[shift])
return (true);
return (false);
}
//+------------------------------------------------------------------+
```

```例 1
//计算黑色和白色烛形
double BlackCandlesCount = 0;
double WhiteCandlesCount = 0;
double BProbability = 0;

for(int i = 0; i < Bars - 1; i++)
{
if(isBlack(i) == true)
BlackCandlesCount++;

if(isWhite(i) == true)
WhiteCandlesCount++;
}

BProbability = BlackCandlesCount / Bars;
```

```//例 2
//计算顺序序列
//BW 的意思是黑色烛形后面是白色
double BW = 0;
double WB = 0;
double BB = 0;
double WW = 0;

for(i = Bars; i > 0; i--)
{
if(isBlack(i) && isWhite(i-1))
BW++;
if(isWhite(i) && isBlack(i-1))
WB++;
if(isBlack(i) && isBlack(i-1))
BB++;
if(isWhite(i) && isWhite(i-1))
WW++;
}
```

- 白色后面是黑色 - 23.64 %
- 黑色后面是白色 - 23.67 %
- 白色后面是白色 - 21.14 %
- 黑色后面是黑色 - 20.85 %

```//例 3.1
//根据RSI构造柱形图
//RSI 最小/最大 - 0/100

double RSIHistogramBlack[100];
double RSIHistogramWhite[100];

for(i = Bars; i > 0; i--)
{
int rsi_val = iRSI(NULL,0,12,PRICE_CLOSE,i);
if(isWhite(i))
RSIHistogramWhite[rsi_val]++;
if(isBlack(i))
RSIHistogramBlack[rsi_val]++;
}
for(i = 0; i < 100; i++)
{
ExtMapBuffer1[i] = RSIHistogramBlack[i];
ExtMapBuffer2[i] = -RSIHistogramWhite[i];
}

//例 3.2
//根据 %R 构造柱形图
//%R min/max - 0/-100

double WPRHistogramBlack[100];
double WPRHistogramWhite[100];

for(i = Bars; i > 0; i--)
{
int wpr_val = iWPR(NULL,0,12,i);
int idx = MathAbs(wpr_val);
if (isWhite(i))
WPRHistogramWhite[idx]++;
if (isBlack(i))
WPRHistogramBlack[idx]++;
}
```

```int TestOrder(int shift, int barscount, int spread, int tp, int sl, int operation)
{
double open_price = Close[shift];

if (operation == OP_BUY)
open_price  = open_price + (Point * spread);

if (operation == OP_SELL)
open_price  = open_price - (Point * spread);

for (int i = 0; i<barscount; i++)
{
if (operation == OP_BUY)
{
//止损
if (Low[shift-i] <= open_price - (Point * sl) )
return (MODE_STOPLOSS);
//获利
if (High[shift-i] >= open_price + (Point * tp) )
return (MODE_TAKEPROFIT);
}

if (operation == OP_SELL)
{
//止损
if (High[shift-i] >= open_price + (Point * sl) )
return (MODE_STOPLOSS);
//获利
if (Low[shift-i] <= open_price - (Point * tp) )
return (MODE_TAKEPROFIT);
}

}
return (MODE_EXPIRATION);
}
```

### 结论

instrument.mq4 (5.02 KB)