MT5外汇期货哪里开户_外汇交易辅助EA(编写)

作者:MT4 发布时间:2021-09-22 15:04

//=============== VARS external
extern int 第一方针点数 = 20;
extern int 第两方针取第一方针间隔 = 20;
extern double 分批仄仓手数 = 0.2;
//=======================================
extern bool 应用挪动行益功用 = true;
extern int 第一次红利点数 = 10;
extern int 第一次移行益间隔启仓价点数 = 0;
extern int 第两次红利点数 = 30;
extern int 第两次移行益间隔启仓价点数 = 10;
//======================================
extern bool 应用最年夜容许吃亏功用 = true;
extern int 最年夜吃亏点数 = 20;
extern int Magic_Number=0;

//=============== VARS internal
int nextTP;
bool sl;
int range = 5;
int multiplier;
// OrderType == 1 is OP_SELL

 


//=============== FUNCTION init
int init()
  {
   sl=0;
   nextTP = 第一方针点数;
   getMaxLoss();
  }
//== end function


//=============== FUNCTION deinit
int deinit()
  {
//----
   sl=0;
   nextTP = 第一方针点数;
//----
   return(0);
  }
//== end function

//========== FUNCTION Start
int start()
  {
//----
   getOpenOrders();
   getSpread();
   //Co妹妹ent(sl);
//----
   return(0);
  }
//== end function

//========== FUNCTION getPipValue
double type_order_profit(double order_openprice,int ordertype)
{
   double val;
   RefreshRates();
   if(ordertype == 1) val=(NormalizeDouble(order_openprice,Digits) - NormalizeDouble(Ask,Digits));
   else val=(NormalizeDouble(Bid,Digits) - NormalizeDouble(order_openprice,Digits));
   val = val/Point;
   return(val);  
}
//== end function

int getSpread()
{
   int spread=MarketInfo(Symbol(),MODE_SPREAD);
   return(spread);
}


int getMaxLoss()
{
   int calcMaxLoss;
   calcMaxLoss = 最年夜吃亏点数;
   return(calcMaxLoss);
}
//========== FUNCTION getOpenOrders
void getOpenOrders()
{
   int nsl, nsd;
   string mngMagic;
   int totalorders = OrdersTotal();
   for(int j=0; j<totalorders;j++)
     { 
         OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
         if((OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderSymbol() == Symbol()&&(Magic_Number==0 || Magic_Number == OrderMagicNumber()))
         {

            double order_profit=type_order_profit(OrderOpenPrice(),OrderType());
            //int val = OrderProfit()/(OrderLots()*10);
            if(应用最年夜容许吃亏功用 && 最年夜吃亏点数 > 0) killTrade(order_profit,OrderTicket());
            if(应用挪动行益功用) checkStops(order_profit,OrderTicket());
            Close_at_Profit(order_profit,OrderTicket());           
           
         }
        
         if(Magic_Number == 0)
         mngMagic = "All "+Symbol()+" trades.";
         else
         mngMagic = "Trades with magic number = "+Magic_Number;
        
        
         if(sl==0)
            {
               nsl = 第一次红利点数;
               nsd = 第一次移行益间隔启仓价点数;
            }
          else
            {
               nsl = 第两次红利点数;
               nsd = 第两次移行益间隔启仓价点数;
            }
         //RefreshRates();
         Co妹妹ent("Order Open: ",OrderOpenPrice(),
         "/nPip Count: ", order_profit,
         "/nNext Stop Target: ",nsl,
         "/nNext Stop Differential: ", nsd,
         "/nNext TP: ", nextTP,
         "/nSL: ",sl,
         "/nMax Loss: ", getMaxLoss(),
         "/nManaging: ",mngMagic);
       &nbs启外汇账户必要哪些材料p;

     } 
}

//========== FUNCTION takeProfit
void Close_at_Profit(int orderprofit, int orderticket)
{
   if(OrderSelect(orderticket, SELECT_BY_TICKET)==true)
   {

      if(orderprofit >= nextTP && orderprofit < (nextTP + 第两方针取第一方针间隔))
      {
         if(OrderType()==1)
         {
            if(OrderClose(orderticket, 分批仄仓手数, Ask, 3, YellowGreen))
            nextTP+=第两方针取第一方针间隔;
            else
            Print("Error closing order : ",GetLastError());
         }
         else
         {
            if(OrderClose(orderticket, 分批仄仓手数, Bid, 3, YellowGreen))
            nextTP+=第两方针取第一方针间隔;
            else
            Print("Error closing order : ",GetLastError());
         }
             
      }

   }
}

//== end function

 

//========== FUNCTION moveStops
void checkStops(int Orderprofit,int ticket)
{
   if(sl==0 && Orderprofit < 第两次红利点数)
   {
      if(Orderprofit >= 第一次红利点数 && Orderprofit < (第两次红利点数))
      {
         moveStops(ticket, 第一次移行益间隔启仓价点数);
      }
   }
   else if(sl==1 || Orderprofit >= 第两次红利点数)
   {
      if(Orderprofit >= 第两次红利点数)
      {
         moveStops(ticket,第两次移行益间隔启仓价点数);
      }
   }


}

//== end function

//========== FUNCTION moveStops
void moveStops(int orderticket,int TrainingStop)
{
   if(OrderSelect(orderticket, SELECT_BY_TICKET)==true)
   {
      Print("moveStops called ",orderticket, " ",TrainingStop);
      if(OrderType()==1)
      {
      OrderModify(orderticket,OrderOpenPrice(),OrderOpenPrice()-TrainingStop*Point, OrderTakeProfit(),0,Plum);
      sl=1;
      }
      else
      {
      OrderModify(orderticket,OrderOpenPrice(),OrderOpenPrice()+TrainingStop*Point, OrderTakeProfit(),0,Plum);
      sl=1;
      }
   }
  

  
}

//== end function

//========== FUNCTION killTrades
void killTrade(int pips, int ticket)
{
   if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
   {
      if(pips <= -1*getMaxLoss())
      {
         if(OrderType()==1) OrderClose(ticket,OrderLots(),Ask,3,Red);    
         else OrderClose(ticket,OrderLots(),Bid,3,Red);
      }     
  外汇开户费; }
}