# 对两种不同货币K线的比较,用简单的加减乘除来计算(获得金油比,交叉盘价格,期差数据等) -MT5指标 - MetaTrader 5脚本

718

2020.04.01 17:00

2020.04.27 04:49

```enum method
{
subtract,  // "-"
multiply,  // "*"
divide,    // "/"
logdivide,  // "log(/)"
};

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double apply(double x,double y,method f)
{
double ret = EMPTY_VALUE;
switch(f)
{
case 1:
ret = x + y;
break;
case 2:
ret = x - y;
break;
case 3:
ret = x * y;
break;
case 4:
if(y != 0)
ret = x / y;
break;
case 5:
if(x > 0 && y > 0)
ret = log((double)x / (double)y);
break;
}
return ret;
}```

```   StringTrimRight(iname);
StringTrimLeft(iname);
StringToUpper(iname);
bool is_custom;
if(!SymbolExist(iname,is_custom))
{
return(INIT_FAILED);
}
else
if(is_custom)

CopyRates(iname,PERIOD_CURRENT,0,(int)SeriesInfoInteger(iname,PERIOD_CURRENT,SERIES_BARS_COUNT),rates);
ChartSetInteger(0,CHART_FOREGROUND,ChartWindowFind(),false);
ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,ChartWindowFind(),true);

string pstr = EnumToString(_Period);
string mstr = EnumToString(InpMethod);
if(!StringToUpper(mstr))
mstr = method_tostr(InpMethod);

myname = iname + method_tostr(InpMethod) + _Symbol;
if(InpMethod > 2)
{
string str[4];
str[0] = StringSubstr(iname,0,3);
str[1] = StringSubstr(iname,3,-1);
str[2] = StringSubstr(_Symbol,0,3);
str[3] = StringSubstr(_Symbol,3,-1);
//ArrayPrint(str);
if(InpMethod == multiply)
{
if(str[1] == str[2])
myname = str[0] + str[3];
if(str[0] == str[3])
myname = str[2] + str[1];
}
if(InpMethod == divide)
{
if(str[1] == str[3])
myname = str[0] + str[2];
if(str[0] == str[2])
myname = str[3] + str[1];
}
}
string comment = myname + "," + StringSubstr(pstr,StringFind(pstr,"_") + 1);```

```   int to_copy;
if(prev_calculated > rates_total || prev_calculated <= 0)
to_copy = rates_total;
else
{
to_copy = rates_total - prev_calculated;
to_copy++;
}
int bars = iBars(iname,PERIOD_CURRENT);
if(limit < to_copy)
to_copy = limit;
if(bars < to_copy) //(int)MathMin(bars,MathMax(showbars,to_copy)
to_copy = bars;
if(1 > to_copy)
to_copy = 1;

int copied = CopyRates(iname,PERIOD_CURRENT,0,to_copy,rates);
if(copied != to_copy)
{
copied = CopyRates(iname,PERIOD_CURRENT,0,showbars,rates);
if(prev_calculated < 1)
printf("For the symbol %s, managed to receive only %d bars of %d requested ones",iname,copied,to_copy);
if(copied < 1)
return 0;
}```

``` int pos = 0;
for(int i = 0; i < copied; i++)
{
while(pos < copied && pos <= rates_total - prev_calculated &&  !_StopFlag)
{
if(rates[i].time > time[pos])
break;
KBuffer1[pos] = apply(rates[i].open,open[pos],InpMethod);
KBuffer2[pos] = apply(rates[i].high,high[pos],InpMethod);
KBuffer3[pos] = apply(rates[i].low,low[pos],InpMethod);
KBuffer4[pos] = apply(rates[i].close,close[pos],InpMethod);
KColors[pos] = (KBuffer1[pos] > KBuffer4[pos]) ? 1 : 0;
pos ++;
}
}```

1.除法和减法是由输入的目标货币在前，当前图表的货币在后，如果反了，你调换一下输入和图表就行。

2.由于有时目标货币在本地没有足够的数据，需要等待一段时间下载，如果没有显示的话你可以切换下周期试试。

针对等量等间隔网格刷单最大风险和间隔的计算

这个脚本是计算等价等量加仓步骤的，比如在当前原油价格低迷情况下，又在反复震荡，投资者又想抄底，可以通过这个脚本来计算需要间隔多少来实现逐步等量加仓。

MT5版本三线RSI指标

MT5版本三线RSI指标，根据通达信公式改编。

在外汇中显示不同周期级别的加权平均价与结算价-MT5指标

于主图显示，类似于期货日内均线，可以选择更多的结算周期

对账户资金的实时记录并显示K线图

在做EA账户风控时，有时候需要知道账户各个时间段的资金数据，本EA可以基于每个净值变动来记录，并画出图表K线或保存至Excel。