编码帮助 - 页 514

 
mladen:
triip

请看这个:https://www.mql5.com/en/forum/general

将快速平均线的周期设置为1,那么它将与价格越过移动平均线(slo ma)的情况相同。

非常好!谢谢你mladen

 

指示器这样的错误。如何修复?

附加的文件:
xxc.jpg  188 kb
 
popej30:
指示器这样的错误。如何解决?

从那张图片上看不出哪里出了错误

 

如何在Smartfone上添加警报

代码是:....

.... 但警报显示的是每一个现在的蜡烛!!!我有数字 "推 "MetaQuotes ID。

我有数字 "push "MetaQuotes ID。

测试正常。

有什么问题吗?

附加的文件:
xxc_1.jpg  97 kb
xxv.jpg  115 kb
 
popej30:
如何在智能电话上添加警报?

代码是:....

.... 但警报显示每个人现在都是蜡烛!!!。

我有数字 "推 "MetaQuotes ID。

测试正常。

什么是错的?

你没有任何标准来决定何时发送通知(类似于 "if (condition==true) SentNotification("alert");)。添加 "如果 "条件,何时执行?

它应该在启动程序中,而不是在脱机程序中(因为脱机程序只有在指标因任何原因停止时才会执行)

 

提醒它是在开放的蜡烛上--一个错误!

警报是只改变颜色的蜡烛。

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_width1 4

#property indicator_color2 Red

#property indicator_width2 4

#property indicator_minimum 0

#property indicator_maximum 1

//---- input parameters

extern string TimeFrame = "Current time frame";

extern int Price = 12;

extern int Length = 4;

extern int Displace = 0;

extern int Filter = 1;

extern double Deviation = 0;

extern string _ = "alerts settings";

extern bool alertsOn = true;

extern bool alertsOnCurrent = true;

extern bool alertsMessage = true;

extern bool alertsSound = false;

extern bool alertsEmail = false;

double Cycle = 4;

//---- indicator buffers

double MABuffer[];

double UpBuffer[];

double DnBuffer[];

double price[];

double trend[];

string indicatorFileName;

bool returnBars;

bool calculateValue;

int timeFrame;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

SendNotification("smartfon alert");

int ft=0;

string short_name;

//---- indicator line

IndicatorBuffers(5);

SetIndexBuffer(0,UpBuffer); SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexBuffer(1,DnBuffer); SetIndexStyle(1,DRAW_HISTOGRAM);

SetIndexBuffer(2,MABuffer);

SetIndexBuffer(3,price);

SetIndexBuffer(4,trend);

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

//---- name for DataWindow and indicator subwindow label

SetIndexLabel(0,"NLMA");

SetIndexLabel(1,"Up");

SetIndexLabel(2,"Dn");

//----

SetIndexShift(0,Displace);

SetIndexShift(1,Displace);

SetIndexShift(2,Displace);

SetIndexDrawBegin(0,Length*Cycle+Length);

SetIndexDrawBegin(1,Length*Cycle+Length);

SetIndexDrawBegin(2,Length*Cycle+Length);

//----

indicatorFileName = WindowExpertName();

returnBars = (TimeFrame=="returnBars"); if (returnBars) return(0);

calculateValue = (TimeFrame=="calculateValue"); if (calculateValue) return(0);

timeFrame = stringToTimeFrame(TimeFrame);

short_name=timeFrameToString(timeFrame)+" XXX ("+Length+")";

IndicatorShortName(short_name);

return(0);

}

//+------------------------------------------------------------------+

//| NonLagMA_v4 |

//+------------------------------------------------------------------+

int start()

