bollea

    xiaoxiao2021-04-16  38

    //+------------------------------------------------------------------+ //|                                布林战法.mq4 | //|                        Copyright 2016, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, MetaQuotes Software Corp." #property link      "https://www.mql5.com" #property version   "1.00" #property strict extern double lots=0.1; extern int sln=100;//止损点数,非价位哦! extern int tpn=500;// int magic_b=12345; int magic_s=54321;

     

    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; double glbOrderTime; //+------------------------------------------------------------------+ //| Expert initialization function                                   | //+------------------------------------------------------------------+ int OnInit()   {

        //---    return(INIT_SUCCEEDED);   } //+------------------------------------------------------------------+ //| Expert deinitialization function                                 | //+------------------------------------------------------------------+ void OnDeinit(const int reason)   { //---     } //+------------------------------------------------------------------+ //| Expert tick function                                             | //+------------------------------------------------------------------+ void OnTick()   { //---

     //---        //  iBands()  //  iBars()   double a=iClose(NULL,0,0);   double b=iOpen(NULL,0,0);   double c=a-b;   double h=iHigh(NULL,0,0);   double l=iLow(NULL,0,0);   double t_bar=iTime(NULL,0,0); //  Print("收价:",a,"开价:",b,"收-开:",c);       double a1=iClose(NULL,0,1);   double b1=iOpen(NULL,0,1);   double h1=iHigh(NULL,0,1);   double l1=iLow(NULL,0,1);    double c1=a1-b1; //  Print("Bar1收价:",a1,"Bar1开价:",b1,"Bar1收-开:",c1);

      double a2=iClose(NULL,0,2);   double b2=iOpen(NULL,0,2);   double h2=iHigh(NULL,0,2);   double l2=iLow(NULL,0,2);   double c2=a1-b1; //  Print("Bar2收价:",a2,"Bar2开价:",b2,"Bar2收-开:",c2);       double bh=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);   double bm=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,0);   double bl=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0); //  Print("BOLL上轨价:",bh,"BOLL中轨价:",bm,"BOLL下轨价:",bl);      double bh1=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1);   double bm1=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,1);   double bl1=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,1); //  Print("BOLL1上轨价:",bh1,"BOLL1中轨价:",bm1,"BOLL1下轨价:",bl1);     double bh2=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,2);   double bm2=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,2);   double bl2=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,2); //  Print("BOLL2上轨价:",bh2,"BOLL1中轨价:",bm2,"BOLL1下轨价:",bl2);     //================================================上轨下单 // Print("dddddddd",t_Order_his(magic_s,magic_b ));   if (OrderFind(magic_s)==false && bh-bl>100*Point&& glbOrderTime!=t_bar &&isNewBar())//无单且上下轨距超50点&& t_Order_his(magic_s,magic_b )!=t_bar     { //         double hh;      if (h1>h2) hh=h1;       else hh=h2;      if ((b2bh2 && a1bm1&&b1>bh1&& a1<(a2-c2*0.4))        {         if (hh          {           double sl=h2+30*Point;//第二根bar的最高价以上3点做为止损位           if(OrderSend(NULL,OP_SELL,lots,Bid,3,sl,NormalizeDouble(Bid-tpn*Point,Digits),NULL,magic_s,0,clrNONE)==false)           Print("error:",GetLastError());          }        }     }       //------------------------卖单阶段止损(保平)      if (OrderFind(magic_s)==true)    {      Print("glbt:",glbOrderTime,"t_bar:",t_bar);           if( l<(bm+50*Point) && glbOrderStopLoss>glbOrderOpenPrice)         OrderModify(glbOrderTicket,glbOrderOpenPrice,glbOrderOpenPrice,bm,0,clrNONE);     //------------------------卖单阶段止损(目标1止损)    if (OrderFind(magic_s)==true && l<(bm-5*Point)&&NormalizeDouble(glbOrderStopLoss,Digits-1)>NormalizeDouble(bm,Digits-1))         OrderModify(glbOrderTicket,glbOrderOpenPrice,bm,bl,0,clrNONE);     //============================================下轨多单        }                

     

        } //+------------------------------------------------------------------+

      //+------------------------------------------------------------------+ 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();            glbOrderTime=OrderOpenTime();            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);   } //------------------orderfind()----over-------------------------------+      //===================最是否新Bar bool isNewBar() { static datetime TimeBar=0; bool flag=false; if(TimeBar!=Time[0]) { TimeBar=Time[0]; flag=true; } return (flag); }

    转载请注明原文地址: https://ju.6miu.com/read-672402.html

    最新回复(0)