设为首页 收藏本站 切换语言

【马丁SW无限】马丁SW无限  

| 发表于 2021-12-7 17:35:54 | 显示全部楼层 |复制链接
//+------------------------------------------------------------------+
//|                                                        huobi.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input int 加仓最大单量=22;
input int 回踩次数=3;
input int    一K最大单量=1;
input int    一天最大单量=300;
extern bool 报警开关=true;
extern bool 弹窗报警=true;
extern bool 邮件报警=true;
extern bool 手机推送报警=true;
input int 大于停止时间=24;
input int 小于停止时间=0;


input ENUM_TIMEFRAMES sw运行周期=30;
input int 均线参数=5;
input bool 均线开关=0;
input bool sw开关=1;
input double 首仓=0.01;
input bool sw变色加仓=1;
input double 亏损点数1=150;
input double 仓1=0.02;
input double 亏损点数2=150;
input double 仓2=0.03;
input double 亏损点数3=150;
input double 仓3=0.04;
input double 亏损点数4=150;
input double 仓4=0.05;
input double 亏损点数5=200;
input double 仓5=0.06;
input double 亏损点数6=200;
input double 仓6=0.07;
input double 亏损点数7=200;
input double 仓7=0.08;
input double 亏损点数8=200;
input double 仓8=0.1;
input double 亏损点数9=250;
input double 仓9=0.12;
input double 亏损点数10=250;
input double 仓10=0.14;
input double 亏损点数11=250;
input double 仓11=0.17;
input double 亏损点数12=250;
input double 仓12=0.2;
input double 亏损点数13=300;
input double 仓13=0.3;
input double 亏损点数14=0;
input double 仓14=0;
input double 亏损点数15=0;
input double 仓15=0;
input double 亏损点数16=0;
input double 仓16=0;
input double 亏损点数17=0;
input double 仓17=0;
input double 亏损点数18=0;
input double 仓18=0;
input double 亏损点数19=0;
input double 仓19=0;
input double 亏损点数20=0;
input double 仓20=0;;
input int    止盈点数=500;
input double 止损金额=2000;
input bool 跟踪止盈开关=1;
input double genzong1=300;//跟踪止盈触发点数1
input double genzf1=298;//跟踪保盈点数1
input double genzong2=250;//跟踪止盈触发点数2
input double genzf2=248;//跟踪保盈点数2
input double genzong3=200;//跟踪止盈触发点数3
input double genzf3=198;//跟踪保盈点数3
input double genzong4=180;//跟踪止盈触发点数4
input double genzf4=178;//跟踪保盈点数4
input double genzong5=150;//跟踪止盈触发点数5
input double genzf5=148;//跟踪保盈点数5
input double genzong6=100;//跟踪止盈触发点数6
input double genzf6=98;//跟踪保盈点数6
input double genzong7=60;//跟踪止盈触发点数7
input double genzf7=58;//跟踪保盈点数7
input double genzong8=40;//跟踪止盈触发点数8
input double genzf8=38;//跟踪保盈点数8
input double genzong9=30;//跟踪止盈触发点数9
input double genzf9=28;//跟踪保盈点数9
input double genzong10=20;//跟踪止盈触发点数10
input double genzf10=15;//跟踪保盈点数10
input double genzong11=20;//跟踪止盈触发点数11
input double genzf11=15;//跟踪保盈点数11
input double genzong12=20;//跟踪止盈触发点数12
input double genzf12=15;//跟踪保盈点数12
input double genzong13=10;//跟踪止盈触发点数13
input double genzf13=5;//跟踪保盈点数13
input double genzong14=5;//跟踪止盈触发点数14
input double genzf14=1;//跟踪保盈点数14







extern int           Magic2 = 111901;
bool 多=1;
bool 空=1;
int  开始=0;
int  结束=24;
int 小时1=24,小时2=0;

string Settings_ex = "---- Indicator Settings";
datetime 时间限制=D'2099.09.04';
int 绑定账号=70028150;
int kscs=0;
datetime com7y,com7ay;
datetime com9,com8,com7,com6,com5;
datetime com9a,com8a,com7a,com6a,com5a;
datetime cvm;
int com = 0;
int com1 = 0;//短线,高低平
int com2 = 0;//限制交易次数
int jiange=0;
bool baoj=0;
int jiange1=0;
bool baoj1=0;
int                  TradesSlippage = 50,CloseSlippage=50;
int com1a = 0;//短线,高低平
int com2a = 0;//限制交易次数
int jiangea=0;
bool baoja=0;
int jiange1a=0;
bool baoj1a=0;
double pingcdx=0;
int g1=0;
int g=0;
bool panz=0;
int com9h=0;
int shij1,shij2;
int shij1a,shij2a;
int danliang;
datetime yhg;

int danliang1;
int danliangv;
int danliang1v;

int danliangx;

int danliangx1;
int danliangxv;
int danliangx1v;
int danliangz;

int danliangz1;
int danliangzv;
int danliangz1v;
datetime yhga;
double jizhun1=0;
datetime jim[9];

double ji5zhun1=0;
int zhuangt=0;
double ji5zhun2=0;
double pingcd=0;
bool genz=0;
bool jiack=0;
bool jiacd=0;
bool sell2=0,buy2=0;
int kongci=0,duoci=0;


int OnInit()
  {
//--- create timer
   EventSetTimer(1);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

bool y3=0;

if(yhg!=iTime(NULL,0,1))

         {danliangv=0;danliang1v=0;

         danliangxv=0;danliangx1v=0;
         danliangzv=0;danliangz1v=0;
         yhg=iTime(NULL,0,1);

        }



   if(yhga!=iTime(NULL,1440,1))

         {danliang=0;danliang1=0;
         danliangx=0;danliangx1=0;
         danliangz=0;danliangz1=0;
         yhga=iTime(NULL,1440,1);

        }



   if(DayOfWeek()==1&&TimeHour(TimeLocal())==6&&TimeMinute(TimeLocal())<3)y3=1;   

          if(DayOfWeek()==1&&TimeHour(TimeLocal())<6)y3=1;  



            if(TimeHour(TimeCurrent())>小时1||TimeHour(TimeCurrent())<小时2)y3=1;   


if(y3==0){





int cd1 = -1;
   int cd2 = -1;
      int cd3 = -1;
   int cd4 = -1;
    int cd5 = -1;

      bool hs=IsConnected();
  if(hs==0){Alert("MT4网络故障暂停运行30秒,请检查网络");Sleep(30000);}

  if(hs==1){


      cd3 = CountTrades("sell",Magic2);//已经有卖开单
   cd4 = CountTrades("buy",Magic2);//已经有买开单





  }

  int 运行周期=sw运行周期;



double swd=iCustom(NULL,运行周期,"PZ_SwingTrading",0,1);
double sw1d=iCustom(NULL,运行周期,"PZ_SwingTrading",1,1);

double swdv=iCustom(NULL,运行周期,"PZ_SwingTrading",0,2);
double sw1dv=iCustom(NULL,运行周期,"PZ_SwingTrading",1,2);

//double swdva=iCustom(NULL,运行周期,"PZ_SwingTrading",0,3);
//double sw1dva=iCustom(NULL,运行周期,"PZ_SwingTrading",1,3);




//  kong               duo
if(swd>sw1d&&swdv<sw1dv&&sell2==0){sell2=1;kongci=0;}//转空
//    duo               kong
if(swd<sw1d&&swdv>sw1dv&&buy2==0){buy2=1;duoci=0;}//转多
//  kong               duo



bool duo=0,kong=0;
if(swd>sw1d){buy2=0;kong=1;}//多停
//    duo               kong
if(swd<sw1d){sell2=0;duo=1;}//空停



   if(kong==1)jiacd=0;
   if(duo==1)jiack=0;


double xiagui=MathMin(swd,sw1d);
double shanggui=MathMax(swd,sw1d);
bool sanzhuxiao=0,sanzhuda=0;
bool junxxiao=0,junxda=0;


if(iClose(NULL,运行周期,1)<xiagui&&iClose(NULL,运行周期,2)<xiagui&&iClose(NULL,运行周期,3)<xiagui)sanzhuxiao=1;
if(iClose(NULL,运行周期,1)>shanggui&&iClose(NULL,运行周期,2)>shanggui&&iClose(NULL,运行周期,3)>shanggui)sanzhuda=1;


double junxian=iMA(NULL,运行周期,均线参数,0,MODE_EMA,PRICE_CLOSE,1);
if(junxian<xiagui)junxxiao=1;
if(junxian>shanggui)junxda=1;

if(均线开关==0){junxxiao=1;junxda=1;}


bool kaiduo=0,kaikong=0;
if(sell2==1&&swd>sw1d&&swdv>sw1dv&&sanzhuxiao==1&&Close[0]>xiagui)kaikong=1;//首单控

if(buy2==1&&swd<sw1d&&swdv<sw1dv&&sanzhuda==1&&Close[0]<shanggui)kaiduo=1;









bool shijian=0;
if(TimeHour(Time[0])>=开始&&TimeHour(Time[0])<=结束)shijian=1;

if(shijian==0)danliang=一天最大单量;




if(sw开关==1){





if(多==1&&danliang<一天最大单量&&kaiduo==1&&danliangv<=一K最大单量&&jim[1]!=iTime(NULL,运行周期,1)&&cd4<1&&cd3<1)
{int tik=OrderSend(Symbol(),OP_BUY,首仓,Ask,TradesSlippage,0,0,"sw-buy1",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;
jim[1]=iTime(NULL,运行周期,1);

jiacd=1;
duoci=duoci+1;
}

Print("sw-buy1");
   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy1");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy1",
   Symbol()+" "+PeriodToText()+    "sw-buy1");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy1");
            }


}

if(空==1&&danliang1<一天最大单量&&kaikong==1&&danliang1v<=一K最大单量&&jim[2]!=iTime(NULL,运行周期,1)&&cd3<1&&cd4<1)
{int tik=OrderSend(Symbol(),OP_SELL,首仓,Bid,TradesSlippage,0,0,"sw-sell1",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;
jim[2]=iTime(NULL,运行周期,1);
jiack=1;
kongci=kongci+1;



}
Print("sw-sell1");
   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell1");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell1",
   Symbol()+" "+PeriodToText()+    "sw-sell1");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell1");
            }
}
}




   double 总仓位d=CountTradesv("buy",Magic2);
    double 总仓位k=CountTradesv("sell",Magic2);




