qq570214485 发表于 2019-1-31 10:24:20

突破EA(沙漠之鹰)新版本横空出世

dkzhrwb 发表于 2019-2-21 16:04:43

空出世,让您的交易更加

awei3028 发表于 2019-3-29 23:03:45

新版本横空出世,让您的交易更加如虎添翼

ml1599941 发表于 2019-3-29 23:40:26

#property copyright "谁懂易经 www.shuidongyijing.cn Q614771879"
#property link      "http://www.shuidongyijing.cn"

#include <stdlib.mqh>
#include <stderror.mqh>

#define MAGICMA614771879


extern double    优化指数 = 3;
extern int       ATR周期=4;
extern int       周期波段 = 20;
extern double    追踪价格 = 30;
extern bool      反馈=true; //
extern double    Lots=0.1;
extern bool      autolots = true;
extern double    按比例仓位 = 0.02;


   double Atr;
   double Resist;
   double ResistPrev;
   double Support;
   double SupportPrev;
   double Pivot;


int CalculateCurrentOrders(string symbol)
{
   int buys=0;
   int sells=0;

   for(int i=0;i<OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
      {
         if(OrderType()==OP_BUY)
            buys++;
         if(OrderType()==OP_SELL)
         sells++;
      }
   }

      if(buys>0)
         return(buys);
      else
      return(-sells);
}

double LotsOptimized()
{
   double lot=Lots;
   if (autolots == true)
    {
        int    orders=HistoryTotal();   
        int    losses=0;                  

           lot=NormalizeDouble(AccountFreeMargin()*按比例仓位/1000.0,1);

           if(优化指数>0)
           {
              for(int i=orders-1;i>=0;i--)
                      {
                         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
                         {
                         Print("Error on History!");
                         break;
                        }
                         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL)
                         continue;
                 //----
                         if(OrderProfit()>0) break;
                         if(OrderProfit()<0) losses++;
                      }
              if(losses>1) lot=NormalizeDouble(lot-lot*losses/优化指数,1);
           }
   }

   if(lot<0.1) lot=0.1;
   return(lot);
}

void defPcChannel()
{
   Resist=High; // up channel   
   ResistPrev=High;   
   Support=Low;
   SupportPrev=Low;
   Pivot = (Resist+Support+Close)/3;
}

bool isOpenBuy()
{
      
   defPcChannel() ;   
   
   if ( High >= Resist && Resist == ResistPrev)
      return (true);
      
   if ( Close < Resist && Resist == ResistPrev && Close > Pivot)
       return(true);

      return(false);

}

bool isOpenSell()
{
      defPcChannel();

      if (Low <= Support && Support==SupportPrev )
         return (true);

      if (Close > Support && Support==SupportPrev && Close < Pivot )
         return (true);

      return (false);
}

void CheckForOpen()
{

   int    res;
   string sHeaderLetter;
   string sBodyLetter;

   if(Volume>1)
   return;

   Atr = iATR(NULL,0,ATR周期,1);

   
   if (isOpenBuy() == True)
      {   
      res=OrderSend(Symbol(),OP_SELL, LotsOptimized(),Bid,3, Resist+Atr,0,"",MAGICMA,0,Red);
       if (反馈 == True && res != -1)
         {
         sHeaderLetter = "Operation SELL by " + Symbol()+"";
         sBodyLetter = "Order Sell by "+ Symbol() + " at " + DoubleToStr(Bid,4)+ ", and set stop/loss at " + DoubleToStr(Resist+Atr,4)+"";
         sndMessage(sHeaderLetter, sBodyLetter);
         }
      
      return;
   }
//---- is Buy?
      
         
      if (isOpenSell() == true)
      {
         res=OrderSend(Symbol(),OP_BUY, LotsOptimized() ,Ask,3,Support-Atr,0,"order",MAGICMA,0,Blue);
         if ( 反馈 == True && res != -1)
            {
            sHeaderLetter = "Operation BUY at " + Symbol()+"";
            sBodyLetter = "Order Buy at "+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and set stop/loss at " + DoubleToStr(Support-Atr,4)+"";
            sndMessage(sHeaderLetter, sBodyLetter);
            }
      return;
      }
    return;   
}


bool isCloseSell()
{
   defPcChannel();
   if (Low <= Support && Support==SupportPrev )
      return (true);
   return (false);
}

bool isCloseBuy()
{
   defPcChannel();
   
   if ( High >= Resist && Resist == ResistPrev)
      return (true);
      
   
   
   return (false);
}

void CheckForClose()
{
   string sHeaderLetter;
   string sBodyLetter;
   bool CloseOrd;

   if(Volume>1) return;

   

   for(int i=0;i<OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
      break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol())
      continue;
      

      if(OrderType()==OP_BUY)
      {
         if (isCloseBuy() == true )      
         {
          CloseOrd=OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);
            if ( 反馈 == True && CloseOrd == True)
            {
            sHeaderLetter = "Operation CLOSE BUY at" + Symbol()+"";
            sBodyLetter = "Close order Buy at "+ Symbol() + " for " + DoubleToStr(Bid,4)+ ", and finish this Trade";
            sndMessage(sHeaderLetter, sBodyLetter);
            }
         break;
         }                                          
         else
         {

         if(追踪价格>0)
            {               
            if(Bid-OrderOpenPrice()>Point*追踪价格)
               {
               if(OrderStopLoss()<Bid-Point*追踪价格)
                  {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*追踪价格,OrderTakeProfit(),0,Green);
                  return ;
                  }
                }
            }
         
         }
      
      }
      
      if(OrderType()==OP_SELL)
      {
         
         if (isCloseSell() == true)      
         {
         CloseOrd=OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);
            if ( 反馈 == True && CloseOrd == True)
            {
            sHeaderLetter = "Operation CLOSE SELL at" + Symbol()+"";
            sBodyLetter = "Close order Sell at "+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and finish this Trade";
            sndMessage(sHeaderLetter, sBodyLetter);
            }
         break;
         }
         else
         {

         if(追踪价格>0)
            {               
            if((OrderOpenPrice()-Ask)>(Point*追踪价格))
               {
               if((OrderStopLoss()>(Ask+Point*追踪价格)) || (OrderStopLoss()==0))
                  {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*追踪价格,OrderTakeProfit(),0,Red);
                  return;
                  }
               }
             }


         }
      }
   }

}

void sndMessage(string HeaderLetter, string BodyLetter)
{
   int RetVal;
      SendMail( HeaderLetter, BodyLetter );
      RetVal = GetLastError();
      if (RetVal!= ERR_NO_MQLERROR)
      Print ("Error, message not send: ", ErrorDescription(RetVal));
      return;      
}

int start()
{


   if(Bars<25 || IsTradeAllowed()==false)
   return (0);
   if (AccountFreeMargin()<(100*Point*Lots))
   {
   Print("Stop!Our account not enable for trade.Free margin is= ", AccountFreeMargin());
   return(0);
   }


   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();

   return(0);
}

shzq 发表于 2019-3-29 23:42:02

谢谢楼主的分享

jian66 发表于 2019-3-30 00:48:18

学习一下。。。

2357186528 发表于 2019-3-30 08:28:15

哇咔咔   

vbeta 发表于 2019-3-30 08:37:33

666666666666666

alang 发表于 2019-3-30 08:55:18

6666666666666

xuelang 发表于 2019-3-30 21:59:05

好像很厉害的样子
页: 21 22 23 24 25 26 27 28 29 30 [31] 32 33 34 35 36 37 38 39 40
查看完整版本: 突破EA(沙漠之鹰)新版本横空出世,让您的交易更加如虎添翼!