设为首页 收藏本站 切换语言

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

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


1674706053890.png
1674706053890.png
1674706090289.png
1674706090289.png

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    我的评分:未评 下载时遇到问题?
举报

评论 使用道具

精彩评论28

欧啦啦
未及格
| 发表于 2023-1-26 12:26:37 | 显示全部楼层
你这事做的太不地道,这不是mt4自带的演示ea吗,你还卖这么贵,心真够黑的
举报

点赞 评论 使用道具

mcx
C
| 发表于 2023-1-26 14:19:01 | 显示全部楼层
新年快乐谢谢分享
举报

点赞 评论 使用道具

bg4abm
CC
| 发表于 2023-1-26 15:02:37 | 显示全部楼层
这么贵,谁会买?
举报

点赞 评论 使用道具

nikelwong
DDD
| 发表于 2023-1-26 15:06:38 | 显示全部楼层
最原始,最贵,买买买。。。我看就好。
举报

点赞 评论 使用道具

daerbushen
DD
| 发表于 2023-1-26 15:20:28 | 显示全部楼层
疯了吧,这不是MT4自带的例程么
举报

点赞 评论 使用道具

财富中心
D
| 发表于 2023-1-26 16:09:09 | 显示全部楼层
发力哟坪
举报

点赞 评论 使用道具

yang
DD
| 发表于 2023-1-26 16:25:03 来自手机 | 显示全部楼层
得,这里又疯了一个
举报

点赞 评论 使用道具

pandaco
DDD
| 发表于 2023-1-26 18:52:44 | 显示全部楼层
金叉死叉,开单开单
举报

点赞 评论 使用道具

彩虹桥
DDD
| 发表于 2023-1-26 19:28:40 | 显示全部楼层
一笑而过
举报

点赞 评论 使用道具

liguangxing2007
DDD
| 发表于 2023-1-26 20:54:54 | 显示全部楼层
再好,我也用不来
举报

点赞 评论 使用道具

甘草糖
DD
| 发表于 2023-1-26 21:37:08 | 显示全部楼层
太贵了,这是新年玩笑么?
举报

点赞 评论 使用道具

373965006
DD
| 发表于 2023-1-27 02:41:13 | 显示全部楼层
代码是指标的对吧
举报

点赞 评论 使用道具

ken138888
CCC
| 发表于 2023-1-27 07:18:57 | 显示全部楼层
评论区很精彩
举报

点赞 评论 使用道具

yang0906
DDD
| 发表于 2023-1-27 09:10:34 | 显示全部楼层
看看就行
举报

点赞 评论 使用道具

ea12213
C
| 发表于 2023-1-27 10:17:30 | 显示全部楼层
空手套白狼
举报

点赞 评论 使用道具

simonqian
DD
| 发表于 2023-1-27 18:34:18 | 显示全部楼层
笑死了,拿示例出来卖
举报

点赞 评论 使用道具

cpchoiaa
D
| 发表于 2023-1-27 22:23:50 | 显示全部楼层
又疯了一个人......
举报

点赞 评论 使用道具

kimari254
D
| 发表于 2023-1-28 07:20:55 | 显示全部楼层
lol funny 30 coins  wow  to  expensive
举报

点赞 评论 使用道具

thuantrinh
DDD
| 发表于 2023-1-28 14:39:41 | 显示全部楼层
Holy sh"t :)) 30 coin
举报

点赞 评论 使用道具

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

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)