double junjiadv=FindLastOrder("buy","Price",Magic2);

double junjiakv=FindLastOrder("sell","Price",Magic2);


   //FindLastOrder(string as_0, string as_8,int Mag)



   if(kong==1)jiacd=0;
   if(duo==1)jiack=0;




   if(sw变色加仓==1){if(多==1)jiacd=1;

                     if(空==1)jiack=1;}



   if(多==1&&danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==1&&Bid<junjiadv-亏损点数1*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓1,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}
   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}

     if(多==1&&danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==2&&Bid<junjiadv-亏损点数2*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓2,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}




     if(多==1&&danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==3&&Bid<junjiadv-亏损点数3*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓3,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}



     if(多==1&&danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==4&&Bid<junjiadv-亏损点数4*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓4,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}



       if(多==1&&danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==5&&Bid<junjiadv-亏损点数5*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓5,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}


         if(多==1&&danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==6&&Bid<junjiadv-亏损点数6*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓6,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}


           if(多==1&&danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==7&&Bid<junjiadv-亏损点数7*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓7,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}


              if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==8&&Bid<junjiadv-亏损点数8*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓8,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==9&&Bid<junjiadv-亏损点数9*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓9,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==10&&Bid<junjiadv-亏损点数10*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓10,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==11&&Bid<junjiadv-亏损点数11*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓11,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==12&&Bid<junjiadv-亏损点数12*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓12,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==13&&Bid<junjiadv-亏损点数13*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓13,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==14&&Bid<junjiadv-亏损点数14*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓14,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==15&&Bid<junjiadv-亏损点数15*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓15,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==16&&Bid<junjiadv-亏损点数16*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓16,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==17&&Bid<junjiadv-亏损点数17*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓17,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==18&&Bid<junjiadv-亏损点数18*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓18,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}


                if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==19&&Bid<junjiadv-亏损点数19*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓19,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
               }


}

                   if(danliang<一天最大单量&&danliangv<=一K最大单量&&cd4==20&&Bid<junjiadv-亏损点数20*Point&&jiacd==1&&cd4<加仓最大单量){
int tik=OrderSend(Symbol(),OP_BUY,仓20,Ask,TradesSlippage,0,0,"sw-buy2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang=danliang+1;
danliangv=danliangv+1;

}   if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-buy2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-buy2",
   Symbol()+" "+PeriodToText()+    "sw-buy2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-buy2");
            }


}





    if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==1&&Bid>junjiakv+亏损点数1*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓1,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


}  if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
      if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==2&&Bid>junjiakv+亏损点数2*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓2,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
         if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==3&&Bid>junjiakv+亏损点数3*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓3,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
            if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==4&&Bid>junjiakv+亏损点数4*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓4,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
               if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==5&&Bid>junjiakv+亏损点数5*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓5,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==6&&Bid>junjiakv+亏损点数6*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓6,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                   if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==7&&Bid>junjiakv+亏损点数7*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓7,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==8&&Bid>junjiakv+亏损点数8*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓8,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==9&&Bid>junjiakv+亏损点数9*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓9,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==10&&Bid>junjiakv+亏损点数10*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓10,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==11&&Bid>junjiakv+亏损点数11*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓11,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==12&&Bid>junjiakv+亏损点数12*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓12,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==13&&Bid>junjiakv+亏损点数13*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓13,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==14&&Bid>junjiakv+亏损点数14*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓14,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==15&&Bid>junjiakv+亏损点数15*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓15,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==16&&Bid>junjiakv+亏损点数16*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓16,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==17&&Bid>junjiakv+亏损点数17*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓17,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==18&&Bid>junjiakv+亏损点数18*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓18,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                  if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==19&&Bid>junjiakv+亏损点数19*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓19,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}
                   if(danliang1<一天最大单量&&danliang1v<=一K最大单量&&cd3==20&&Bid>junjiakv+亏损点数20*Point&&jiack==1&&cd3<加仓最大单量){
    int tik=OrderSend(Symbol(),OP_SELL,仓20,Bid,TradesSlippage,0,0,"sw-sell2",Magic2,0,clrGreen);
Sleep(2000);
if(tik>0){
danliang1=danliang1+1;
danliang1v=danliang1v+1;


} if(报警开关)
   {   
    if(弹窗报警)
   Alert(Symbol()," "+PeriodToText()+    "sw-sell2");
   if(邮件报警)
   SendMail(Symbol()+" "+PeriodToText()+    "sw-sell2",
   Symbol()+" "+PeriodToText()+    "sw-sell2");
   if(手机推送报警)
   SendNotification(Symbol()+" "+PeriodToText()+ "sw-sell2");
            }
}

     }


    double fukuid=CountTradeslirun("buy",Magic2);
   double fukuik=CountTradeslirun("sell",Magic2);


     int cd3 = CountTrades("sell",Magic2);//已经有卖开单
  int cd4 = CountTrades("buy",Magic2);//已经有买开单


double junjiad=AveragePrice("buy",Magic2);

double junjiak=AveragePrice("sell",Magic2);

int yinglidd=0;
int yinglidk=0;
if(Bid-junjiad>0&&junjiad>0)yinglidd=(Bid-junjiad)/Point;
if(Bid<junjiak&&junjiak>0)yinglidk=(junjiak-Bid)/Point;

  if(yinglidd>止盈点数)deleteordermd(Magic2);

  if(yinglidk>止盈点数)deleteordermk(Magic2);

  if(fukuid+fukuik<-止损金额)deleteorderm(Magic2);

  // double fukuid=CountTradeslirun("buy");
  // double fukuik=CountTradeslirun("sell");
  if(跟踪止盈开关==1){

double zhisun=0;

   if(yinglidd>genzong1&&cd4==1){ zhisun=junjiad+genzf1*Point;
  jlllkxiug("buy",zhisun,Magic2); }

    if(yinglidd>genzong2&&cd4==2){ zhisun=junjiad+genzf2*Point;
  jlllkxiug("buy",zhisun,Magic2); }

    if(yinglidd>genzong3&&cd4==3){ zhisun=junjiad+genzf3*Point;
  jlllkxiug("buy",zhisun,Magic2); }
     if(yinglidd>genzong4&&cd4==4){ zhisun=junjiad+genzf4*Point;
  jlllkxiug("buy",zhisun,Magic2); }
       if(yinglidd>genzong5&&cd4==5){ zhisun=junjiad+genzf5*Point;
  jlllkxiug("buy",zhisun,Magic2); }
        if(yinglidd>genzong6&&cd4==6){ zhisun=junjiad+genzf6*Point;
  jlllkxiug("buy",zhisun,Magic2); }
         if(yinglidd>genzong7&&cd4==7){ zhisun=junjiad+genzf7*Point;
  jlllkxiug("buy",zhisun,Magic2); }
          if(yinglidd>genzong8&&cd4==8){ zhisun=junjiad+genzf8*Point;
  jlllkxiug("buy",zhisun,Magic2); }
            if(yinglidd>genzong9&&cd4==9){ zhisun=junjiad+genzf9*Point;
  jlllkxiug("buy",zhisun,Magic2); }
             if(yinglidd>genzong10&&cd4==10){ zhisun=junjiad+genzf10*Point;
  jlllkxiug("buy",zhisun,Magic2); }
              if(yinglidd>genzong11&&cd4==11){ zhisun=junjiad+genzf11*Point;
  jlllkxiug("buy",zhisun,Magic2); }
               if(yinglidd>genzong12&&cd4==12){ zhisun=junjiad+genzf12*Point;
  jlllkxiug("buy",zhisun,Magic2); }
                if(yinglidd>genzong13&&cd4==13){ zhisun=junjiad+genzf13*Point;
  jlllkxiug("buy",zhisun,Magic2); }
      if(yinglidd>genzong14&&cd4>=14){ zhisun=junjiad+genzf14*Point;
  jlllkxiug("buy",zhisun,Magic2); }




   if(yinglidk>genzong1&&cd3==1){zhisun=junjiak-genzf1*Point;
  jlllkxiug("sell",zhisun,Magic2); }
    if(yinglidk>genzong2&&cd3==2){zhisun=junjiak-genzf2*Point;
  jlllkxiug("sell",zhisun,Magic2); }
    if(yinglidk>genzong3&&cd3==3){zhisun=junjiak-genzf3*Point;
  jlllkxiug("sell",zhisun,Magic2); }
     if(yinglidk>genzong4&&cd3==4){zhisun=junjiak-genzf4*Point;
  jlllkxiug("sell",zhisun,Magic2); }
       if(yinglidk>genzong5&&cd3==5){zhisun=junjiak-genzf5*Point;
  jlllkxiug("sell",zhisun,Magic2); }
        if(yinglidk>genzong6&&cd3==6){zhisun=junjiak-genzf6*Point;
  jlllkxiug("sell",zhisun,Magic2); }
         if(yinglidk>genzong7&&cd3==7){zhisun=junjiak-genzf7*Point;
  jlllkxiug("sell",zhisun,Magic2); }
          if(yinglidk>genzong8&&cd3==8){zhisun=junjiak-genzf8*Point;
  jlllkxiug("sell",zhisun,Magic2); }
           if(yinglidk>genzong9&&cd3==9){zhisun=junjiak-genzf9*Point;
  jlllkxiug("sell",zhisun,Magic2); }
            if(yinglidk>genzong10&&cd3==10){zhisun=junjiak-genzf10*Point;
  jlllkxiug("sell",zhisun,Magic2); }
             if(yinglidk>genzong11&&cd3==11){zhisun=junjiak-genzf11*Point;
  jlllkxiug("sell",zhisun,Magic2); }
              if(yinglidk>genzong12&&cd3==12){zhisun=junjiak-genzf12*Point;
  jlllkxiug("sell",zhisun,Magic2); }
               if(yinglidk>genzong13&&cd3==13){zhisun=junjiak-genzf13*Point;
  jlllkxiug("sell",zhisun,Magic2); }
      if(yinglidk>genzong14&&cd3>=14){zhisun=junjiak-genzf14*Point;
  jlllkxiug("sell",zhisun,Magic2); }


   }








  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---

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


double AveragePrice(string as_0,int mic){      //返回现有买单平均价格,或者卖单平均价格
   double ld_8 = 0;
   double ld_16 = 0;
   for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) {
      OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || (OrderMagicNumber() != mic)) continue;
      if (OrderSymbol() == Symbol() && (OrderMagicNumber() == mic)) {
         if (as_0 == "buy") {
            if (OrderType() == OP_BUY) {
               ld_8 += OrderOpenPrice() * OrderLots();
               ld_16 += OrderLots();
            }
         }
         if (as_0 == "sell") {
            if (OrderType() == OP_SELL) {
               ld_8 += OrderOpenPrice() * OrderLots();
               ld_16 += OrderLots();
            }
         }
      }
   }
  if(ld_16>0) ld_8 = NormalizeDouble(ld_8 / ld_16, Digits);
   return (ld_8);
}




double CountTradesv(string as_0,int mic){
   double l_count_8 = 0;
   for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) {
      OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || (OrderMagicNumber() != mic)) continue;
      if (OrderSymbol() == Symbol() && (OrderMagicNumber() == mic)) {
         if (as_0 == "buy")
            if (OrderType() == OP_BUY) l_count_8=l_count_8+OrderLots();
         if (as_0 == "sell")
            if (OrderType() == OP_SELL) l_count_8=l_count_8+OrderLots();
      }
   }
   return (l_count_8);
}     



double CountTradeslirun(string as_0,int mic){
   double l_count_8 = 0;
   for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) {
      OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || (OrderMagicNumber() != mic)) continue;
      if (OrderSymbol() == Symbol() && (OrderMagicNumber() == mic)) {
         if (as_0 == "buy")
            if (OrderType() == OP_BUY) l_count_8=l_count_8+OrderProfit();
         if (as_0 == "sell")
            if (OrderType() == OP_SELL) l_count_8=l_count_8+OrderProfit();
      }
   }
   return (l_count_8);
}     



void deleteorderm(int magi)//平仓,本编号本货币的所有订单,一个TICK平所有
{
datetime time=TimeCurrent();
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
         if(OrderOpenTime()<time){
           if(OrderSymbol()==Symbol() && OrderMagicNumber()==magi)
               if(OrderType()>=2)
               {
                  OrderDelete(OrderTicket());
                  i=OrdersTotal();
               }
               else
               {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0);
                  i=OrdersTotal();
               }
            }
         }
      }
   }



double FindLastOrder(string as_0, string as_8,int Mag) {//返回最近最新开仓的价格或者仓位,多单空单可选
   double l_ord_open_price_16=0;
   double l_ord_lots_24=0;
   int l_ticket_32 = 0;
   for (int l_pos_36 = OrdersTotal() - 1; l_pos_36 >= 0; l_pos_36--) {
      OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Mag) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Mag) {
         if (as_0 == "buy") {
            if (OrderType() == OP_BUY) {
               if (OrderTicket() > l_ticket_32) {
                  l_ord_open_price_16 = OrderOpenPrice();
                  l_ord_lots_24 = OrderLots();
                  l_ticket_32 = OrderTicket();
               }
            }
         }
         if (as_0 == "sell") {
            if (OrderType() == OP_SELL) {
               if (OrderTicket() > l_ticket_32) {
                  l_ord_open_price_16 = OrderOpenPrice();
                  l_ord_lots_24 = OrderLots();
                  l_ticket_32 = OrderTicket();
               }
            }
         }
      }
   }
   if (as_8 == "Price") return (l_ord_open_price_16);
   if (as_8 == "Lots") return (l_ord_lots_24);
   return (0.0);
}


  int CountTrades(string as_0,int Magic) {//返回现有本货币本订单编号买单总数,或者卖单总数
   int l_count_8 = 0;
   for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) {
      OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
      //if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
         if (as_0 == "buy")
            if (OrderType() == OP_BUY) l_count_8++;
         if (as_0 == "sell")
            if (OrderType() == OP_SELL) l_count_8++;
      }
   }
   return (l_count_8);
}




void deleteordermd(int magi)//平仓,本编号本货币的所有订单,一个TICK平所有
{
datetime time=TimeCurrent();
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
         if(OrderOpenTime()<time){
           if(OrderSymbol()==Symbol() && OrderMagicNumber()==magi&&OrderType()==0)
               if(OrderType()>=2)
               {
                  OrderDelete(OrderTicket());
                  i=OrdersTotal();
               }
               else
               {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0);
                  i=OrdersTotal();
               }
            }
         }
      }
   }



