需要编码方面的帮助 - 页 8

 

类似这样的问题。

if (MACD[0]>MACD[1]) Alert("Message to use for alert"):
Jovager:
你好。

我怎样才能在一个指标中编入一个警报?

例如,当MACD[0]>MACD[1]时如何报警?

谢谢你的帮助。

 
mladen:

类似这样的情况:

if (MACD[0]>MACD[1]) Alert("Message to use for alert"):

谢谢Mladen,但在哪里?

我有这样的信息:

红色-If_function未定义

红色警报_emicolon预期。

------------------------------------------------------------------------------------------------------------------

#属性 indicator_separate_window

#属性 indicator_buffers 2

#属性 indicator_color1 银色

#属性 indicator_color2 红色

#属性 indicator_width1 2

//---- 指标参数

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//----指标缓冲区

double MacdBuffer[];

double SignalBuffer[];

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

//|自定义指标初始化函数|

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

int init()

{

//---- 绘图设置

SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,SignalSMA);

IndicatorDigits(Digits+1)。

//---- 指标缓冲区的映射

SetIndexBuffer(0,MacdBuffer);

SetIndexBuffer(1,SignalBuffer);

//---- DataWindow和指标子窗口标签的名称

IndicatorShortName("MACD("+FastEMA+", "+SlowEMA+", "+SignalSMA+")")。

SetIndexLabel(0, "MACD")。

SetIndexLabel(1, "信号")。

//---- 初始化完成

return(0);

}

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

//| 移动平均线收敛/背离|

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

开始()

{

int limit;

int counted_bars=IndicatorCounted()。

//---- 最后一个被计数的柱子将被重新计数

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars。

//---- macd在第1个缓冲区计数。

for(int i=0; i<limit; i++)

MacdBuffer=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i) 。

//---- 信号线在第2个缓冲器中计数

for(i=0; i<limit; i++)

SignalBuffer=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i)。

//---- 完成。

返回(0)。

}

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

 

就在你的代码中最后一个返回之前(这样你就能确保只有在所有其他处理完成后才会执行它)。

Jovager:
谢谢Mladen,但在哪里?

我有这样的信息。

红色-If_function未定义

红色-警报_分音符预期

------------------------------------------------------------------------------------------------------------------

#属性 indicator_separate_window

#属性 indicator_buffers 2

#属性 indicator_color1 银色

#属性 indicator_color2 红色

#属性 indicator_width1 2

//---- 指标参数

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- 指标缓冲区

double MacdBuffer[];

double SignalBuffer[];

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

//|自定义指标初始化函数|

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

int init()

{

//---- 绘图设置

SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,SignalSMA);

IndicatorDigits(Digits+1)。

//---- 指标缓冲区的映射

SetIndexBuffer(0,MacdBuffer);

SetIndexBuffer(1,SignalBuffer);

//---- DataWindow和指标子窗口标签的名称

IndicatorShortName("MACD("+FastEMA+", "+SlowEMA+", "+SignalSMA+")")。

SetIndexLabel(0, "MACD")。

SetIndexLabel(1, "信号")。

//---- 初始化完成

return(0);

}

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

//| 移动平均线收敛/背离|

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

开始()

{

int limit;

int counted_bars=IndicatorCounted()。

//---- 最后一个被计数的柱子将被重新计数

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars。

//---- macd在第1个缓冲区计数。

for(int i=0; i<limit; i++)

MacdBuffer=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i) 。

//---- 信号线在第2个缓冲器中计数

for(i=0; i<limit; i++)

SignalBuffer=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i)。

//---- 完成。

返回(0)。

}

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

请修复使用时间框架为 "0 "时的零除法错误

pivot_crazy.mq4 谁能解决使用时间框架为 "0 "时的除零错误?

谢谢。

附加的文件:
 

试试吧。现在已经纠正了

privateer:
pivot_crazy.mq4 谁能解决使用时间框架为 "0 "时的除零错误,谢谢。
附加的文件:
 

谢谢你Mladen的工作,像一个魅力

mladen:
试试吧。现在已经纠正了

谢谢你,Mladen的工作就像一种魅力

 

我需要帮助这个EA,它有马丁格尔功能,但不能正常工作,例如,如果一个位置在损失中关闭,马丁格尔功能应该乘以最后一个位置在损失中关闭的手数,但在代码中存在一个错误,使马丁格尔能够正常工作,这里是EAuniversalmacrossea.mq4

附加的文件:
 

亏损后开新单的方式不是马太效应,马太效应对已建仓位有效。

blondutrader:
我需要帮助这个EA,它有马丁格尔功能,但不能正常工作,例如,如果一个位置在损失中关闭,马丁格尔功能应该乘以最后一个在损失中关闭的位置的手数,但在代码中存在一个错误,使马丁格尔能够正常工作,这里是EAuniversalmacrossea.mq4 的。
 

当我想在每笔交易中交易5%的资金时,我如何计算我的手数?

 

sunshineh,

试着使用这个函数

double getLots(string symbol, double Risk, double stopLossDistance)

{

RefreshRates();

double lots = 0;

double MinLots = NormalizeDouble(MarketInfo(symbol,MODE_MINLOT) ,2);

double MaxLots = NormalizeDouble(MarketInfo(symbol,MODE_MAXLOT) ,2);

double LotStep = NormalizeDouble(MarketInfo(symbol,MODE_LOTSTEP),2);

int LotDigit = 2;

if(MarketInfo(symbol,MODE_DIGITS)==3 || MarketInfo(symbol,MODE_DIGITS)==5) stopLossDistance *= 10.0;

//

//

//

//

//

if (LotStep==1) LotDigit=0;

if (LotStep==0.1) LotDigit=1;

if (LotStep==0.01) LotDigit=2;

if (Risk>0)

{

if (AccountBalance()>AccountFreeMargin())

lots = NormalizeDouble(AccountFreeMargin()*(Risk/100.0)/(stopLossDistance*MarketInfo(symbol,MODE_TICKVALUE)),LotDigit);

else lots = NormalizeDouble(AccountBalance() *(Risk/100.0)/(stopLossDistance*MarketInfo(symbol,MODE_TICKVALUE)),LotDigit);

}

//

//

//

//

//

lots = NormalizeDouble(NormalizeDouble(lots/LotStep,0)*LotStep,LotDigit);

lots = MathMax(MathMin(lots,MaxLots),MinLots);

return(lots);

}
sunshineh:
当我想在每笔交易中交易5%的资金时,我如何计算我的手数?
原因: