【macd】最原始的就是最好的  

899 25
| 发表于 2023-1-26 12:10:22 | 只看该作者 |复制链接
© 本贴为 ruzhu 原创/首发,严禁抄袭!

input double TakeProfit    =50;
input double Lots          =0.1;
input double TrailingStop  =30;
input double MACDOpenLevel =3;
input double MACDCloseLevel=2;
input int    MATrendPeriod =26;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick(void)
  {
   double MacdCurrent,MacdPrevious;
   double SignalCurrent,SignalPrevious;
   double MaCurrent,MaPrevious;
   int    cnt,ticket,total;
//---
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
//---
   if(Bars<100)
     {
      Print("bars less than 100");
      return;
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return;
     }
//--- to simplify the coding and speed up access data are put into internal variables
   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
   MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);

   total=OrdersTotal();
   if(total<1)
     {
      //--- no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ",AccountFreeMargin());
         return;
        }
      //--- check for long position (BUY) possibility
      if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("BUY order opened : ",OrderOpenPrice());
           }
         else
            Print("Error opening BUY order : ",GetLastError());
         return;
        }
      //--- check for short position (SELL) possibility
      if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
         MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious)
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("SELL order opened : ",OrderOpenPrice());
           }
         else
            Print("Error opening SELL order : ",GetLastError());
        }
      //--- exit from the "no opened orders" block
      return;
     }
//--- it is important to enter the market correctly, but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   // check for opened position
         OrderSymbol()==Symbol())  // check for symbol
        {
         //--- long position is opened
         if(OrderType()==OP_BUY)
           {
            //--- should it be closed?
            if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
               MacdCurrent>(MACDCloseLevel*Point))
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
            //--- check for trailing stop
            if(TrailingStop>0)
              {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
                        Print("OrderModify error ",GetLastError());
                     return;
                    }
                 }
              }
           }
         else // go to short position
           {
            //--- should it be closed?
            if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
               MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*Point))
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
            //--- check for trailing stop
            if(TrailingStop>0)
              {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
                        Print("OrderModify error ",GetLastError());
                     return;
                    }
                 }
              }
           }
        }
     }
//---
  }
//+------------------------------------------------------------------+


【macd】最原始的就是最好的 - EAHub外汇EA智能交易社区
【macd】最原始的就是最好的 - EAHub外汇EA智能交易社区
【macd】最原始的就是最好的 - EAHub外汇EA智能交易社区
【macd】最原始的就是最好的 - EAHub外汇EA智能交易社区

MACD.ex4

10.95 KB, 下载次数: 0, 下载积分: 活跃度 -5 售价: 30 H币  [记录]  [购买]

MACD.mq4

3.42 KB, 下载次数: 0, 下载积分: 活跃度 -5 售价: 30 H币  [记录]  [购买]

评分
  • 1
  • 2
  • 3
  • 4
  • 5
平均分:NAN    参与人数:0    我的评分:未评
举报

收藏 0 点赞 0 评论 使用道具

精彩评论25

跳转到指定楼层
欧啦啦
未及格
2#
| 发表于 2023-1-26 12:26:37 | 只看该作者
你这事做的太不地道,这不是mt4自带的演示ea吗,你还卖这么贵,心真够黑的
举报

点赞 评论 使用道具

mcx
DDD
3#
| 发表于 2023-1-26 14:19:01 | 只看该作者
新年快乐谢谢分享
举报

点赞 评论 使用道具

bg4abm
C
4#
| 发表于 2023-1-26 15:02:37 | 只看该作者
这么贵,谁会买?
举报

点赞 评论 使用道具

nikelwong
DDD
5#
| 发表于 2023-1-26 15:06:38 | 只看该作者
最原始,最贵,买买买。。。我看就好。
举报

点赞 评论 使用道具

daerbushen
DD
6#
| 发表于 2023-1-26 15:20:28 | 只看该作者
疯了吧,这不是MT4自带的例程么
举报

点赞 评论 使用道具

财富中心
未及格
7#
| 发表于 2023-1-26 16:09:09 | 只看该作者
发力哟坪
举报

点赞 评论 使用道具

yang
DD
8#
| 发表于 2023-1-26 16:25:03 来自手机 | 只看该作者
得,这里又疯了一个
举报

点赞 评论 使用道具

pandaco
DD
9#
| 发表于 2023-1-26 18:52:44 | 只看该作者
金叉死叉,开单开单
举报

点赞 评论 使用道具

彩虹桥
DDD
10#
| 发表于 2023-1-26 19:28:40 | 只看该作者
一笑而过
举报

点赞 评论 使用道具

liguangxing2007
DDD
11#
| 发表于 2023-1-26 20:54:54 | 只看该作者
再好,我也用不来
举报

点赞 评论 使用道具

甘草糖
DD
12#
| 发表于 2023-1-26 21:37:08 | 只看该作者
太贵了,这是新年玩笑么?
举报

点赞 评论 使用道具

373965006
DD
13#
| 发表于 2023-1-27 02:41:13 | 只看该作者
代码是指标的对吧
举报

点赞 评论 使用道具

ken138888
C
14#
| 发表于 2023-1-27 07:18:57 | 只看该作者
评论区很精彩
举报

点赞 评论 使用道具

yang0906
DDD
15#
| 发表于 2023-1-27 09:10:34 | 只看该作者
看看就行
举报

点赞 评论 使用道具

ea12213
C
16#
| 发表于 2023-1-27 10:17:30 | 只看该作者
空手套白狼
举报

点赞 评论 使用道具

simonqian
DD
17#
| 发表于 2023-1-27 18:34:18 | 只看该作者
笑死了,拿示例出来卖
举报

点赞 评论 使用道具

cpchoiaa
DD
18#
| 发表于 2023-1-27 22:23:50 | 只看该作者
又疯了一个人......
举报

点赞 评论 使用道具

kimari254
D
19#
| 发表于 2023-1-28 07:20:55 | 只看该作者
lol funny 30 coins  wow  to  expensive
举报

点赞 评论 使用道具

thuantrinh
DDD
20#
| 发表于 2023-1-28 14:39:41 | 只看该作者
Holy sh"t :)) 30 coin
举报

点赞 评论 使用道具

12下一页
发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册