4评论

1收藏

谁懂,不能运行,是什么原因

avatar da.da | 1508 人阅读 | 4 人评论 | 2023-11-10

//+------------------------------------------------------------------+
//|                                                           01.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property  copyright  "MetaQuotes  Ltd."
#property  link       "https://www.mql5.com"
#property  version     "1.00"
#property  strict
//  Input  parameters
input  double  LotSize  =  0.1;
input  int  StopLoss  =  500;
input  int  TakeProfit  =  5000;
int  OnInit()
{
     //---
     return(INIT_SUCCEEDED);
}
void  OnDeinit(const  int  reason)
{
     //---
}
void  OnTick()
{
     double  ma20  =  iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
     double  angle  =  MathArctan((iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0)  -  iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1))  /  1)  *  (180/MathPi);
     if  (angle  >  30  &&  Close[0]  >  ma20  &&  Close[1]  >  ma20  &&  Close[2]  >  ma20)
     {
       if  (OrdersTotal()  ==  0)
       {
           //  Open  long  position
           OrderSend(Symbol(),  OP_BUY,LotSize,Ask,0,Bid  -  StopLoss  *  Point,Bid  +  TakeProfit  *  Point);
       }
     }
     else  if  (angle  <  -30  &&  Close[0]  <  ma20  &&  Close[1]  <  ma20  &&  Close[2]  <  ma20)
     {
       if  (OrdersTotal()  ==  0)
       {
           //  Open  short  position
           OrderSend(Symbol(),  OP_SELL,LotSize,Bid,0,Ask  +  StopLoss  *  Point,Ask  -  TakeProfit  *  Point);
       }
     }
     else  if  (Close[0]  <  ma20  &&  Close[1]  >  ma20)
     {
       //  Close  long  position
       CloseOrder(OP_BUY);
     }
     else  if  (Close[0]  >  ma20  &&  Close[1]  <  ma20)
     {
       //  Close  short  position
       CloseOrder(OP_SELL);
     }
}
void  CloseOrder(int  orderType)
{
     int  total  =  OrdersTotal();
     for  (int  i  =  total  -  1;i  >=  0;i--)
     {
       if  (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
       {
           if  (OrderType()  ==  orderType)
           {
             OrderClose(OrderTicket(),  OrderLots(),  Bid,Slippage);
           }
       }
     }
}

""
还没有人打赏,支持一下

评论|共 4 个

张寒轩

发表于 2023-11-11 09:59:32 | 显示全部楼层


//+------------------------------------------------------------------+
//|                                                           01.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property  copyright  "MetaQuotes  Ltd."
#property  link       "https://www.mql5.com"
#property  version     "1.00"
#property  strict
//  Input  parameters
input  double  LotSize  =  0.1;
input  int  StopLoss  =  500;
input  int  TakeProfit  =  5000;
input int SlipPage=2;// Slippage
input int MathPi=2;// MathPi
int  OnInit()
{
     //---
     return(INIT_SUCCEEDED);
}
void  OnDeinit(const  int  reason)
{
     //---
}
void  OnTick()
{
     double  ma20  =  iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
     double  angle  =  MathArctan((iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0)  -  iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1))  /  1)  *  (180/MathPi);
     if  (angle  >  30  &&  Close[0]  >  ma20  &&  Close[1]  >  ma20  &&  Close[2]  >  ma20)
     {
       if  (OrdersTotal()  ==  0)
       {
           //  Open  long  position
           OrderSend(Symbol(),  OP_BUY,LotSize,Ask,0,Bid  -  StopLoss  *  Point,Bid  +  TakeProfit  *  Point);
       }
     }
     else  if  (angle  <  -30  &&  Close[0]  <  ma20  &&  Close[1]  <  ma20  &&  Close[2]  <  ma20)
     {
       if  (OrdersTotal()  ==  0)
       {
           //  Open  short  position
           OrderSend(Symbol(),  OP_SELL,LotSize,Bid,0,Ask  +  StopLoss  *  Point,Ask  -  TakeProfit  *  Point);
       }
     }
     else  if  (Close[0]  <  ma20  &&  Close[1]  >  ma20)
     {
       //  Close  long  position
       CloseOrder(OP_BUY);
     }
     else  if  (Close[0]  >  ma20  &&  Close[1]  <  ma20)
     {
       //  Close  short  position
       CloseOrder(OP_SELL);
     }
}
void  CloseOrder(int  orderType)
{
     int  total  =  OrdersTotal();
     for  (int  i  =  total  -  1;i  >=  0;i--)
     {
       if  (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
       {
           if  (OrderType()  ==  orderType)
           {
             OrderClose(OrderTicket(),OrderLots(),Bid,SlipPage);
           }
       }
     }
}

张寒轩

发表于 2023-11-11 10:00:20 | 显示全部楼层

问题就是你没有声明slippage和MathPi

山海之巅

发表于 2023-11-12 19:44:04 | 显示全部楼层

张寒轩 发表于 2023-11-11 10:00
问题就是你没有声明slippage和MathPi

大哥 你好厉害

看雾成烟

发表于 2024-7-7 21:52:22 | 显示全部楼层

支持下

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则