//---- indicator line SetIndexStyle(0,DRAW_LINE); //---- //---- name for DataWindow and indicator subwindow label // short_name="RSI("+IntegerToString(RSIPeriod)+")"; short_name="RSI("+RSIPeriod+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name);
return(0); } //+------------------------------------------------------------------+ //| Relative Strength Index | //+------------------------------------------------------------------+ int start() { int i,counted_bars=IndicatorCounted(); double rel,negative,positive,sma,x,y,Pos,Neg; //---- if(Bars<=RSIPeriod) return(0); if(TF!=0) { string name=WindowExpertName(); for(i=0; i<Bars-counted_bars+1; i++) { int barIndex=iBarShift(NULL,TF,Time[i],false); MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex); } return(0); }
//---- indicator line SetIndexStyle(0,DRAW_LINE); //---- //---- name for DataWindow and indicator subwindow label // short_name="RSI("+IntegerToString(RSIPeriod)+")"; short_name="RSI("+RSIPeriod+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name);
return(0); } //+------------------------------------------------------------------+ //| Relative Strength Index | //+------------------------------------------------------------------+ int start() { int i,counted_bars=IndicatorCounted(); double rel,negative,positive,sma,x,y,Pos,Neg; //---- if(Bars<=RSIPeriod) return(0); if(TF!=0) { string name=WindowExpertName(); for(i=0; i<Bars-counted_bars+1; i++) { int barIndex=iBarShift(NULL,TF,Time[i],false); MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex); } return(0); }
我很想用mql4来实现这样的算法。
有两个来自不同经纪公司的MT4终端。其中一个有一个 "独占 "指标,它不能被移到另一个终端(如市场)。
那又怎样!?是否有可能将 "独家 "指标的缓冲区读数,在自己的终端中实现自己的指标?
某种程度上,资源并没有发挥作用。
选项1=在Mikhalych开立账户(对吗?)
选项2=写一个指标,将指标数据保存在一个文件中并保存,然后在另一个终端中用另一个指标读取这个文件,并与之建立行。
请帮助--我正在尝试淡化指标--从RSI转换而来,但我不明白为什么指标值会不同?
//| SVA_02.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(1);
SetIndexBuffer(0,MABuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
// short_name="RSI("+IntegerToString(RSIPeriod)+")";
short_name="RSI("+RSIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double rel,negative,positive,sma,x,y,Pos,Neg;
//----
if(Bars<=RSIPeriod) return(0);
if(TF!=0)
{
string name=WindowExpertName();
for(i=0; i<Bars-counted_bars+1; i++)
{
int barIndex=iBarShift(NULL,TF,Time[i],false);
MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
}
return(0);
}
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=Close[i]-Close[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(Pos*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(Neg*(RSIPeriod-1)+sumn)/RSIPeriod;
}
Pos=positive;
Neg=negative;
i--;
}
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
x=positive;
y=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
и
//| SVA_03.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(1);
SetIndexBuffer(0,MABuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
// short_name="RSI("+IntegerToString(RSIPeriod)+")";
short_name="RSI("+RSIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double rel,negative,positive,sma,x,y,Pos,Neg;
//----
if(Bars<=RSIPeriod) return(0);
if(TF!=0)
{
string name=WindowExpertName();
for(i=0; i<Bars-counted_bars+1; i++)
{
int barIndex=iBarShift(NULL,TF,Time[i],false);
MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
}
return(0);
}
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=Close[i]-Close[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(Pos*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(Neg*(RSIPeriod-1)+sumn)/RSIPeriod;
}
x=positive;
y=negative;
Pos=positive;
Neg=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
请帮助--我正在尝试淡化指标--从RSI转换,但我不明白为什么指标值会不同?
...
и
...
请帮助--我正在尝试淡化指标--从RSI转换而来,但我不明白为什么指标值会不同?
只是完全不清楚你想做什么,你做错了什么,你最后想得到什么。
最初,我试图在计算RSI部分时通过删除理论上不必要的缓冲区来摆脱不必要的缓冲区。
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=Close[i]-Close[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
}
PosBuffer[i]=positive;
NegBuffer[i]=negative;
i--;
}
PosBuffer[i]和NegBuffer[i]实际上是过去的正值和负值,比一个条形图更深的条形图不被使用,但消耗内存, 成为。
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=Close[i]-Close[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(Pos*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(Neg*(RSIPeriod-1)+sumn)/RSIPeriod;
}
Pos=positive;
Neg=negative;
i--;
}
此外,我为我的指标修剪了一部分(提供了有问题的代码部分),在相同的循环中,进一步计算SVA_02
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
x=positive;
y=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
然后我想,既然循环是相同的,我可以直接把计算放在第一个循环中--我得到了SVA_03
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=Close[i]-Close[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(Pos*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(Neg*(RSIPeriod-1)+sumn)/RSIPeriod;
}
x=positive;
y=negative;
Pos=positive;
Neg=negative;
if(x>0)sma=Close[i+1]+x;
else sma=Close[i+1]-y;
MABuffer[i]=sma;
i--;
}
//----
return(0);
}
这里是最后一步,事实证明,MABuffer[i]的 结果在SVA_02和SVA_03中是不同的--我在逻辑上无法理解错误 是什么。
在03年的时候,正负值被计算出来,并立即用于计算平均数。在02年,平均计算是在一个单独的周期,在正和负的什么?有一些东西,但不是为正在计算的酒吧。
是的,这是事实,但实际的区别是什么?循环是相同的--请帮助我理解逻辑错误是什么。
怎么能向你解释什么呢?这里 已经解释过了。这个解释有什么不清楚的地方?做一个傻瓜,让自己出丑是一种生活方式吗?在那之后,你怎么能解释什么呢?用大锤敲击头部?好吧,把你的头盔摘下来。
是的,因为这句话"东西是有的,但不是为了被计算的酒吧。"听起来很奇怪,因为这个周期有一个来自上一个周期的正负值。
从最后一个周期的一些最后的酒吧,一些东西留在里面,你把它应用于每个酒吧。在正确的变体中,没有任何东西被留在变量中,而是对每个条形进行计算,并立即用于计算平均值。
我正在努力弄清它的意义。所以在你看来,正确的选项是SVA_03,对吗?