{

int i,shift, counted_bars=IndicatorCounted(),limit;

double alfa, beta, t, Sum, Weight, g;

double pi = 3.1415926535;

double Coeff = 3*pi;

int Phase = Length-1;

double Len = Length*Cycle + Phase;

if ( counted_bars > 0 ) limit=Bars-counted_bars;

if ( counted_bars < 0 ) return(0);

if ( counted_bars ==0 ) limit=Bars-Len-1;

if ( returnBars) { UpBuffer[0] = limit+1; return(0); }

if (calculateValue || timeFrame==Period())

{

if ( counted_bars < 1 )

for(i=1;i<Length*Cycle+Length;i++)

{

MABuffer=0;

UpBuffer=0;

DnBuffer=0;

}

for(shift=limit;shift>=0;shift--)

{

Weight=0; Sum=0; t=0;

for (i=0;i<=Len-1;i++)

{

g = 1.0/(Coeff*t+1);

if (t <= 0.5 ) g = 1;

beta = MathCos(pi*t);

alfa = g * beta;

//if (shift>=1) price = iMA(NULL,0,Per,Displace,Mode,Price,shift+i);

//else

price = iMA(NULL,0,1,0,MODE_SMA,Price,shift+i);

Sum += alfa*price;

Weight += alfa;

if ( t < 1 ) t += 1.0/(Phase-1);

else if ( t < Len-1 ) t += (2*Cycle-1)/(Cycle*Length-1);

}

if (Weight > 0) MABuffer[shift] = (1.0+Deviation/100)*Sum/Weight;

if (Filter>0)

{

if( MathAbs(MABuffer[shift]-MABuffer[shift+1]) < Filter*Point ) MABuffer[shift]=MABuffer[shift+1];

}

trend[shift]=trend[shift+1];

if (MABuffer[shift]-MABuffer[shift+1] > Filter*Point) trend[shift]= 1;

if (MABuffer[shift+1]-MABuffer[shift] > Filter*Point) trend[shift]=-1;

if (trend[shift]>0)

{

UpBuffer[shift] = 1;

DnBuffer[shift] = EMPTY_VALUE;

}

if (trend[shift]<0)

{

DnBuffer[shift] = 1;

UpBuffer[shift] = EMPTY_VALUE;

}

}

manageAlerts();

return(0);

}

//

//

//

//

//

for(i = limit; i >=0; i--)

{

int y = iBarShift(NULL,timeFrame,Time);

UpBuffer = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Price,Length,Displace,Filter,Deviation,0,y);

DnBuffer = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Price,Length,Displace,Filter,Deviation,1,y);

trend = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Price,Length,Displace,Filter,Deviation,4,y);

}

manageAlerts();

return(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((tchar > 96 && tchar 223 && tchar < 256))

s = StringSetChar(s, length, tchar - 32);

else if(tchar > -33 && tchar < 0)

s = StringSetChar(s, length, tchar + 224);

}

return(s);

}

//

//

//

//

//

void manageAlerts()

{

if (!calculateValue && alertsOn)

{

if (alertsOnCurrent)

int whichBar = 0;

else whichBar = 1; whichBar = iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar));

if (trend[whichBar] != trend[whichBar+1])

{

if (trend[whichBar] == 1) doAlert(whichBar,"buy");

if (trend[whichBar] == -1) doAlert(whichBar,"sell");

}

}

}

//

//

//

//

//

void doAlert(int forBar, string doWhat)

{

static string previousAlert="nothing";

static datetime previousTime;

string message;

if (previousAlert != doWhat || previousTime != Time[forBar]) {

previousAlert = doWhat;

previousTime = Time[forBar];

//

//

//

//

//

message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," - ",timeFrameToString(timeFrame)+" NonLagMa slope ",doWhat);

if (alertsMessage) Alert(message);

if (alertsEmail) SendMail(StringConcatenate(Symbol()," XXX "),message);

if (alertsSound) PlaySound("alert2.wav");

}

}
 
popej30:
提醒它是在开盘的蜡烛上--一个错误!

警报是只改变颜色的蜡烛。

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_width1 4

#property indicator_color2 Red

#property indicator_width2 4

#property indicator_minimum 0

#property indicator_maximum 1

//---- input parameters

extern string TimeFrame = "Current time frame";

extern int Price = 12;

extern int Length = 4;

extern int Displace = 0;

extern int Filter = 1;

extern double Deviation = 0;

extern string _ = "alerts settings";

extern bool alertsOn = true;

extern bool alertsOnCurrent = true;

extern bool alertsMessage = true;

extern bool alertsSound = false;

extern bool alertsEmail = false;

double Cycle = 4;

//---- indicator buffers

double MABuffer[];

double UpBuffer[];

double DnBuffer[];

double price[];

double trend[];

string indicatorFileName;

bool returnBars;

bool calculateValue;

int timeFrame;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

SendNotification("smartfon alert");

int ft=0;

string short_name;

//---- indicator line

IndicatorBuffers(5);

SetIndexBuffer(0,UpBuffer); SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexBuffer(1,DnBuffer); SetIndexStyle(1,DRAW_HISTOGRAM);

SetIndexBuffer(2,MABuffer);

SetIndexBuffer(3,price);

SetIndexBuffer(4,trend);

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

//---- name for DataWindow and indicator subwindow label

SetIndexLabel(0,"NLMA");

SetIndexLabel(1,"Up");

SetIndexLabel(2,"Dn");

//----

SetIndexShift(0,Displace);

SetIndexShift(1,Displace);

SetIndexShift(2,Displace);

SetIndexDrawBegin(0,Length*Cycle+Length);

SetIndexDrawBegin(1,Length*Cycle+Length);

SetIndexDrawBegin(2,Length*Cycle+Length);

//----

indicatorFileName = WindowExpertName();

returnBars = (TimeFrame=="returnBars"); if (returnBars) return(0);

calculateValue = (TimeFrame=="calculateValue"); if (calculateValue) return(0);

timeFrame = stringToTimeFrame(TimeFrame);

short_name=timeFrameToString(timeFrame)+" XXX ("+Length+")";

