编码帮助 - 页 321 1...314315316317318319320321322323324325326327328...786 新评论 Jan Fouquaert 2014.08.02 20:10 #3201 这就是我试图将MA直接应用于SSA的做法,就像我图片中的例子。 当然,我是一个完全不懂编码的人...... 所以,如果有人能告诉我,我应该怎么改,我将非常感激。 我喜欢解决问题,即使我在这方面是个菜鸟,但如果一个人不尝试解决他的问题,他将永远是个菜鸟...... //+------------------------------------------------------------------+ //| FullSSA.mq4 ! //| Copyright © 2007,klot | | //|klot@mail.ru| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, klot" #property link "klot@mail.ru" #import "libSSA.dll" void fastSingular(double& a[],int n,int lag ,int s,double&b[]); #import #属性 indicator_separate_window #属性 indicator_buffers 2 #属性 indicator_color1 White #属性 indicator_color2 深粉色 #属性 indicator_width1 3 #属性 indicator_level1 0.0 #属性 indicator_levelstyle STYLE_DASH #perty indicator_levelcolor Magenta #perty indicator_levelcolor Magenta 外部字符串 note_TimeFrames ="M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF" 。 外部字符串 TimeFrame = "当前时间框架"。 外部int Lag = 10; extern int NumComps = 2; 外部int PeriodNorm = 10; extern int N = 1000; 外部int SSAMa_Mode = 3; 外置int MaPeriod = 5; 外置 int Ma_Mode = 3; 外置 bool Interpolate = true。 double SSA[]; double ssaWork[]; double SSAma[]; double arryTimeSeries[]; string indicatorFileName; bool returnBars; bool calculateValue; int timeFrame; int init() { SetIndexBuffer(0,SSA); SetIndexBuffer(1,SSAma);SetIndexStyle(0,DRAW_LINE); SetIndexDrawBegin(0,Bars-N); indicatorFileName = WindowExpertName(); calculateValue = (TimeFrame=="calculateValue"); if(calculateValue) return(0); returnBars = (TimeFrame=="returnBars"); if(returnBars) return(0); timeFrame = stringToTimeFrame(TimeFrame); IndicatorShortName(timeFrameToString(timeFrame)+ " FullSSA normalize correct")。 return(0); } int deinit(){return(0);} int start() { double dev,ma; int nmax, nmin; int size = N; 如果(size>Bars) size = Bars; 如果(ArraySize(arryTimeSeries) != size) { ArrayResize(arryTimeSeries,size)。 ArrayResize(ssaWork,size)。 } int limit, i; int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); 如果(counted_bars>0) counted_bars--。 limit=MathMin(Bars-counted_bars,Bars-1)。 如果(returnBars) { SSA[0] = limit+1; return(0); } 如果(calculateValue || timeFrame==Period()) { for( i=size-1; i>=0; i--) { ma=iMA(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。 dev=3*iStdDev(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。 如果(dev==0)dev=0.1。 arryTimeSeries=(Close-ma)/dev;//iDeMarker(NULL,0,PeriodNorm,i); ObjectDelete("Sell "+Time); ObjectDelete("Buy "+Time); } fastSingular(arryTimeSeries,size,Lag,NumComps,ssaWork)。 ArrayCopy(SSA,ssaWork); nmax=ArrayMaximum(SSA,3,1); nmin=ArrayMinimum(SSA,3,1)。 如果(nmax==2) { ObjectCreate("Sell "+Time[0],OBJ_ARROW,0,Time[0],Open[0]) 。 ObjectSet("Sell "+Time[0],OBJPROP_ARROWCODE,226); } 如果(nmin==2) { ObjectCreate("Buy "+Time[0],OBJ_ARROW,0,Time[0],Open[0]); ObjectSet("Buy "+Time[0],OBJPROP_ARROWCODE,225); } //---- return(0); } limit =MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,", "returnBars",0,0)*timeFrame/Period())。 for(i=limit; i>=0; i--) for (i=limit; i>=0; i--) SSAma = iMAOnArray(SSA,Bars,MaPeriod,0,Ma_Mode,i) 。 { int y = iBarShift(NULL,timeFrame,Time); SSA =iCustom(NULL,timeFrame,indicatorFileName,"", "calculateValue",Lag,NumComps,PeriodNorm,N,0,y) 。 如果(timeFrame <= Period() ||y==iBarShift(NULL,timeFrame,Time))继续。 如果(!Interpolate)继续。 datetime time = iTime(NULL,timeFrame,y); for(int n = 1; i+n =time; n++) 继续。 double factor = 1.0 / n; for(int x = 1; x < n; x++) { SSA= x*因子*SSA + (1.0-x*因子)*SSA。 } } 返回(0)。 } //+------------------------------------------------------------------+ string sTfTable[] ={"M1","M5","M15","M30","H1","H4","D1","W1","MN"}; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; // // // // // int stringToTimeFrame(string tfs) { tfs = StringUpperCase(tfs); for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tfs==sTfTable || tfs==""+iTfTable)return(MathMax(iTfTable,Period())。 return(Period())。 } string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable) return(sTfTable); return("")。 } // // // // // string StringUpperCase(string str) { string s = str; for (int length=StringLen(str)-1; length>=0; length--) { int tchar = StringGetChar(s, length); if((tsar > 96 && tchar 223 && tchar < 256)) s = StringSetChar(s, length, tchar - 32); 否则如果(tchar > -33 && tchar < 0) s = StringSetChar(s, length, tchar + 224); } return(s); } Coding help 多时间框架指标 精英指标 :) [删除] 2014.08.02 20:50 #3202 mladen: 对于斜率变化,请尝试这样做:[PHP]double current = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,0);double previous1 = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,1); double previous2 = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,2); if (current>previous1 && previous1 谢谢你,Mladen!,现在我明白了,忘了在条件中加入Extmapbuffer,数字2。 我已经有了订单的执行条件,而不是斜率变化的执行条件,那么 "在上升趋势时 "买入或 "在下降趋势时 "卖出的条件会是什么呢? 再次感谢您 丹尼尔 [删除] 2014.08.03 04:47 #3203 亲爱的Mladen, 我需要的条件是 "在趋势中",而不是在斜率的确切变化中,所以我这样写,但在下降趋势中出现了问题,这个条件正确吗?对于上升趋势,似乎效果不错......但对于下降趋势,我也有问题......希望你能帮助我,谢谢。 if (current>previous1) { // 上升趋势 } 如果(current<previous1) { // 下降趋势 这不工作,完全没有触发任何卖出订单...... } Mladen Rakic 2014.08.03 07:22 #3204 Wulong10: 这是我在尝试直接向SSA申请MA时的做法,就像我图片中的例子。当然,我是一个完全不懂编码的人......。 所以,如果有谁能告诉我,我必须改变什么,我将非常感激。 我喜欢解决问题,即使我在这方面是个新手,但如果一个人不尝试解决他的问题,他将永远是个新手...... //+------------------------------------------------------------------+ //| FullSSA.mq4 ! //| Copyright © 2007,klot | | //|klot@mail.ru| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, klot" #property link "klot@mail.ru" #import "libSSA.dll" void fastSingular(double& a[],int n,int lag ,int s,double&b[]); #import #属性 indicator_separate_window #属性 indicator_buffers 2 #属性 indicator_color1 White #属性 indicator_color2 深粉色 #属性 indicator_width1 3 #属性 indicator_level1 0.0 #属性 indicator_levelstyle STYLE_DASH #perty indicator_levelcolor Magenta #perty indicator_levelcolor Magenta 外部字符串 note_TimeFrames ="M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF" 。 外部字符串 TimeFrame = "当前时间框架"。 外部int Lag = 10; extern int NumComps = 2; 外部int PeriodNorm = 10; extern int N = 1000; 外部int SSAMa_Mode = 3; 外置int MaPeriod = 5; 外置 int Ma_Mode = 3; 外置 bool Interpolate = true。 double SSA[]; double ssaWork[]; double SSAma[]; double arryTimeSeries[]; string indicatorFileName; bool returnBars; bool calculateValue; int timeFrame; int init() { SetIndexBuffer(0,SSA); SetIndexBuffer(1,SSAma);SetIndexStyle(0,DRAW_LINE); SetIndexDrawBegin(0,Bars-N); indicatorFileName = WindowExpertName(); calculateValue = (TimeFrame=="calculateValue"); if(calculateValue) return(0); returnBars = (TimeFrame=="returnBars"); if(returnBars) return(0); timeFrame = stringToTimeFrame(TimeFrame); IndicatorShortName(timeFrameToString(timeFrame)+ " FullSSA normalize correct")。 return(0); } int deinit(){return(0);} int start() { double dev,ma; int nmax, nmin; int size = N; 如果(size>Bars) size = Bars; 如果(ArraySize(arryTimeSeries) != size) { ArrayResize(arryTimeSeries,size)。 ArrayResize(ssaWork,size)。 } int limit, i; int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); 如果(counted_bars>0) counted_bars--。 limit=MathMin(Bars-counted_bars,Bars-1)。 如果(returnBars) { SSA[0] = limit+1; return(0); } 如果(calculateValue || timeFrame==Period()) { for( i=size-1; i>=0; i--) { ma=iMA(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。 dev=3*iStdDev(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。 如果(dev==0)dev=0.1。 arryTimeSeries=(Close-ma)/dev;//iDeMarker(NULL,0,PeriodNorm,i); ObjectDelete("Sell "+Time); ObjectDelete("Buy "+Time); } fastSingular(arryTimeSeries,size,Lag,NumComps,ssaWork)。 ArrayCopy(SSA,ssaWork); nmax=ArrayMaximum(SSA,3,1); nmin=ArrayMinimum(SSA,3,1)。 如果(nmax==2) { ObjectCreate("Sell "+Time[0],OBJ_ARROW,0,Time[0],Open[0]); ObjectSet("Sell "+Time[0],OBJPROP_ARROWCODE,226); } 如果(nmin==2) { ObjectCreate("Buy "+Time[0],OBJ_ARROW,0,Time[0],Open[0]); ObjectSet("Buy "+Time[0],OBJPROP_ARROWCODE,225); } //---- return(0); } limit =MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,", "returnBars",0,0)*timeFrame/Period())。 for(i=limit; i>=0; i--) for (i=limit; i>=0; i--) SSAma = iMAOnArray(SSA,Bars,MaPeriod,0,Ma_Mode,i) 。 { int y = iBarShift(NULL,timeFrame,Time); SSA =iCustom(NULL,timeFrame,indicatorFileName,"", "calculateValue",Lag,NumComps,PeriodNorm,N,0,y) 。 如果(timeFrame <= Period() ||y==iBarShift(NULL,timeFrame,Time))继续。 如果(!Interpolate)继续。 datetime time = iTime(NULL,timeFrame,y); for(int n = 1; i+n =time; n++) 继续。 double factor = 1.0 / n; for(int x = 1; x < n; x++) { SSA= x*因子*SSA + (1.0-x*因子)*SSA。 } } 返回(0)。 } //+------------------------------------------------------------------+ string sTfTable[] ={"M1","M5","M15","M30","H1","H4","D1","W1","MN"}; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; // // // // // int stringToTimeFrame(string tfs) { tfs = StringUpperCase(tfs); for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tfs==sTfTable || tfs==""+iTfTable)return(MathMax(iTfTable,Period())。 return(Period())。 } string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable) return(sTfTable); return("")。 } // // // // // string StringUpperCase(string str) { string s = str; for (int length=StringLen(str)-1; length>=0; length--) { int tchar = StringGetChar(s, length); if((tsar > 96 && tchar 223 && tchar < 256)) s = StringSetChar(s, length, tchar - 32); 否则如果(tchar > -33 && tchar < 0) s = StringSetChar(s, length, tchar + 224); } return(s)。 } Wulong10 我没有看到图片 你能附上吗? Jan Fouquaert 2014.08.03 07:54 #3205 我已经贴出了图片,但在此再次贴出。 所以,当我从MT4中提取一个MA并将其应用于SSA(应用于第一个独立数据),当我打开MT4时,MA看起来没有问题,但是当它实时运行时,它不再跟随SSA了。 这只发生在M1上,在M5上运行没有问题。 图片应该可以直观地说明问题。 谢谢。 附加的文件: ssa.png 72 kb Mladen Rakic 2014.08.03 08:48 #3206 Wulong10: 我已经贴出了图片,但在这里再次贴出。因此,当我从MT4中提取一个MA,并将其应用于SSA(应用于第一个ind.数据),当我打开MT4时,MA看起来没有问题,但当它实时运行时,它不再跟随SSA了。 这只发生在M1上,在M5上运行没有问题。 这张图应该可以直观地说明问题。 谢谢。 不要忘了,SSA会重新计算。如果你不计算所有重新计算的SSA条的MA,那么它将停止跟随SSA。 Jan Fouquaert 2014.08.03 09:56 #3207 好的,现在我明白了,为什么它在M5上有效,这是因为我在那里把MA的周期设置为1,而在M1上我把它设置为2 ....,这应该可以解决这个问题。我已经在我的模拟交易中进行了测试,它并不完美,但要好得多! 在周期1中,MA应该跟随SSA。 但是我怎样才能在SSA的代码中直接加入MA?而且它还应该重新计算所有的SSA条数....,这不可能吗? Mladen Rakic 2014.08.03 11:04 #3208 Wulong10: 好的,现在我明白了,为什么在M5上有效,这是因为我在那里把MA的周期设置为1,而在M1上我把它设置为2....,这应该能解决问题。我已经在我的模拟交易中进行了测试,它并不完美,但要好得多!对于第1期,MA应该遵循SSA。 但是我怎样才能在SSA的代码中直接加入MA?而且它还应该重新计算所有的SSA条数....,还是不可能? Wulong10 你能把你的mq4文件也贴出来吗(把文本复制到mql几乎总是会引起一些问题)? Mladen Rakic 2014.08.03 12:35 #3209 不要在意最后的请求 这里有一个添加了移动平均线的版本:SSA__MA.mq4 附加的文件: ssa__ma.mq4 5 kb ssa__ma.gif 75 kb Jan Fouquaert 2014.08.03 15:16 #3210 好的,谢谢你,Mladen,你是最棒的!我现在没有时间测试了,今天晚上就可以了。 我现在没有时间测试,今天晚上是脚,我会让你知道结果的...当时间成熟时。 现在我也能看到我应该怎么做了,所以我在研究后会少了0.5%的愚蠢。 1...314315316317318319320321322323324325326327328...786 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
这就是我试图将MA直接应用于SSA的做法,就像我图片中的例子。
当然,我是一个完全不懂编码的人......
所以,如果有人能告诉我,我应该怎么改,我将非常感激。
我喜欢解决问题,即使我在这方面是个菜鸟,但如果一个人不尝试解决他的问题,他将永远是个菜鸟......
//+------------------------------------------------------------------+
//| FullSSA.mq4 !
//| Copyright © 2007,klot | |
//|klot@mail.ru| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, klot"
#property link "klot@mail.ru"
#import "libSSA.dll"
void fastSingular(double& a[],int n,int lag ,int s,double&b[]);
#import
#属性 indicator_separate_window
#属性 indicator_buffers 2
#属性 indicator_color1 White
#属性 indicator_color2 深粉色
#属性 indicator_width1 3
#属性 indicator_level1 0.0
#属性 indicator_levelstyle STYLE_DASH
#perty indicator_levelcolor Magenta #perty indicator_levelcolor Magenta
外部字符串 note_TimeFrames ="M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF" 。
外部字符串 TimeFrame = "当前时间框架"。
外部int Lag = 10;
extern int NumComps = 2;
外部int PeriodNorm = 10;
extern int N = 1000;
外部int SSAMa_Mode = 3;
外置int MaPeriod = 5;
外置 int Ma_Mode = 3;
外置 bool Interpolate = true。
double SSA[];
double ssaWork[];
double SSAma[];
double arryTimeSeries[];
string indicatorFileName;
bool returnBars;
bool calculateValue;
int timeFrame;
int init()
{
SetIndexBuffer(0,SSA); SetIndexBuffer(1,SSAma);SetIndexStyle(0,DRAW_LINE); SetIndexDrawBegin(0,Bars-N);
indicatorFileName = WindowExpertName();
calculateValue = (TimeFrame=="calculateValue"); if(calculateValue) return(0);
returnBars = (TimeFrame=="returnBars"); if(returnBars) return(0);
timeFrame = stringToTimeFrame(TimeFrame);
IndicatorShortName(timeFrameToString(timeFrame)+ " FullSSA normalize correct")。
return(0);
}
int deinit(){return(0);}
int start()
{
double dev,ma;
int nmax, nmin;
int size = N;
如果(size>Bars) size = Bars;
如果(ArraySize(arryTimeSeries) != size)
{
ArrayResize(arryTimeSeries,size)。
ArrayResize(ssaWork,size)。
}
int limit, i;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
如果(counted_bars>0) counted_bars--。
limit=MathMin(Bars-counted_bars,Bars-1)。
如果(returnBars) { SSA[0] = limit+1; return(0); }
如果(calculateValue || timeFrame==Period())
{
for( i=size-1; i>=0; i--)
{
ma=iMA(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。
dev=3*iStdDev(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。
如果(dev==0)dev=0.1。
arryTimeSeries=(Close-ma)/dev;//iDeMarker(NULL,0,PeriodNorm,i);
ObjectDelete("Sell "+Time);
ObjectDelete("Buy "+Time);
}
fastSingular(arryTimeSeries,size,Lag,NumComps,ssaWork)。
ArrayCopy(SSA,ssaWork);
nmax=ArrayMaximum(SSA,3,1);
nmin=ArrayMinimum(SSA,3,1)。
如果(nmax==2) {
ObjectCreate("Sell "+Time[0],OBJ_ARROW,0,Time[0],Open[0]) 。
ObjectSet("Sell "+Time[0],OBJPROP_ARROWCODE,226);
}
如果(nmin==2) {
ObjectCreate("Buy "+Time[0],OBJ_ARROW,0,Time[0],Open[0]);
ObjectSet("Buy "+Time[0],OBJPROP_ARROWCODE,225);
}
//----
return(0);
}
limit =MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,", "returnBars",0,0)*timeFrame/Period())。
for(i=limit; i>=0; i--)
for (i=limit; i>=0; i--) SSAma = iMAOnArray(SSA,Bars,MaPeriod,0,Ma_Mode,i) 。
{
int y = iBarShift(NULL,timeFrame,Time);
SSA =iCustom(NULL,timeFrame,indicatorFileName,"", "calculateValue",Lag,NumComps,PeriodNorm,N,0,y) 。
如果(timeFrame <= Period() ||y==iBarShift(NULL,timeFrame,Time))继续。
如果(!Interpolate)继续。
datetime time = iTime(NULL,timeFrame,y);
for(int n = 1; i+n =time; n++) 继续。
double factor = 1.0 / n;
for(int x = 1; x < n; x++)
{
SSA= x*因子*SSA + (1.0-x*因子)*SSA。
}
}
返回(0)。
}
//+------------------------------------------------------------------+
string sTfTable[] ={"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
//
//
//
//
//
int stringToTimeFrame(string tfs)
{
tfs = StringUpperCase(tfs);
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tfs==sTfTable || tfs==""+iTfTable)return(MathMax(iTfTable,Period())。
return(Period())。
}
string timeFrameToString(int tf)
{
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tf==iTfTable) return(sTfTable);
return("")。
}
//
//
//
//
//
string StringUpperCase(string str)
{
string s = str;
for (int length=StringLen(str)-1; length>=0; length--)
{
int tchar = StringGetChar(s, length);
if((tsar > 96 && tchar 223 && tchar < 256))
s = StringSetChar(s, length, tchar - 32);
否则如果(tchar > -33 && tchar < 0)
s = StringSetChar(s, length, tchar + 224);
}
return(s);
}
对于斜率变化,请尝试这样做:[PHP]double current = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,0);double previous1 = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,1); double previous2 = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,2); if (current>previous1 && previous1
谢谢你,Mladen!,现在我明白了,忘了在条件中加入Extmapbuffer,数字2。
我已经有了订单的执行条件,而不是斜率变化的执行条件,那么 "在上升趋势时 "买入或 "在下降趋势时 "卖出的条件会是什么呢?
再次感谢您
丹尼尔
亲爱的Mladen,
我需要的条件是 "在趋势中",而不是在斜率的确切变化中,所以我这样写,但在下降趋势中出现了问题,这个条件正确吗?对于上升趋势,似乎效果不错......但对于下降趋势,我也有问题......希望你能帮助我,谢谢。
if (current>previous1)
{
// 上升趋势
}
如果(current<previous1)
{
// 下降趋势 这不工作,完全没有触发任何卖出订单......
}
这是我在尝试直接向SSA申请MA时的做法,就像我图片中的例子。
当然,我是一个完全不懂编码的人......。
所以,如果有谁能告诉我,我必须改变什么,我将非常感激。
我喜欢解决问题,即使我在这方面是个新手,但如果一个人不尝试解决他的问题,他将永远是个新手......
//+------------------------------------------------------------------+
//| FullSSA.mq4 !
//| Copyright © 2007,klot | |
//|klot@mail.ru| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, klot"
#property link "klot@mail.ru"
#import "libSSA.dll"
void fastSingular(double& a[],int n,int lag ,int s,double&b[]);
#import
#属性 indicator_separate_window
#属性 indicator_buffers 2
#属性 indicator_color1 White
#属性 indicator_color2 深粉色
#属性 indicator_width1 3
#属性 indicator_level1 0.0
#属性 indicator_levelstyle STYLE_DASH
#perty indicator_levelcolor Magenta #perty indicator_levelcolor Magenta
外部字符串 note_TimeFrames ="M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF" 。
外部字符串 TimeFrame = "当前时间框架"。
外部int Lag = 10;
extern int NumComps = 2;
外部int PeriodNorm = 10;
extern int N = 1000;
外部int SSAMa_Mode = 3;
外置int MaPeriod = 5;
外置 int Ma_Mode = 3;
外置 bool Interpolate = true。
double SSA[];
double ssaWork[];
double SSAma[];
double arryTimeSeries[];
string indicatorFileName;
bool returnBars;
bool calculateValue;
int timeFrame;
int init()
{
SetIndexBuffer(0,SSA); SetIndexBuffer(1,SSAma);SetIndexStyle(0,DRAW_LINE); SetIndexDrawBegin(0,Bars-N);
indicatorFileName = WindowExpertName();
calculateValue = (TimeFrame=="calculateValue"); if(calculateValue) return(0);
returnBars = (TimeFrame=="returnBars"); if(returnBars) return(0);
timeFrame = stringToTimeFrame(TimeFrame);
IndicatorShortName(timeFrameToString(timeFrame)+ " FullSSA normalize correct")。
return(0);
}
int deinit(){return(0);}
int start()
{
double dev,ma;
int nmax, nmin;
int size = N;
如果(size>Bars) size = Bars;
如果(ArraySize(arryTimeSeries) != size)
{
ArrayResize(arryTimeSeries,size)。
ArrayResize(ssaWork,size)。
}
int limit, i;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
如果(counted_bars>0) counted_bars--。
limit=MathMin(Bars-counted_bars,Bars-1)。
如果(returnBars) { SSA[0] = limit+1; return(0); }
如果(calculateValue || timeFrame==Period())
{
for( i=size-1; i>=0; i--)
{
ma=iMA(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。
dev=3*iStdDev(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i)。
如果(dev==0)dev=0.1。
arryTimeSeries=(Close-ma)/dev;//iDeMarker(NULL,0,PeriodNorm,i);
ObjectDelete("Sell "+Time);
ObjectDelete("Buy "+Time);
}
fastSingular(arryTimeSeries,size,Lag,NumComps,ssaWork)。
ArrayCopy(SSA,ssaWork);
nmax=ArrayMaximum(SSA,3,1);
nmin=ArrayMinimum(SSA,3,1)。
如果(nmax==2) {
ObjectCreate("Sell "+Time[0],OBJ_ARROW,0,Time[0],Open[0]);
ObjectSet("Sell "+Time[0],OBJPROP_ARROWCODE,226);
}
如果(nmin==2) {
ObjectCreate("Buy "+Time[0],OBJ_ARROW,0,Time[0],Open[0]);
ObjectSet("Buy "+Time[0],OBJPROP_ARROWCODE,225);
}
//----
return(0);
}
limit =MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,", "returnBars",0,0)*timeFrame/Period())。
for(i=limit; i>=0; i--)
for (i=limit; i>=0; i--) SSAma = iMAOnArray(SSA,Bars,MaPeriod,0,Ma_Mode,i) 。
{
int y = iBarShift(NULL,timeFrame,Time);
SSA =iCustom(NULL,timeFrame,indicatorFileName,"", "calculateValue",Lag,NumComps,PeriodNorm,N,0,y) 。
如果(timeFrame <= Period() ||y==iBarShift(NULL,timeFrame,Time))继续。
如果(!Interpolate)继续。
datetime time = iTime(NULL,timeFrame,y);
for(int n = 1; i+n =time; n++) 继续。
double factor = 1.0 / n;
for(int x = 1; x < n; x++)
{
SSA= x*因子*SSA + (1.0-x*因子)*SSA。
}
}
返回(0)。
}
//+------------------------------------------------------------------+
string sTfTable[] ={"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
//
//
//
//
//
int stringToTimeFrame(string tfs)
{
tfs = StringUpperCase(tfs);
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tfs==sTfTable || tfs==""+iTfTable)return(MathMax(iTfTable,Period())。
return(Period())。
}
string timeFrameToString(int tf)
{
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tf==iTfTable) return(sTfTable);
return("")。
}
//
//
//
//
//
string StringUpperCase(string str)
{
string s = str;
for (int length=StringLen(str)-1; length>=0; length--)
{
int tchar = StringGetChar(s, length);
if((tsar > 96 && tchar 223 && tchar < 256))
s = StringSetChar(s, length, tchar - 32);
否则如果(tchar > -33 && tchar < 0)
s = StringSetChar(s, length, tchar + 224);
}
return(s)。
}Wulong10
我没有看到图片
你能附上吗?
我已经贴出了图片,但在此再次贴出。
所以,当我从MT4中提取一个MA并将其应用于SSA(应用于第一个独立数据),当我打开MT4时,MA看起来没有问题,但是当它实时运行时,它不再跟随SSA了。
这只发生在M1上,在M5上运行没有问题。
图片应该可以直观地说明问题。
谢谢。
我已经贴出了图片,但在这里再次贴出。
因此,当我从MT4中提取一个MA,并将其应用于SSA(应用于第一个ind.数据),当我打开MT4时,MA看起来没有问题,但当它实时运行时,它不再跟随SSA了。
这只发生在M1上,在M5上运行没有问题。
这张图应该可以直观地说明问题。
谢谢。不要忘了,SSA会重新计算。如果你不计算所有重新计算的SSA条的MA,那么它将停止跟随SSA。
好的,现在我明白了,为什么它在M5上有效,这是因为我在那里把MA的周期设置为1,而在M1上我把它设置为2 ....,这应该可以解决这个问题。我已经在我的模拟交易中进行了测试,它并不完美,但要好得多!
在周期1中,MA应该跟随SSA。
但是我怎样才能在SSA的代码中直接加入MA?而且它还应该重新计算所有的SSA条数....,这不可能吗?
好的,现在我明白了,为什么在M5上有效,这是因为我在那里把MA的周期设置为1,而在M1上我把它设置为2....,这应该能解决问题。我已经在我的模拟交易中进行了测试,它并不完美,但要好得多!
对于第1期,MA应该遵循SSA。
但是我怎样才能在SSA的代码中直接加入MA?而且它还应该重新计算所有的SSA条数....,还是不可能?Wulong10
你能把你的mq4文件也贴出来吗(把文本复制到mql几乎总是会引起一些问题)?
不要在意最后的请求
这里有一个添加了移动平均线的版本:SSA__MA.mq4
好的,谢谢你,Mladen,你是最棒的!我现在没有时间测试了,今天晚上就可以了。
我现在没有时间测试,今天晚上是脚,我会让你知道结果的...当时间成熟时。
现在我也能看到我应该怎么做了,所以我在研究后会少了0.5%的愚蠢。