gpt4 book ai didi

mql5 - 如果止损不为 0,ExpertMACD 会提高 [无效止损]

转载 作者:行者123 更新时间:2023-12-01 18:30:14 28 4
gpt4 key购买 nike

请注意,我刚刚开始使用 MQL5。

出于学习目的,我在 Alpari-MT5-Demo 账户上的 BTCUSD H1 对上的 ExpertMACD(MT5 中预装)上运行了 MT5 的 EA 优化。

一切正常,直到 2017 年 7 月的数据为止,此后 Advisor 不再发展,它一遍又一遍地放置 0 笔交易(屏幕截图)。回测也是如此,2017 年 7 月的数据没有进行任何交易。

在测试日志中,出现错误[无效停止]。如果我从要优化的输入中取消选择止损级别并将默认值设置为 0,则一切都会再次运行,尽管不再使用止损。

你能解释一下这是怎么回事吗?为什么负责整个历史的 Advisor 从 2017 年 7 月起就停止工作了? (我检查了刻度数据,看起来一切正常)为什么取消止损会使其再次进行交易?

enter image description here

附注

我注意到,当 BTCUSD 的价差(突然)从 2 到 13000(是的,没有逗号)时,顾问程序崩溃了,这当然会让顾问程序陷入困境,而且一般来说,不会使感觉。这怎么可能?这种情况我该怎么办?我检查了其他经纪商,他们都显示在 2017 年 7 月的某个地方出现了同样的点差增加。

深入Alpari网站我发现the average spread value for BTCUSD确实有那么高。再说一遍,这怎么可能?为什么会这样呢? ( Maybe related to the fork? 这对我来说毫无意义)

最后,在这种情况下,您将如何修改 ExpertMACD 以便正确下单,包括合理的止损?

ExpertMACD的代码如下:

//+------------------------------------------------------------------+
//| ExpertMACD.mq5 |
//| Copyright 2009-2017, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
#include <Expert\Signal\SignalMACD.mqh>
#include <Expert\Trailing\TrailingNone.mqh>
#include <Expert\Money\MoneyNone.mqh>
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
//--- inputs for expert
input string Inp_Expert_Title ="ExpertMACD";
int Expert_MagicNumber =10981;
bool Expert_EveryTick =false;
//--- inputs for signal
input int Inp_Signal_MACD_PeriodFast =12;
input int Inp_Signal_MACD_PeriodSlow =24;
input int Inp_Signal_MACD_PeriodSignal=9;
input int Inp_Signal_MACD_TakeProfit =50;
input int Inp_Signal_MACD_StopLoss =20;
//+------------------------------------------------------------------+
//| Global expert object |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- Initializing expert
if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
{
//--- failed
printf(__FUNCTION__+": error initializing expert");
ExtExpert.Deinit();
return(-1);
}
//--- Creation of signal object
CSignalMACD *signal=new CSignalMACD;
if(signal==NULL)
{
//--- failed
printf(__FUNCTION__+": error creating signal");
ExtExpert.Deinit();
return(-2);
}
//--- Add signal to expert (will be deleted automatically))
if(!ExtExpert.InitSignal(signal))
{
//--- failed
printf(__FUNCTION__+": error initializing signal");
ExtExpert.Deinit();
return(-3);
}
//--- Set signal parameters
signal.PeriodFast(Inp_Signal_MACD_PeriodFast);
signal.PeriodSlow(Inp_Signal_MACD_PeriodSlow);
signal.PeriodSignal(Inp_Signal_MACD_PeriodSignal);
signal.TakeLevel(Inp_Signal_MACD_TakeProfit);
signal.StopLevel(Inp_Signal_MACD_StopLoss);
//--- Check signal parameters
if(!signal.ValidationSettings())
{
//--- failed
printf(__FUNCTION__+": error signal parameters");
ExtExpert.Deinit();
return(-4);
}
//--- Creation of trailing object
CTrailingNone *trailing=new CTrailingNone;
if(trailing==NULL)
{
//--- failed
printf(__FUNCTION__+": error creating trailing");
ExtExpert.Deinit();
return(-5);
}
//--- Add trailing to expert (will be deleted automatically))
if(!ExtExpert.InitTrailing(trailing))
{
//--- failed
printf(__FUNCTION__+": error initializing trailing");
ExtExpert.Deinit();
return(-6);
}
//--- Set trailing parameters
//--- Check trailing parameters
if(!trailing.ValidationSettings())
{
//--- failed
printf(__FUNCTION__+": error trailing parameters");
ExtExpert.Deinit();
return(-7);
}
//--- Creation of money object
CMoneyNone *money=new CMoneyNone;
if(money==NULL)
{
//--- failed
printf(__FUNCTION__+": error creating money");
ExtExpert.Deinit();
return(-8);
}
//--- Add money to expert (will be deleted automatically))
if(!ExtExpert.InitMoney(money))
{
//--- failed
printf(__FUNCTION__+": error initializing money");
ExtExpert.Deinit();
return(-9);
}
//--- Set money parameters
//--- Check money parameters
if(!money.ValidationSettings())
{
//--- failed
printf(__FUNCTION__+": error money parameters");
ExtExpert.Deinit();
return(-10);
}
//--- Tuning of all necessary indicators
if(!ExtExpert.InitIndicators())
{
//--- failed
printf(__FUNCTION__+": error initializing indicators");
ExtExpert.Deinit();
return(-11);
}
//--- succeed
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Deinitialization function of the expert |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ExtExpert.Deinit();
}
//+------------------------------------------------------------------+
//| Function-event handler "tick" |
//+------------------------------------------------------------------+
void OnTick(void)
{
ExtExpert.OnTick();
}
//+------------------------------------------------------------------+
//| Function-event handler "trade" |
//+------------------------------------------------------------------+
void OnTrade(void)
{
ExtExpert.OnTrade();
}
//+------------------------------------------------------------------+
//| Function-event handler "timer" |
//+------------------------------------------------------------------+
void OnTimer(void)
{
ExtExpert.OnTimer();
}
//+------------------------------------------------------------------+

更新

过了一会儿,Alpari的客服回复了:

The Spread is indicated correctly in the specification at our website. Spread is specified by 3 digits after the dot. It is about 19 US dollars difference between Bid and Ask prices.

因此,19094 的价差实际上是 19.094。

最佳答案

CSampleExpert::LongOpened() 函数内,您可以添加一个 block 来忽略较大价差的条目:

double spread = m_symbol.Ask()
- m_symbol.Bid(); // Spread(); is int, not double

if ( spread > InpMaxSpread * m_adjusted_point ){
printf( "%i - spread %.5f is too high!", __LINE__, spread );
return;
}

ShortOpened()相同。另外,不要忘记将 InpMaxSpread 添加到输入中。

至于关于止损的问题 - 这取决于您的需要,代码中提供了使用止盈的示例。

double stoploss = m_symbol.Bid() - InpStopLoss * m_adjusted_point;

if ( m_trade.PositionOpen( m_symbol,
ORDER_TYPE_BUY,
InpLots,
price,
stoploss,
tp
)
){ ... }

关于mql5 - 如果止损不为 0,ExpertMACD 会提高 [无效止损],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47043096/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com