请教一个关于多单平仓出错的问题,多单在开单价小于开盘价时平仓,总是出错 新评论 erli zhinian 2023.08.30 14:55 void OnTick() { double buyop,buylots; int buydanshu=buydanshu(buyop,buylots); if(buydanshu==0 ) { if( Close[0]>High[1] ) { if(selltime!=Time[0]) { if(buy(Lots,0,0,Symbol()+"buy",magic)>0) { selltime=Time[0]; } } } } if( Open[ 0 ]>buyop) { closebuy(); } } void closebuy() { double buyop,buylots; while(buydanshu(buyop,buylots)>0) { int t=OrdersTotal(); for(int i=t-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==magic) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),300,Green); } } } Sleep(800); } } int buydanshu(double &op,double &lots) { int a=0; op=0; lots=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==magic) { a++; op=OrderOpenPrice(); lots=OrderLots(); } } } return(a); }int buy(double lots,double sl,double tp,string com,int buymagic) { int a=0; bool zhaodan=false; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { string zhushi=OrderComment(); int ma=OrderMagicNumber(); if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && zhushi==com && ma==buymagic) { zhaodan=true; break; } } } if(zhaodan==false) { if(sl!=0 && tp==0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,Ask-sl*Point,0,com,buymagic,0,White); } if(sl==0 && tp!=0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,0,Ask+tp*Point,com,buymagic,0,White); } if(sl==0 && tp==0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,0,0,com,buymagic,0,White); } if(sl!=0 && tp!=0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,Ask-sl*Point,Ask+tp*Point,com,buymagic,0,White); } } return(a); } 新评论 原因: 取消 您错过了交易机会: 免费交易应用程序 免费24小时外汇VPS 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
erli zhinian 2023.08.30 14:55 void OnTick() { double buyop,buylots; int buydanshu=buydanshu(buyop,buylots); if(buydanshu==0 ) { if( Close[0]>High[1] ) { if(selltime!=Time[0]) { if(buy(Lots,0,0,Symbol()+"buy",magic)>0) { selltime=Time[0]; } } } } if( Open[ 0 ]>buyop) { closebuy(); } } void closebuy() { double buyop,buylots; while(buydanshu(buyop,buylots)>0) { int t=OrdersTotal(); for(int i=t-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==magic) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),300,Green); } } } Sleep(800); } } int buydanshu(double &op,double &lots) { int a=0; op=0; lots=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==magic) { a++; op=OrderOpenPrice(); lots=OrderLots(); } } } return(a); }int buy(double lots,double sl,double tp,string com,int buymagic) { int a=0; bool zhaodan=false; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { string zhushi=OrderComment(); int ma=OrderMagicNumber(); if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && zhushi==com && ma==buymagic) { zhaodan=true; break; } } } if(zhaodan==false) { if(sl!=0 && tp==0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,Ask-sl*Point,0,com,buymagic,0,White); } if(sl==0 && tp!=0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,0,Ask+tp*Point,com,buymagic,0,White); } if(sl==0 && tp==0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,0,0,com,buymagic,0,White); } if(sl!=0 && tp!=0) { a=OrderSend(Symbol(),OP_BUY,lots,Ask,50,Ask-sl*Point,Ask+tp*Point,com,buymagic,0,White); } } return(a); }