有您的持续关注
我们会做得更好

Carry EA



Carry EA程序极其简洁。单一在执行挂buylimit多单。如果上涨趋势存在,则会不断的盈利出场。面临要解决的问题如果上涨趋势结束如何截断亏损。又或者当前下跌趋势存在又如何改变交易方向?

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。Carry EA源码:

//+------------------------------------------------------------------+
//|                                                        Carry.mq4 |
//+------------------------------------------------------------------+

#property copyright "Luis Dosal"
#property link      "http://www.125808047.com/"

//---- input parameters
extern double    TakeProfit             = 100;
extern int       Trades                 = 1;
extern double    AccountBegBalance      = 5592;
extern double    AccountBegBalanceMonth = 7451.62;
extern double    LotSizer               = 2500;
int              EnableClose            = 0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   Comment("www.125808047.com");
//----
   return(0);
  }


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 

int ticket, total;
   
   double   Equity, Profit, ProfitM, Profit_Trade, Profit_Limit, Lots;
   datetime Expiration;
   string   sComment   = "";
   string   sp         = "-------------------------------------------------------------------\n";
   string   NL         = "\n";
   
   total         = OrdersTotal(); 
   Equity        = AccountEquity();
   Lots          = MathRound(Equity / LotSizer);
   Profit_Limit  = Lots * TakeProfit;
   Profit_Trade  = AccountProfit();
   Expiration    = iTime(NULL,0,0) + 15000;
   
   if (total == 0) {
   EnableClose=0; // Before Debug: EnableClose=1 
   }
   if (Profit_Trade > Profit_Limit) {
    EnableClose=1;
   }    

   Profit        = Equity - AccountBegBalance;
   ProfitM       = Equity - AccountBegBalanceMonth;
  
   if(Bars < 100)
     {
      Print("bars less than 100");
      return(0);  
     }
     
   sComment = sp;
   sComment = sComment + "Equity IRR          : " + (Profit / AccountBegBalance)*100 + " %"+ NL;
   sComment = sComment + "Equity IRR          : " + (ProfitM / AccountBegBalanceMonth)*100 + " % month"+ NL;   
   sComment = sComment + "Limit Orders         : " + Trades + NL;
   sComment = sComment + "Lots                    : " + Lots/10 + NL;
   sComment = sComment + "Enable Close       : " + EnableClose + NL;
   sComment = sComment + sp;

   Comment(sComment);
   
   if (total < Trades)

     {
       ticket=OrderSend(Symbol(),OP_BUYLIMIT,Lots/10,Ask-TakeProfit*Point,3,0,Ask,"Carry",12345,Expiration,Green);
       return(0);
     }

CloseAll();
   return(0); 
}
   
void CloseAll () {   // #function of CloseAll
if (EnableClose==1) {  // #if Close is yes
int _total=OrdersTotal(); // number of lots or trades  ????
int _ordertype;// order type   
if (_total==0) {return;}  // if total==0
int _ticket; // ticket number
double _priceClose;// price to close orders;
for(int _i=_total-1;_i>=0;_i--)
      {  //# for loop
      if (OrderSelect(_i,SELECT_BY_POS))
         { //# if 
         _ordertype=OrderType();
         _ticket=OrderTicket();
         switch(_ordertype)
            {  //# switch
            case 0:
               // close buy                
               _priceClose=MarketInfo(OrderSymbol(),MODE_BID);
              
               bool cg = OrderClose(_ticket,OrderLots(),_priceClose,3,Red);
               break;
            case 1:
               // close sell
               _priceClose=MarketInfo(OrderSymbol(),MODE_ASK);
               
               cg = OrderClose(_ticket,OrderLots(),_priceClose,3,Red);
               break;
            default:
               // values from  1 to 5, deleting pending orders
//               Print("Delete on ",_i," position order with ticket ?,_ticket);
//               OrderDelete(_ticket);  
               break;
            }    //# switch
         }  // # if 
}  // # for loop

} // #if Close yes

return;
} // #function of CloseAll
   
//+------------------------------------------------------------------+

如您喜欢此文章请点下面分享按钮↴峰汇在线 » Carry EA
上一篇:
下一篇:
分享到:更多 ()