📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

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

    da.da LV7
    2023-11-10 · 2590 阅读
    //+------------------------------------------------------------------+
    //|                                                           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);
               }
           }
         }
    }

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

    举报

     

    回答|共 6 个

    张寒轩 LV3

    发表于 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);
               }
           }
         }
    }

    张寒轩 LV3

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

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

    山海之巅 LV5

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

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

    大哥 你好厉害

    看雾成烟 LV2

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

    支持下

    过渡到个 LV3

    发表于 2025-4-22 19:01:48 | 显示全部楼层

    顶下
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服