void deleteordermk(int magi)//平仓,本编号本货币的所有订单,一个TICK平所有
{
datetime time=TimeCurrent();
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
         if(OrderOpenTime()<time){
           if(OrderSymbol()==Symbol() && OrderMagicNumber()==magi&&OrderType()==1)
               if(OrderType()>=2)
               {
                  OrderDelete(OrderTicket());
                  i=OrdersTotal();
               }
               else
               {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0);
                  i=OrdersTotal();
               }
            }
         }
      }
   }





string PeriodToText()
{
   switch (Period())
   {
      case 1:
            return("M1");
            break;
      case 5:
            return("M5");
            break;
      case 15:
            return("M15");
            break;
      case 30:
            return("M30");
            break;
      case 60:
            return("H1");
            break;
      case 240:
            return("H4");
            break;
      case 1440:
            return("D1");
            break;
      case 10080:
            return("W1");
            break;
      case 43200:
            return("MN1");
            break;
   }
   return "NULL";
}



void jlllkxiug(string as_0,double zhis,int Magic1) {//每张单子修改止损
  // double l_price_8;
   //double l_price_16 = AveragePrice(as_0);
   for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) {
      OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || (OrderMagicNumber() != Magic1)) continue;
      if (OrderSymbol() == Symbol() && (OrderMagicNumber() == Magic1)) {
         if (as_0 == "buy") {
            if (OrderType() == OP_BUY) {
             //  l_price_8 = l_price_16 + 止损点数 * Point;//止盈价格
               if (OrderStopLoss() != zhis) {
                  //Print("多平均价格 " + DoubleToStr(l_price_16, 4) + "利润空间 = " + Profit + " 多止盈位= " + DoubleToStr(l_price_8, 4));
                  OrderModify(OrderTicket(), OrderOpenPrice(), zhis, OrderTakeProfit(), 0, clrLightSkyBlue);
               }
            }
         }
         if (as_0 == "sell") {
            if (OrderType() == OP_SELL) {
            //   l_price_8 = l_price_16  - 止损点数 * Point;//止盈价格
               if (OrderStopLoss() != zhis) {
                 // Print("空平均价格 " + DoubleToStr(l_price_16, 4) + "利润空间 = " + Profit + " 空止盈= " + DoubleToStr(l_price_8, 4));
                  OrderModify(OrderTicket(), OrderOpenPrice(), zhis, OrderTakeProfit(), 0, clrLightSkyBlue);
               }
            }
         }
      }
   }
}
1638869620(1).png
举报

评论 使用道具

精彩评论14

nikelwong
DDD
| 发表于 2021-12-10 11:42:00 | 显示全部楼层
您可以把源码上载给人下载吗?这样怎么试呢?
举报

点赞 评论 使用道具

天天格外
DDD
| 发表于 2021-12-15 14:51:34 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

dt888
D
| 发表于 2021-12-15 14:55:29 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

win5286
DDD
| 发表于 2022-1-18 18:34:12 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

交易者
DDD
| 发表于 2022-1-18 19:09:21 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

小朋友你要去哪
DDD
| 发表于 2022-1-18 19:35:06 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

翠翠6666
DD
| 发表于 2022-1-20 10:23:59 来自手机 | 显示全部楼层
多谢
举报

点赞 评论 使用道具

Mike
D
| 发表于 2022-1-20 10:27:34 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

纠结的马小东
DD
| 发表于 2022-1-20 11:38:16 | 显示全部楼层
满满的干货,积分都省了,楼主良心。
举报

点赞 评论 使用道具

wangddtt
CC
| 发表于 2022-1-20 15:11:08 | 显示全部楼层
支持这种模式
举报

点赞 评论 使用道具

erixx9
CC
| 发表于 2022-1-20 17:26:38 | 显示全部楼层
复制贴上舒服
举报

点赞 评论 使用道具

www1110111
DD
| 发表于 2022-1-20 23:59:38 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

byqcom
未及格
| 发表于 2024-4-10 16:20:58 | 显示全部楼层
支持一下下    有时间测测
举报

点赞 评论 使用道具

875858098
D
| 发表于 2024-4-11 09:48:08 | 显示全部楼层
支持这种模式感谢分享
举报

点赞 评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)