IndicatorShortName(short_name);

return(0);

}

//+------------------------------------------------------------------+

//| NonLagMA_v4 |

//+------------------------------------------------------------------+

int start()

{

int i,shift, counted_bars=IndicatorCounted(),limit;

double alfa, beta, t, Sum, Weight, g;

double pi = 3.1415926535;

double Coeff = 3*pi;

int Phase = Length-1;

double Len = Length*Cycle + Phase;

if ( counted_bars > 0 ) limit=Bars-counted_bars;

if ( counted_bars < 0 ) return(0);

if ( counted_bars ==0 ) limit=Bars-Len-1;

if ( returnBars) { UpBuffer[0] = limit+1; return(0); }

if (calculateValue || timeFrame==Period())

{

if ( counted_bars < 1 )

for(i=1;i<Length*Cycle+Length;i++)

{

MABuffer=0;

UpBuffer=0;

DnBuffer=0;

}

for(shift=limit;shift>=0;shift--)

{

Weight=0; Sum=0; t=0;

for (i=0;i<=Len-1;i++)

{

g = 1.0/(Coeff*t+1);

if (t <= 0.5 ) g = 1;

beta = MathCos(pi*t);

alfa = g * beta;

//if (shift>=1) price = iMA(NULL,0,Per,Displace,Mode,Price,shift+i);

//else

price = iMA(NULL,0,1,0,MODE_SMA,Price,shift+i);

Sum += alfa*price;

Weight += alfa;

if ( t < 1 ) t += 1.0/(Phase-1);

else if ( t < Len-1 ) t += (2*Cycle-1)/(Cycle*Length-1);

}

if (Weight > 0) MABuffer[shift] = (1.0+Deviation/100)*Sum/Weight;

if (Filter>0)

{

if( MathAbs(MABuffer[shift]-MABuffer[shift+1]) < Filter*Point ) MABuffer[shift]=MABuffer[shift+1];

}

trend[shift]=trend[shift+1];

if (MABuffer[shift]-MABuffer[shift+1] > Filter*Point) trend[shift]= 1;

if (MABuffer[shift+1]-MABuffer[shift] > Filter*Point) trend[shift]=-1;

if (trend[shift]>0)

{

UpBuffer[shift] = 1;

DnBuffer[shift] = EMPTY_VALUE;

}

if (trend[shift]<0)

{

DnBuffer[shift] = 1;

UpBuffer[shift] = EMPTY_VALUE;

}

}

manageAlerts();

return(0);

}

//

//

//

//

//

for(i = limit; i >=0; i--)

{

int y = iBarShift(NULL,timeFrame,Time);

UpBuffer = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Price,Length,Displace,Filter,Deviation,0,y);

DnBuffer = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Price,Length,Displace,Filter,Deviation,1,y);

trend = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Price,Length,Displace,Filter,Deviation,4,y);

}

manageAlerts();

return(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((tchar > 96 && tchar 223 && tchar < 256))

s = StringSetChar(s, length, tchar - 32);

else if(tchar > -33 && tchar < 0)

s = StringSetChar(s, length, tchar + 224);

}

return(s);

}

//

//

//

//

//

void manageAlerts()

{

if (!calculateValue && alertsOn)

{

if (alertsOnCurrent)

int whichBar = 0;

else whichBar = 1; whichBar = iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar));

if (trend[whichBar] != trend[whichBar+1])

{

if (trend[whichBar] == 1) doAlert(whichBar,"buy");

if (trend[whichBar] == -1) doAlert(whichBar,"sell");

}

}

}

//

//

//

//

//

void doAlert(int forBar, string doWhat)

{

static string previousAlert="nothing";

static datetime previousTime;

string message;

if (previousAlert != doWhat || previousTime != Time[forBar]) {

previousAlert = doWhat;

previousTime = Time[forBar];

//

//

//

//

//

message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," - ",timeFrameToString(timeFrame)+" NonLagMa slope ",doWhat);

if (alertsMessage) Alert(message);

if (alertsEmail) SendMail(StringConcatenate(Symbol()," XXX "),message);

if (alertsSound) PlaySound("alert2.wav");

}

}

你为什么不简单地使用任何一个已经正确编码的非滞后的mas呢?你的t变量值从来没有被分配一个合适的值--其余的dU没有检查,因为仅此一点就可以阻止所有的正确计算。

 
triip:
非常好!谢谢你mladen

快乐交易

 
mladen:
你为什么不简单地使用任何一个已经正确编码的非滞后的mas?你的t变量值从来没有被分配一个正确的值--其余的dU没有检查,因为仅此一项就可以阻止所有的正确计算

你帮助我的 "推动智能方"。

 
popej30:
你帮助我的 "推送智能方"。

如果所有其他部分(MetQuotesID和其他部分)都设置好了,只需要SendNotificaton()就可以了。