int start()// Special function 'start'{string Symb=Symbol();// Symboldouble Dist=1000000.0;// Presettingint Real_Order=-1;// No market orders yetdouble Win_Price=WindowPriceOnDropped();// The script is dropped here//-------------------------------------------------------------------------------- 2 --for(int i=1; i<=OrdersTotal(); i++)// Order searching cycle{if(OrderSelect( i-1, SELECT_BY_POS)==true)// If the next is available{// Order analysis://----------------------------------------------------------------------- 3 --if(OrderSymbol()!= Symb)continue;// Symbol is not oursint Tip=OrderType();// Order typeif( Tip>1)continue;// Pending order //----------------------------------------------------------------------- 4 --double Price=OrderOpenPrice();// Order priceif(NormalizeDouble(MathAbs( Price- Win_Price),Digits)<//SelectionNormalizeDouble( Dist,Digits))// of the closest order {
Dist=MathAbs( Price- Win_Price);// New value
Real_Order= Tip;// Market order availableint Ticket=OrderTicket();// Order ticketdouble Lot=OrderLots();// Amount of lots}//----------------------------------------------------------------------- 5 --}//End of order analysis}//End of order searching//-------------------------------------------------------------------------------- 6 --while(true)// Order closing cycle{if( Real_Order==-1)// If no market orders available{Alert("For ", Symb," no market orders available");break;// Exit closing cycle }//-------------------------------------------------------------------------- 7 --switch( Real_Order)// By order type{case0:double Price_Cls=Bid;// Order Buystring Text="Buy ";// Text for Buybreak;// Из switchcase1: Price_Cls=Ask;// Order Sell
Text="Sell ";// Text for Sell}Alert("Attempt to close ", Text," ", Ticket,". Awaiting response..");bool Ans=OrderClose( Ticket, Lot, Price_Cls,2);// Order closing
请检查 "Dist "值
检查?如何检查?我从MQL4的书中复制了代码(有距离变量的部分)。
see also: https://book.mql4.com/trading/orderclose1.确保 "Dist "的初始值是正确的。
2.在周期开始时插入警报以检查 "Dist "的值:"警报(" Dist = ", Dist );"
有什么方法可以在不使用变量 "Dist "的情况下选择正确的顺序吗?
回答1
样本中的符号">"和"<"在同一表达式中的方向不同
见closeorder.mq4 的第22行和前一个样本的第6行
我认为在第二个例子中,这一定是一个错误......你怎么看?
回答2
取决于 "正确的订单 "的含义
我需要选择(并关闭)开盘价较低的订单OP_BUY,而且这种选择必须在有2个订单OP_BUY时开始...OP_SELL也是如此...这有这么难实现吗?我很迷惑...
普通工作
那么我做错了什么呢?您如何选择具有较低openprice的OP_BUY?我甚至试过不使用 "Dist"...
这一行 "if (Price < Price), Digits) "的意图是什么?
对我来说,这看起来很疯狂。
CB
这一行 "if (Price < Price), Digits) "的意图是什么?
对我来说,这看起来很疯狂。
不仅如此。
这句话在编译时怎么可能不出错,因为少了一个左括号。
人类都会犯错
如果(a_human_made_a_mistake=true)
{human_learn_next_lesson();}。
否则
{reincarnate_as_plant=true;}。
{human_learn_next_lesson();}。
如果我们有MT5就好了。那么我们就可以用human->learnNextLesson()来代替。
如果我们有MT5就好了。那么我们就可以用human->learnNextLesson()来代替。
我从来没有熟悉过OOP。
我讨厌这样。
在这种情况下,我拒绝学习...;-)
this->repeat->this->repeat->this->repeat->this->repeat->this->repeat->this->repeat->this。