如何编码? - 页 284 1...277278279280281282283284285286287288289290291...347 新评论 Beno 2012.01.02 15:08 #2831 我已经整理出了一个关于时间过滤器 关闭所有的解决方案。 外部变量 extern string timefilter="Time Filter"; extern int gmtshift=1; // gmt offset of the broker extern bool generalfilter=false; // enable time filter extern int starthour=7; // start hour to trade after this hour extern int startminutes=0; // minutes of the start hour extern int endhour=21; // stop to trade after this hour extern int endminutes=0; // minutes of the start hour extern bool tradesunday=true; // trade on sunday extern bool fridayfilter=false; // enable special time filter on friday extern int fridayhour=21; // stop to trade after this hour extern int fridayminutes=0; // minutes of the friday hour [/CODE] int nstarthour,nendhour,nfridayhour; string istarthour,istartminutes,iendhour,iendminutes,ifridayhour,ifridayminutes; datetime tstart,tend,tfriday;[/CODE] Place Code in Start, [CODE] if(generalfilter){ nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24; if(nstarthour<10)istarthour="0"+nstarthour; if(nstarthour>9)istarthour=nstarthour; if(startminutes<10)istartminutes="0"+startminutes; if(startminutes>9)istartminutes=startminutes; tstart=StrToTime(istarthour+":"+istartminutes); nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24; if(endhour<10)iendhour="0"+nendhour; if(endhour>9)iendhour=nendhour; if(endminutes<10)iendminutes="0"+endminutes; if(endminutes>9)iendminutes=endminutes; tend=StrToTime(iendhour+":"+iendminutes); } if(fridayfilter){ nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24; if(nfridayhour<10)ifridayhour="0"+nfridayhour; if(nfridayhour>9)ifridayhour=nfridayhour; if(fridayminutes<10)ifridayminutes="0"+fridayminutes; if(fridayminutes>9)ifridayminutes=fridayminutes; tfriday=StrToTime(ifridayhour+":"+ifridayminutes); } if((generalfilter && (nstarthour<nendhour && TimeCurrent()tend) || (nstarthour>nendhour && TimeCurrent()tend)) || (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday)) { CloseAll(); Comment("Non-trading Hours All Positions Closed"); return(0); } and the CloseAll function. [CODE] void CloseAll(){ int total = OrdersTotal(); for(int i=total-1;i>=0;i--){ OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type){ //Close opened long positions case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Lime); break; //Close opened short positions case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, LightGreen ); } if(result == false){ Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } return(0); } 谢谢你的提示和建议,Kalenzo How to code? 新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 Aggressive scalp ea Beno 2012.01.02 17:11 #2832 停止损失 日子 我一直在尝试一个实验,根据每笔交易的tickvalue、最大dd和百分比来计算SL。 double lotSize = NormalizeDouble(Kellylot(),2); double Pip = Point; if(Digits==3 || Digits==5) Pip = 10*Point; double Bal = AccountBalance(); // $1000 double TV = MarketInfo(Symbol(), MODE_TICKVALUE); // $1 double Risk = 2; // 2% double MaxDD = 10; // 10% double RiskCapital = Bal*MaxDD/100; // Total Exposure 10% of $1000 = $100 double RPT = Bal*Risk/100; // 2% of $1000 = $20 double stopLoss = NormalizeDouble(RPT/TV*lotSize/Pip,Digits); //$20/1*0.01/10 = 0.02000 double Positions = MathAbs(RiskCapital/RPT); // Maximum 5 positions 100 / 20 我的想法是,根据货币对和货币对的单个tickvalue以及手数,可以设置2%的SL。 我认为这是正确的,但如果可能的话,我希望有人能检查一下。 How to code? 需要编码方面的帮助 编码帮助 Kale 2012.01.03 07:13 #2833 Beno: 尊敬的先生 我一直在尝试一个实验,根据每笔交易的tickvalue、最大dd和百分比来计算SL。 double lotSize = NormalizeDouble(Kellylot(),2); double Pip = Point; if(Digits==3 || Digits==5) Pip = 10*Point; double Bal = AccountBalance(); // $1000 double TV = MarketInfo(Symbol(), MODE_TICKVALUE); // $1 double Risk = 2; // 2% double MaxDD = 10; // 10% double RiskCapital = Bal*MaxDD/100; // Total Exposure 10% of $1000 = $100 double RPT = Bal*Risk/100; // 2% of $1000 = $20 double stopLoss = NormalizeDouble(RPT/TV*lotSize/Pip,Digits); //$20/1*0.01/10 = 0.02000 double Positions = MathAbs(RiskCapital/RPT); // Maximum 5 positions 100 / 20 我的想法是,根据货币对和货币对的单个tickvalue以及手数,可以设置2%的SL。 我认为这是正确的,但如果可能的话,希望有人能检查一下。 干得好,贝诺。 送鱼竿总比送鱼好。我很高兴能通过一些评论来帮助你。 至于止损,这个想法很好,但是也可以尝试以相反的方式来考虑它。 首先设置止损 其次设定交易规模 这样一来,你就可以根据市场情况来调整系统的进入/退出,而且风险不会超过你账户的X%,但退出将取决于系统逻辑而不是风险百分比。 Beno 2012.01.03 21:17 #2834 Kalenzo: 干得好,贝诺。送鱼竿总比送鱼好。我很高兴能用一些评论来帮助你。 关于止损,这个想法很好,但是也可以尝试用相反的方式来考虑。 首先设置止损 其次设定交易规模 通过这种方式,你将使系统的进入/退出符合市场条件,并且不会从你的账户中冒出超过X%的风险,但退出将取决于系统逻辑而不是风险百分比。 你好,Kalenzo 我在模拟和真实账户上得到一个错误的开仓卖出指令:无效的止损,而且没有开仓交易。但在测试器上运行良好,没有错误信息。 欧元兑美元,日线:修改#1在1.43348买入0.01欧元兑美元,止损点:1.43895,止盈点:0.00000 OK SL相差0.00547点 我已经检查了 mode_freezelevel 0.0000 mode_stoplevel 0.0000 double lotSize = NormalizeDouble(Kellylot(),2); double Bal = AccountFreeMargin(); double TV = MarketInfo(Symbol(), MODE_TICKVALUE); double Risk = 0.3; double MaxDD = 10; double RiskCapital = Bal*MaxDD/100; double RPT = Bal*Risk/100; double stopLoss = NormalizeDouble((RPT/TV)*lotSize/pips2dbl,Digits); double Positions = MathAbs(RiskCapital/RPT); double SL; //---- sell conditions if(sellsig && ttime!=Time[0]){ double bid = NormalizeDouble(Bid, Digits); SL = NormalizeDouble(Bid + stopLoss * pips2dbl, Digits); res=OrderSend(symbol,OP_SELL,lotSize,bid,slippage * pips2dbl,SL,0,"Pivot_Sell",SpecificMagic,0,Red); if( res<0 ) { Print("Error opening SELL order : ",ErrorDescription(GetLastError())); Print("Bid=" + DoubleToStr(bid,Digits) + " : SL=" + DoubleToStr(SL,Digits)); res=0; } else //now enter in the SL and TP via OrderModify to make compatible with ECN broker { if (OrderSelect(res, SELECT_BY_TICKET)) { if (!OrderModify(res, Bid, SL, 0, 0, Red)) Print("Error modifying order"); } } ttime=Time[0]; return; } //---- buy conditions if(buysig && ttime!=Time[0]) { double ask = NormalizeDouble(Ask, Digits); SL = NormalizeDouble(Ask - stopLoss * pips2dbl, Digits); res=OrderSend(symbol,OP_BUY,lotSize,ask,slippage * pips2dbl,SL,0,"Pivot Buy",SpecificMagic,0,Blue); if( res<0 ) { Print("Error opening BUY order : ",ErrorDescription(GetLastError())); Print("Ask=" + DoubleToStr(ask,Digits) + " : SL=" + DoubleToStr(SL,Digits)); res=0; } else //now enter in the SL and TP via OrderModify to make compatible with ECN broker { if (OrderSelect(res, SELECT_BY_TICKET)) { if (!OrderModify(res, Ask, SL, 0, 0, Blue)) Print("Error modifying order"); } } ttime=Time[0]; return; } } 我以前从未遇到过这种情况。 欢呼声 贝诺 How to code? Unknown ticket for OrderModify [ARCHIVE!] Any rookie question, cmfxtrader 2012.01.03 21:50 #2835 闩锁/非闩锁功能 是否有办法在mq4中编码一个锁存/解锁功能。 你可以根据一个条件锁住一个位的真值,它将存储这个值直到被另一个条件解锁。 cmfxtrader Kale 2012.01.04 06:34 #2836 Beno: 再见,Kalenzo我在模拟和真实账户上得到一个错误的卖出订单:无效的止损,但在测试器上运行良好,没有错误信息。 欧元兑美元,日线:修改#1在1.43348买入0.01欧元兑美元,止损点:1.43895,止盈点:0.00000 OK SL相差0.00547点 我已经检查了 mode_freezelevel 0.0000 mode_stoplevel 0.0000 double lotSize = NormalizeDouble(Kellylot(),2); double Bal = AccountFreeMargin(); double TV = MarketInfo(Symbol(), MODE_TICKVALUE); double Risk = 0.3; double MaxDD = 10; double RiskCapital = Bal*MaxDD/100; double RPT = Bal*Risk/100; double stopLoss = NormalizeDouble((RPT/TV)*lotSize/pips2dbl,Digits); double Positions = MathAbs(RiskCapital/RPT); double SL; //---- sell conditions if(sellsig && ttime!=Time[0]){ double bid = NormalizeDouble(Bid, Digits); SL = NormalizeDouble(Bid + stopLoss * pips2dbl, Digits); res=OrderSend(symbol,OP_SELL,lotSize,bid,slippage * pips2dbl,SL,0,"Pivot_Sell",SpecificMagic,0,Red); if( res<0 ) { Print("Error opening SELL order : ",ErrorDescription(GetLastError())); Print("Bid=" + DoubleToStr(bid,Digits) + " : SL=" + DoubleToStr(SL,Digits)); res=0; } else //now enter in the SL and TP via OrderModify to make compatible with ECN broker { if (OrderSelect(res, SELECT_BY_TICKET)) { if (!OrderModify(res, Bid, SL, 0, 0, Red)) Print("Error modifying order"); } } ttime=Time[0]; return; } //---- buy conditions if(buysig && ttime!=Time[0]) { double ask = NormalizeDouble(Ask, Digits); SL = NormalizeDouble(Ask - stopLoss * pips2dbl, Digits); res=OrderSend(symbol,OP_BUY,lotSize,ask,slippage * pips2dbl,SL,0,"Pivot Buy",SpecificMagic,0,Blue); if( res<0 ) { Print("Error opening BUY order : ",ErrorDescription(GetLastError())); Print("Ask=" + DoubleToStr(ask,Digits) + " : SL=" + DoubleToStr(SL,Digits)); res=0; } else //now enter in the SL and TP via OrderModify to make compatible with ECN broker { if (OrderSelect(res, SELECT_BY_TICKET)) { if (!OrderModify(res, Ask, SL, 0, 0, Blue)) Print("Error modifying order"); } } ttime=Time[0]; return; } } 我以前从未遇到过这种情况。 欢呼声 贝诺 可能是你的止损太近了。试着把止损值 乘以10。当你在4位数的经纪商上测试系统,而你在5位数的经纪商上交易时,这是很常见的问题。你也可以在5位数的经纪商上测试,但不要连接到经纪商(在离线模式),然后metatrader会有旧的设置(从4位数)。 首先从这一行开始。 NormalizeDouble(Ask - stopLoss * pips2dbl, Digits)。 打印这个值 => stopLoss*pips2dbl 然后你就会知道止损的真正价值。 如果它是20或10,那么这意味着你需要将它乘以点值。 NormalizeDouble(Ask - (stopLoss * pips2dbl) *Point, Digits); 如果它像0.00009,那么你需要乘以10,因为它应该是0.0009(当然,如果你想设置9个点的止损)。 Kale 2012.01.04 06:39 #2837 cmfxtrader: 是否有办法在mq4中编码一个锁存/解锁功能。 你可以根据一个条件锁定一个位,并存储这个值,直到被另一个条件解除锁定。 我不确定我的理解是否正确。你希望打开/关闭EA的特定部分(功能),还是希望通过EA B中的操作来取消EA A的功能?这样或那样,都是可能的。 ExForX 2012.01.06 15:23 #2838 将货币价值转换成价格(用于利润目标计算) 我想编写一个函数,为一篮子交易的给定利润目标返回一个价格值,但我遇到了困难。我想达到的目标,是在屏幕上画一条简单的水平线,表示利润目标。然而,利润目标是用户可定义的变量,其形式是一个货币值,而不是一个价格值。(例如,目标=100欧元,而不是目标=1.2000)。 到目前为止,我拥有的程序。 (我的账户是欧元!)。 1) 假设我为USDJPY开了几个买入头寸(为了创造一个例子,在随机位置)。 2) 我计算篮子的平均开仓价(比方说1.1500,同样是假设),并显示一条水平线来表明这一点 3) 我有一个设置了盈利目标的变量:比方说目标=100欧元 4) 当篮子利润>=目标时,我可以成功地关闭所有未结头寸。 这中间的步骤是缺失的。我需要一个函数:double targetPrice(){},返回目标价格。绘制水平线不是问题:计算目标价格才是问题。 目标价格=平均开盘价+货币价值-目标(100欧元)。 所以我基本上想知道:我如何将货币价值转换为 点数。这样我就可以把点数加到平均价格上,这样我就有了我的目标价格。请记住,这也必须考虑到我有一个欧元账户,而我正在交易美元兑日元。我想这里面也有隐患吧? Beno 2012.01.06 22:11 #2839 ECN SL不工作 尊敬的客户 我试图建立一个能在ECN上工作的EA,我知道SL和TP必须被放置/修改,我认为设置是正确的,现在订单打开了,但SL没有被放置,extern double StopLoss = 100;任何帮助都是伟大的。 //---- buy conditions if(buysig && ttime!=Time[0]) { ticket = OrderSend(Symbol(), OP_BUY, lotSize, MarketInfo(Symbol(), MODE_ASK), 2, 0, 0, "", 12345); if(ticket > -1){ if (!OrderSelect(ticket, SELECT_BY_TICKET)) { error_code = GetLastError(); Print("Error: " + ErrorDescription(error_code)); return(-1); } Print("order "+ticket+" successfully opened"); //now enter in the SL and TP via OrderModify to make compatible with ECN broker SL = MarketInfo(Symbol(), MODE_ASK) - (StopLoss * pips2points); Print("Ask = " + DoubleToStr(Ask,Digits) + " : SL = " + DoubleToStr(SL,Digits)); //round to nearest Tickvalue SL = DoubleRound(SL, MarketInfo(Symbol(), MODE_TICKSIZE)); Print("SL rounded: " + SL); if(!OrderModify(ticket, entry_price, SL, 0, Blue)) { error_code = GetLastError(); Print("Error: " + ErrorDescription(error_code)); return(-1); } Print("Stoploss successfully set"); ttime=Time[0]; return(0); } } } //Tickvalue Rounding double DoubleRound(double number, double step){ double mod = MathMod(number, step); if(mod < step/2.0) step = 0; double rounded = number - mod + step; return (rounded); } How to code? MQL4 Learning Automated Trading Championship 2007: bnbb2004 2012.01.07 19:53 #2840 ,,,,,,,,,,,,,.,,,,,,,,, 附加的文件: test_ea.txt 10 kb aizig.ex4 10 kb 1...277278279280281282283284285286287288289290291...347 新评论 原因: 取消 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
我已经整理出了一个关于时间过滤器 关闭所有的解决方案。
外部变量
extern string timefilter="Time Filter";
extern int gmtshift=1; // gmt offset of the broker
extern bool generalfilter=false; // enable time filter
extern int starthour=7; // start hour to trade after this hour
extern int startminutes=0; // minutes of the start hour
extern int endhour=21; // stop to trade after this hour
extern int endminutes=0; // minutes of the start hour
extern bool tradesunday=true; // trade on sunday
extern bool fridayfilter=false; // enable special time filter on friday
extern int fridayhour=21; // stop to trade after this hour
extern int fridayminutes=0; // minutes of the friday hour
[/CODE]
string istarthour,istartminutes,iendhour,iendminutes,ifridayhour,ifridayminutes;
datetime tstart,tend,tfriday;[/CODE]
Place Code in Start,
[CODE] if(generalfilter){
nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24;
if(nstarthour<10)istarthour="0"+nstarthour;
if(nstarthour>9)istarthour=nstarthour;
if(startminutes<10)istartminutes="0"+startminutes;
if(startminutes>9)istartminutes=startminutes;
tstart=StrToTime(istarthour+":"+istartminutes);
nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24;
if(endhour<10)iendhour="0"+nendhour;
if(endhour>9)iendhour=nendhour;
if(endminutes<10)iendminutes="0"+endminutes;
if(endminutes>9)iendminutes=endminutes;
tend=StrToTime(iendhour+":"+iendminutes);
}
if(fridayfilter){
nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24;
if(nfridayhour<10)ifridayhour="0"+nfridayhour;
if(nfridayhour>9)ifridayhour=nfridayhour;
if(fridayminutes<10)ifridayminutes="0"+fridayminutes;
if(fridayminutes>9)ifridayminutes=fridayminutes;
tfriday=StrToTime(ifridayhour+":"+ifridayminutes);
}
if((generalfilter && (nstarthour<nendhour && TimeCurrent()tend) || (nstarthour>nendhour && TimeCurrent()tend))
|| (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday))
{
CloseAll();
Comment("Non-trading Hours All Positions Closed");
return(0);
}and the CloseAll function.
[CODE]
void CloseAll(){
int total = OrdersTotal();
for(int i=total-1;i>=0;i--){
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type){
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Lime); break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, LightGreen );
} if(result == false){
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
return(0);
}
谢谢你的提示和建议,Kalenzo
停止损失
日子
我一直在尝试一个实验,根据每笔交易的tickvalue、最大dd和百分比来计算SL。
double lotSize = NormalizeDouble(Kellylot(),2);
double Pip = Point;
if(Digits==3 || Digits==5) Pip = 10*Point;
double Bal = AccountBalance(); // $1000
double TV = MarketInfo(Symbol(), MODE_TICKVALUE); // $1
double Risk = 2; // 2%
double MaxDD = 10; // 10%
double RiskCapital = Bal*MaxDD/100; // Total Exposure 10% of $1000 = $100
double RPT = Bal*Risk/100; // 2% of $1000 = $20
double stopLoss = NormalizeDouble(RPT/TV*lotSize/Pip,Digits); //$20/1*0.01/10 = 0.02000
double Positions = MathAbs(RiskCapital/RPT); // Maximum 5 positions 100 / 20
我的想法是,根据货币对和货币对的单个tickvalue以及手数,可以设置2%的SL。
我认为这是正确的,但如果可能的话,我希望有人能检查一下。
尊敬的先生
我一直在尝试一个实验,根据每笔交易的tickvalue、最大dd和百分比来计算SL。
double lotSize = NormalizeDouble(Kellylot(),2);
double Pip = Point;
if(Digits==3 || Digits==5) Pip = 10*Point;
double Bal = AccountBalance(); // $1000
double TV = MarketInfo(Symbol(), MODE_TICKVALUE); // $1
double Risk = 2; // 2%
double MaxDD = 10; // 10%
double RiskCapital = Bal*MaxDD/100; // Total Exposure 10% of $1000 = $100
double RPT = Bal*Risk/100; // 2% of $1000 = $20
double stopLoss = NormalizeDouble(RPT/TV*lotSize/Pip,Digits); //$20/1*0.01/10 = 0.02000
double Positions = MathAbs(RiskCapital/RPT); // Maximum 5 positions 100 / 20
我的想法是,根据货币对和货币对的单个tickvalue以及手数,可以设置2%的SL。
我认为这是正确的,但如果可能的话,希望有人能检查一下。干得好,贝诺。
送鱼竿总比送鱼好。我很高兴能通过一些评论来帮助你。
至于止损,这个想法很好,但是也可以尝试以相反的方式来考虑它。
首先设置止损
其次设定交易规模
这样一来,你就可以根据市场情况来调整系统的进入/退出,而且风险不会超过你账户的X%,但退出将取决于系统逻辑而不是风险百分比。
干得好,贝诺。
送鱼竿总比送鱼好。我很高兴能用一些评论来帮助你。
关于止损,这个想法很好,但是也可以尝试用相反的方式来考虑。
首先设置止损
其次设定交易规模
通过这种方式,你将使系统的进入/退出符合市场条件,并且不会从你的账户中冒出超过X%的风险,但退出将取决于系统逻辑而不是风险百分比。你好,Kalenzo
我在模拟和真实账户上得到一个错误的开仓卖出指令:无效的止损,而且没有开仓交易。但在测试器上运行良好,没有错误信息。
欧元兑美元,日线:修改#1在1.43348买入0.01欧元兑美元,止损点:1.43895,止盈点:0.00000 OK
SL相差0.00547点
我已经检查了
mode_freezelevel 0.0000
mode_stoplevel 0.0000
double Bal = AccountFreeMargin();
double TV = MarketInfo(Symbol(), MODE_TICKVALUE);
double Risk = 0.3;
double MaxDD = 10;
double RiskCapital = Bal*MaxDD/100;
double RPT = Bal*Risk/100;
double stopLoss = NormalizeDouble((RPT/TV)*lotSize/pips2dbl,Digits);
double Positions = MathAbs(RiskCapital/RPT);
double SL;
//---- sell conditions
if(sellsig && ttime!=Time[0]){
double bid = NormalizeDouble(Bid, Digits);
SL = NormalizeDouble(Bid + stopLoss * pips2dbl, Digits);
res=OrderSend(symbol,OP_SELL,lotSize,bid,slippage * pips2dbl,SL,0,"Pivot_Sell",SpecificMagic,0,Red);
if( res<0 )
{
Print("Error opening SELL order : ",ErrorDescription(GetLastError()));
Print("Bid=" + DoubleToStr(bid,Digits) + " : SL=" + DoubleToStr(SL,Digits));
res=0;
}
else //now enter in the SL and TP via OrderModify to make compatible with ECN broker
{
if (OrderSelect(res, SELECT_BY_TICKET))
{
if (!OrderModify(res, Bid, SL, 0, 0, Red))
Print("Error modifying order");
}
}
ttime=Time[0];
return;
}
//---- buy conditions
if(buysig && ttime!=Time[0]) {
double ask = NormalizeDouble(Ask, Digits);
SL = NormalizeDouble(Ask - stopLoss * pips2dbl, Digits);
res=OrderSend(symbol,OP_BUY,lotSize,ask,slippage * pips2dbl,SL,0,"Pivot Buy",SpecificMagic,0,Blue);
if( res<0 )
{
Print("Error opening BUY order : ",ErrorDescription(GetLastError()));
Print("Ask=" + DoubleToStr(ask,Digits) + " : SL=" + DoubleToStr(SL,Digits));
res=0;
}
else //now enter in the SL and TP via OrderModify to make compatible with ECN broker
{
if (OrderSelect(res, SELECT_BY_TICKET))
{
if (!OrderModify(res, Ask, SL, 0, 0, Blue))
Print("Error modifying order");
}
}
ttime=Time[0];
return;
}
}我以前从未遇到过这种情况。
欢呼声
贝诺
闩锁/非闩锁功能
是否有办法在mq4中编码一个锁存/解锁功能。 你可以根据一个条件锁住一个位的真值,它将存储这个值直到被另一个条件解锁。
cmfxtrader
再见,Kalenzo
我在模拟和真实账户上得到一个错误的卖出订单:无效的止损,但在测试器上运行良好,没有错误信息。
欧元兑美元,日线:修改#1在1.43348买入0.01欧元兑美元,止损点:1.43895,止盈点:0.00000 OK
SL相差0.00547点
我已经检查了
mode_freezelevel 0.0000
mode_stoplevel 0.0000
double Bal = AccountFreeMargin();
double TV = MarketInfo(Symbol(), MODE_TICKVALUE);
double Risk = 0.3;
double MaxDD = 10;
double RiskCapital = Bal*MaxDD/100;
double RPT = Bal*Risk/100;
double stopLoss = NormalizeDouble((RPT/TV)*lotSize/pips2dbl,Digits);
double Positions = MathAbs(RiskCapital/RPT);
double SL;
//---- sell conditions
if(sellsig && ttime!=Time[0]){
double bid = NormalizeDouble(Bid, Digits);
SL = NormalizeDouble(Bid + stopLoss * pips2dbl, Digits);
res=OrderSend(symbol,OP_SELL,lotSize,bid,slippage * pips2dbl,SL,0,"Pivot_Sell",SpecificMagic,0,Red);
if( res<0 )
{
Print("Error opening SELL order : ",ErrorDescription(GetLastError()));
Print("Bid=" + DoubleToStr(bid,Digits) + " : SL=" + DoubleToStr(SL,Digits));
res=0;
}
else //now enter in the SL and TP via OrderModify to make compatible with ECN broker
{
if (OrderSelect(res, SELECT_BY_TICKET))
{
if (!OrderModify(res, Bid, SL, 0, 0, Red))
Print("Error modifying order");
}
}
ttime=Time[0];
return;
}
//---- buy conditions
if(buysig && ttime!=Time[0]) {
double ask = NormalizeDouble(Ask, Digits);
SL = NormalizeDouble(Ask - stopLoss * pips2dbl, Digits);
res=OrderSend(symbol,OP_BUY,lotSize,ask,slippage * pips2dbl,SL,0,"Pivot Buy",SpecificMagic,0,Blue);
if( res<0 )
{
Print("Error opening BUY order : ",ErrorDescription(GetLastError()));
Print("Ask=" + DoubleToStr(ask,Digits) + " : SL=" + DoubleToStr(SL,Digits));
res=0;
}
else //now enter in the SL and TP via OrderModify to make compatible with ECN broker
{
if (OrderSelect(res, SELECT_BY_TICKET))
{
if (!OrderModify(res, Ask, SL, 0, 0, Blue))
Print("Error modifying order");
}
}
ttime=Time[0];
return;
}
}我以前从未遇到过这种情况。
欢呼声
贝诺可能是你的止损太近了。试着把止损值 乘以10。当你在4位数的经纪商上测试系统,而你在5位数的经纪商上交易时,这是很常见的问题。你也可以在5位数的经纪商上测试,但不要连接到经纪商(在离线模式),然后metatrader会有旧的设置(从4位数)。
首先从这一行开始。
NormalizeDouble(Ask - stopLoss * pips2dbl, Digits)。
打印这个值 => stopLoss*pips2dbl
然后你就会知道止损的真正价值。
如果它是20或10,那么这意味着你需要将它乘以点值。
NormalizeDouble(Ask - (stopLoss * pips2dbl) *Point, Digits);
如果它像0.00009,那么你需要乘以10,因为它应该是0.0009(当然,如果你想设置9个点的止损)。
是否有办法在mq4中编码一个锁存/解锁功能。 你可以根据一个条件锁定一个位,并存储这个值,直到被另一个条件解除锁定。
我不确定我的理解是否正确。你希望打开/关闭EA的特定部分(功能),还是希望通过EA B中的操作来取消EA A的功能?这样或那样,都是可能的。
将货币价值转换成价格(用于利润目标计算)
我想编写一个函数,为一篮子交易的给定利润目标返回一个价格值,但我遇到了困难。我想达到的目标,是在屏幕上画一条简单的水平线,表示利润目标。然而,利润目标是用户可定义的变量,其形式是一个货币值,而不是一个价格值。(例如,目标=100欧元,而不是目标=1.2000)。
到目前为止,我拥有的程序。
(我的账户是欧元!)。
1) 假设我为USDJPY开了几个买入头寸(为了创造一个例子,在随机位置)。
2) 我计算篮子的平均开仓价(比方说1.1500,同样是假设),并显示一条水平线来表明这一点
3) 我有一个设置了盈利目标的变量:比方说目标=100欧元
4) 当篮子利润>=目标时,我可以成功地关闭所有未结头寸。
这中间的步骤是缺失的。我需要一个函数:double targetPrice(){},返回目标价格。绘制水平线不是问题:计算目标价格才是问题。
目标价格=平均开盘价+货币价值-目标(100欧元)。
所以我基本上想知道:我如何将货币价值转换为 点数。这样我就可以把点数加到平均价格上,这样我就有了我的目标价格。请记住,这也必须考虑到我有一个欧元账户,而我正在交易美元兑日元。我想这里面也有隐患吧?
ECN SL不工作
尊敬的客户
我试图建立一个能在ECN上工作的EA,我知道SL和TP必须被放置/修改,我认为设置是正确的,现在订单打开了,但SL没有被放置,extern double StopLoss = 100;任何帮助都是伟大的。
if(buysig && ttime!=Time[0]) {
ticket = OrderSend(Symbol(), OP_BUY, lotSize, MarketInfo(Symbol(), MODE_ASK), 2, 0, 0, "", 12345);
if(ticket > -1){
if (!OrderSelect(ticket, SELECT_BY_TICKET)) {
error_code = GetLastError();
Print("Error: " + ErrorDescription(error_code));
return(-1);
}
Print("order "+ticket+" successfully opened");
//now enter in the SL and TP via OrderModify to make compatible with ECN broker
SL = MarketInfo(Symbol(), MODE_ASK) - (StopLoss * pips2points);
Print("Ask = " + DoubleToStr(Ask,Digits) + " : SL = " + DoubleToStr(SL,Digits));
//round to nearest Tickvalue
SL = DoubleRound(SL, MarketInfo(Symbol(), MODE_TICKSIZE));
Print("SL rounded: " + SL);
if(!OrderModify(ticket, entry_price, SL, 0, Blue)) {
error_code = GetLastError();
Print("Error: " + ErrorDescription(error_code));
return(-1);
}
Print("Stoploss successfully set");
ttime=Time[0];
return(0);
}
}
}
//Tickvalue Rounding
double DoubleRound(double number, double step){
double mod = MathMod(number, step);
if(mod < step/2.0)
step = 0;
double rounded = number - mod + step;
return (rounded);
},,,,,,,,,,,,,.,,,,,,,,,