行情EA自建20160921

来源:互联网 发布:哪个网络验证好 编辑:程序博客网 时间:2024/04/30 08:19

//+------------------------------------------------------------------+
//|                                                      soninf.mq4 |
//|                       Copyright 2016, MetaQuotes Software Corp. |
//|                                            https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes SoftwareCorp."
#propertylink     "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initializationfunction                                  |
//+------------------------------------------------------------------+
extern datetime t_info=D'2016.09.21 16:59:00';
extern double lots=0.01;
extern string aaa="-------下单时距下单时订单价格距市价点数------";
extern int vbpoint=50;
extern int vspoint=50;
//sell_stop
extern int vsl=50;
extern int vtp=1000;
extern string bbb="-----追踪止损------";
extern bool istrailsl=true;
extern int trailsl=100;

int magicnum_buy=9123;
int magicnum_sell=9321;

 


int glbOrderType=NULL;
int glbOrderTicket=NULL;
string glbOrderSymbol=NULL;
double glbOrderOpenPrice=NULL;
double glbOrderStopLoss=NULL;
double glbOrderLots=NULL;
double glbOrderTp=NULL;
double glbOrderP=NULL;
double glbOrderPoint=NULL;
double p_sl=0;
double glbOrderDigits=NULL;
double glbMinlot=NULL;

 

 

int OnInit()
  {
//---
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitializationfunction                                |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tickfunction                                            |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
//   TimeLocal()
//   TimeCurrent()


if(OrderFind(magicnum_buy)==false&&OrderFind(magicnum_buy)==false&& TimeLocal()==t_info)
 
 OrderSend(NULL,OP_BUYSTOP,lots,Ask+vbpoint*Point,3,Bid+(vbpoint-vsl)*Point,Bid+(vbpoint+vtp)*Point,NULL,magicnum_buy,0,clrNONE);
 OrderSend(NULL,OP_SELLSTOP,lots,Bid-vspoint*Point,3,Ask-(vspoint-vsl)*Point,Ask-(vspoint+vtp)*Point,NULL,magicnum_sell,0,clrNONE);
  }
 
 
 
 //================================================================买单成交
  if (OrderFind( magicnum_buy)==true &&glbOrderType==0)  //存在买单并且成交--del buy
    {
     if (OrderFind( magicnum_sell)==true  )//del orclose sellorder
       {
       OrderDelete(glbOrderTicket,clrNONE);
       OrderClose(glbOrderTicket,lots,Ask,3,clrNONE);
       }
    }
    //---------------------------------保本、追踪
   if (OrderFind(magicnum_buy)==true && glbOrderType==0) //存在买单并且成交--trail stop 
    {
   
    doubletp_bp=Bid -glbOrderOpenPrice;//盈利点
    if(tp_bp>150*Point&&glbOrderStopLoss
   OrderModify(glbOrderTicket,glbOrderOpenPrice,glbOrderOpenPrice,glbOrderTp,0,clrNONE);//保本
   
   //------trail stoploss
    if(istrailsl=true &&NormalizeDouble(Bid-trailsl*Point,Digits-1)>glbOrderStopLoss)
   OrderModify(glbOrderTicket,glbOrderOpenPrice,NormalizeDouble(Bid-trailsl*Point,Digits),glbOrderTp,0,clrNONE);
    }
   
   
   //===============================================卖单成交  
   //--------------------------------------   
  if (OrderFind( magicnum_sell)==true &&glbOrderType==1)  //存在卖单并且成交
    {
    if (OrderFind( magicnum_buy)==true  )//del orclose sellorder
       {
       OrderDelete(glbOrderTicket,clrNONE);
       OrderClose(glbOrderTicket,lots,Bid,3,clrNONE);
       }
     }
    //---------------------------------保本、追踪
   if (OrderFind(magicnum_sell)==true && glbOrderType==1) //存在卖单并且成交--trail stop 
    {
   
    doubletp_bp=glbOrderOpenPrice-Ask;//盈利点
    if(tp_bp>150*Point&&glbOrderStopLoss>glbOrderOpenPrice)
   OrderModify(glbOrderTicket,glbOrderOpenPrice,glbOrderOpenPrice,glbOrderTp,0,clrNONE);//保本
   
   //------trail stoploss
    if(istrailsl=true &&NormalizeDouble(Ask+trailsl*Point,Digits-1)
   OrderModify(glbOrderTicket,glbOrderOpenPrice,NormalizeDouble(Ask+trailsl*Point,Digits),glbOrderTp,0,clrNONE);
                 
       
       
       
  
  }
//+------------------------------------------------------------------+


//=========================order find
bool OrderFind(int Magic)
  {
   glbOrderType = -1;
   glbOrderTicket = -1;
   int total =OrdersTotal();
   bool res = false;
   for(int cnt = 0 ; cnt <total ; cnt++)
    {
      
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==false)
      Print("ERR(",GetLastError(),")");
      if(OrderMagicNumber() == Magic && OrderSymbol() ==Symbol())
        {
          glbOrderType = OrderType();
          glbOrderSymbol=OrderSymbol();
          glbOrderTicket = OrderTicket();
          glbOrderOpenPrice=OrderOpenPrice();
          glbOrderStopLoss=OrderStopLoss();
          glbOrderLots=OrderLots();
          glbOrderTp=OrderTakeProfit();
          glbOrderP=OrderProfit();
          glbOrderPoint=Point;
          glbOrderDigits=Digits;
          glbMinlot  =MarketInfo(OrderSymbol(),MODE_MINLOT);
          
//          Print(Symbol(),"ggggggggggggggggg",glbMinlot,"点值",glbOrderPoint);
          res = true;
        }
    }
   return(res);
  }

0 0
原创粉丝点击