乐于分享
好东西不私藏

支撑位阻力位EA做单系统源码分享

支撑位阻力位EA做单系统源码分享
HI,大家好
以后还是按照惯例来,每周的三和周六,我们就开始分享指标和EA的源码,毕竟浪哥太多了,还喜欢分享,这就是你们的福利日,今天周三了,所以要分享源码了,今天分享一套支撑位阻力位EA做单系统,我记得前几天我发布了一个指标是关于支撑位和压力位的显示指标:
基于三指标的显示关键点位置的指标EA系统源码分享
然后再配合这套EA做单系统,简直就是绝配啊,界面:
EA配置界面:
不过我要说明一下哈,做单系统只能限制用于模拟盘来学习和交流的哈,不能商业用和实盘。具体的功能和配置我就不详细聊了,这很简单的,当然,如果你还是不会,可以找我拿源码和配置说明:我是为你们操碎了心
下面是源码:复制后有乱码的丢给AI给你排列!
#property copyright "浪人EA"#property link      ""#property version   "1.0"#property strict//+------------------------------------------------------------------+//| Expert initialization function                                   |//+------------------------------------------------------------------+string     注释="浪人EA:waihuipai";input int        Magic=210922;string 开始工作时间="00:00:00";string 结束工作时间="23:59:59";input double 首单手数=0.01;input double 加仓手数1=0.01;input double 加仓手数2=0.01;input bool 移动止损开关=false;//input int    移动止损激活点数=90;input int    移动止损点数=50;input int 超出极限位置多少小点止损=100;int 止损点数=0;int 止盈点数=0;intOnInit()  {//---   return(INIT_SUCCEEDED);  }boolCloseOrder(int type)  {   bool bRet = true;   for(int i=OrdersTotal()-1;i>=0;i--)    {     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))      {       if (OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)       {          if (OrderType()==type)          {           if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),300,clrGreen))            {               Print("close erro:", GetLastError());               bRet = false;            }          }       }      }    }    return bRet;  }boolfindOrderByComm(string comm){   for(int i=OrdersTotal()-1;i>=0;i--)   {      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))      {         if (OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)         {            if (StringFind(OrderComment(),comm)>=0)            {               return true;            }         }      }   }   return false;}boolcheckToOpen(){   int ret;   double bid=MarketInfo(Symbol(),MODE_BID);   double ask=MarketInfo(Symbol(),MODE_ASK);   //支撑1开多   if (!findOrderByComm("支撑1"))   {      if (Low[1]>g_rsPrice[4] && Bid<=g_rsPrice[4])      {         if((ret=OrderSend(Symbol(),OP_BUY,首单手数,ask,5,getSl(OP_BUY),getTp(OP_BUY),"支撑1",Magic,0))<0)         {            Print(Symbol()+"买多OpenErr:",GetLastError()," sl=",0," tp=",0);         }      }           }   //支撑2开多   if (!findOrderByComm("支撑2"))   {      if (Low[1]>g_rsPrice[5] && Bid<=g_rsPrice[5])      {         if((ret=OrderSend(Symbol(),OP_BUY,加仓手数1,ask,5,getSl(OP_BUY),getTp(OP_BUY),"支撑2",Magic,0))<0)         {            Print(Symbol()+"买多OpenErr:",GetLastError()," sl=",0," tp=",0);         }      }           }   //支撑3开多   if (!findOrderByComm("支撑3"))   {      if (Low[1]>g_rsPrice[6] && Bid<=g_rsPrice[6])      {         if((ret=OrderSend(Symbol(),OP_BUY,加仓手数2,ask,5,getSl(OP_BUY),getTp(OP_BUY),"支撑3",Magic,0))<0)         {            Print(Symbol()+"买多OpenErr:",GetLastError()," sl=",0," tp=",0);         }      }           }   //压力1开空   if (!findOrderByComm("压力1"))   {      if (High[1]<g_rsPrice[0] && Bid>=g_rsPrice[0])      {         if((ret=OrderSend(Symbol(),OP_SELL,首单手数,bid,5,getSl(OP_SELL),getTp(OP_SELL),"压力1",Magic,0))<0)         {            Print(Symbol()+"卖空OpenErr:",GetLastError()," sl=",0," tp=",0);         }      }           }   //压力2开空   if (!findOrderByComm("压力2"))   {      if (High[1]<g_rsPrice[1] && Bid>=g_rsPrice[1])      {         if((ret=OrderSend(Symbol(),OP_SELL,加仓手数1,bid,5,getSl(OP_SELL),getTp(OP_SELL),"压力2",Magic,0))<0)         {            Print(Symbol()+"卖空OpenErr:",GetLastError()," sl=",0," tp=",0);         }      }           }   //压力3开空   if (!findOrderByComm("压力3"))   {      if (High[1]<g_rsPrice[2] && Bid>=g_rsPrice[2])      {         if((ret=OrderSend(Symbol(),OP_SELL,加仓手数2,bid,5,getSl(OP_SELL),getTp(OP_SELL),"压力3",Magic,0))<0)         {            Print(Symbol()+"卖空OpenErr:",GetLastError()," sl=",0," tp=",0);         }      }           }   return true;}intgetSumOrders(int type){ int orders = 0; for(int i=OrdersTotal()-1;i>=0;i--) {  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))   {    if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic)    {      continue;    }    if(OrderType()==type || type == 2)    {      orders+=1;    }   } } return orders;}voidOnTick() {   //if (TimeToStr(TimeCurrent())>="2021.10.01") return;   int cnt = getSumOrders(2);   ShowView();   //if (cnt == 0)   {      if (isWorkTime())      {	     checkToOpen();	   }	}	if (cnt>0)	{   	checkToClose();   	checkToMSL();	} }voidcheckToClose(){   if (g_rsPrice[0]>0 && Bid>=g_rsPrice[0]+超出极限位置多少小点止损*Point)   {      printf("空单超出极限位置止损:%d",超出极限位置多少小点止损);      CloseOrder(1);   }   if (g_rsPrice[6]>0 && Bid<=g_rsPrice[6]-超出极限位置多少小点止损*Point)   {      printf("多单超出极限位置止损:%d",超出极限位置多少小点止损);      CloseOrder(0);   }}doublegetTp(int dir, double refPrice=-1){    if (止盈点数>0)    {      if (dir == 0)      {         if (refPrice < 0)            return MarketInfo(Symbol(),MODE_ASK)+止盈点数*Point();         else            return refPrice+止盈点数*Point();      }      else      {         if (refPrice < 0)            return MarketInfo(Symbol(),MODE_BID)-止盈点数*Point();         else            return refPrice-止盈点数*Point();      }    }    else    {      return 0;    }   return 0;}doublegetSl(int dir,double refPrice=-1){    if (止损点数>0)    {        if (dir == 0)        {            if (refPrice < 0)               return MarketInfo(Symbol(),MODE_ASK)-止损点数*Point();            else               return refPrice-止损点数*Point();        }        else        {               if (refPrice < 0)               return MarketInfo(Symbol(),MODE_BID)+止损点数*Point();            else               return refPrice+止损点数*Point();        }    }    else    {            return 0;    }   return 0;}boolisWorkTime(){   return true;   datetime refDT;   refDT = TimeCurrent();   datetime start = StrToTime(TimeToStr(refDT, TIME_DATE)+" "+开始工作时间);   datetime end = StrToTime(TimeToStr(refDT, TIME_DATE)+" "+结束工作时间);    if (start>end)    {        if (refDT>=start || refDT<=end)        {            return true;        }    }    if (start<end)    {        //Print("start:=",TimeToStr(start,TIME_DATE|TIME_MINUTES|TIME_SECONDS),"end=",TimeToStr(end),"curr=",TimeToStr(TimeCurrent()));        if (refDT>=start && refDT<=end)        {            return true;        }    }   return false;}voidcheckToMSL(){   if (移动止损开关)   {      for(int trade=0;trade<OrdersTotal();trade++)   	{   		if (OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))   		{   		   if(OrderSymbol()!=Symbol() || OrderMagicNumber() != Magic)   			continue;      		if(OrderType()==OP_BUY)      		{      			if (g_rsPrice[3]>0 && Bid>=g_rsPrice[3]) //过中点开始移动止损      			{      				if (OrderStopLoss()==0 || OrderStopLoss()<Bid-移动止损点数*Point()-5*Point)       				{  //printf("stoplevel:%f,ask:%f,slprice:%f,tpprice:%f",stoplevel,Ask,Ask-(移动止损激活点数-保护止损点数)*Point,OrderTakeProfit());      					if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-移动止损点数*Point(),OrderTakeProfit(),0,Blue))      					{      					   //Print("[",IntegerToString(__LINE__),"] ","Exception,OrderModify!, ", IntegerToString(GetLastError()));      					}      				}      			}      		}      		if(OrderType()==OP_SELL)      		{      		   if (g_rsPrice[3]>0 && Bid<=g_rsPrice[3]) //过中点开始移动止损      			{      				if (OrderStopLoss()==0 || OrderStopLoss()>Ask+移动止损点数*Point()+5*Point)       				{      					if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+移动止损点数*Point(),OrderTakeProfit(),0,Blue))      					{      					   //Print("[",IntegerToString(__LINE__),"] ","Exception,OrderModify!, ", IntegerToString(GetLastError()));      					}      				}      			}      		}      	}      }   }   //设置最终止盈位置   for(int trade=0;trade<OrdersTotal();trade++)	{		if (OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))		{		   if(OrderSymbol()!=Symbol() || OrderMagicNumber() != Magic)			continue;   		if(OrderType()==OP_BUY)   		{   			if (g_rsPrice[0]>0) //过中点开始移动止损   			{   				if (OrderTakeProfit()!=g_rsPrice[0])    				{  //printf("stoplevel:%f,ask:%f,slprice:%f,tpprice:%f",stoplevel,Ask,Ask-(移动止损激活点数-保护止损点数)*Point,OrderTakeProfit());   					if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),g_rsPrice[0],0,Blue))   					{   					   //Print("[",IntegerToString(__LINE__),"] ","Exception,OrderModify!, ", IntegerToString(GetLastError()));   					}   				}   			}   		}   		if(OrderType()==OP_SELL)   		{   		   if (g_rsPrice[6]>0) //过中点开始移动止损   			{   				if (OrderTakeProfit()!=g_rsPrice[6])    				{   					if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),g_rsPrice[6],0,Blue))   					{   					   //Print("[",IntegerToString(__LINE__),"] ","Exception,OrderModify!, ", IntegerToString(GetLastError()));   					}   				}   			}   		}   	}   }}boolLabelCreate(constlong              chart_ID=0,               // chart's ID                  const string            name="Label",             // label name                  const int               sub_window=0,             // subwindow index                  const int               x=0,                      // X coordinate                  const int               y=0,                      // Y coordinate                  const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // chart corner for anchoring                  const string            text="Label",             // text                  const string            font="Arial",             // font                  const int               font_size=10,             // font size                  const color             clr=clrRed,               // color                  const double            angle=0.0,                // text slope                  const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type                  const bool              back=false,               // in the background                  const bool              selection=false,          // highlight to move                  const bool              hidden=true,              // hidden in the object list                  const long              z_order=0)                // priority for mouse click   { //--- reset the error value    ResetLastError(); //--- create a text label    if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))      {       Print(__FUNCTION__,             ": failed to create text label! Error code = ",GetLastError());       return(false);      } //--- set label coordinates    ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);    ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); //--- set the chart's corner, relative to which point coordinates are defined    ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); //--- set the text    ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); //--- set text font    ObjectSetString(chart_ID,name,OBJPROP_FONT,font); //--- set font size    ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); //--- set the slope angle of the text    ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); //--- set anchor type    ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); //--- set color    ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- display in the foreground (false) or background (true)    ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- enable (true) or disable (false) the mode of moving the label by mouse    ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);    ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); //--- hide (true) or display (false) graphical object name in the object list    ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- set the priority for receiving the event of a mouse click in the chart    ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- successful execution    return(true);   } double g_rsPrice[7]={0};voidShowView(){   iCustom(NULL,0,"阻力支撑线03",0,0);   double res1=0,res2=0,res3=0,supp1=0,supp2=0,supp3=0,center=0;   string res1Nmae="R1";   string res2Nmae="R2";   string res3Nmae="R3";   string supp1Nmae="S1";   string supp2Nmae="S2";   string supp3Nmae="S3";   string centerNmae="PIVIOT";   if (ObjectFind(0,res3Nmae)>=0)   {      res3 = ObjectGetDouble(0,res3Nmae,OBJPROP_PRICE);      g_rsPrice[0] = res3;   }   if (ObjectFind(0,res2Nmae)>=0)   {      res2 = ObjectGetDouble(0,res2Nmae,OBJPROP_PRICE);      g_rsPrice[1] = res2;   }   if (ObjectFind(0,res1Nmae)>=0)   {      res1 = ObjectGetDouble(0,res1Nmae,OBJPROP_PRICE);      g_rsPrice[2]= res1;   }   if (ObjectFind(0,centerNmae)>=0)   {      center = ObjectGetDouble(0,centerNmae,OBJPROP_PRICE);      g_rsPrice[3]= center;   }   if (ObjectFind(0,supp1Nmae)>=0)   {      supp1 = ObjectGetDouble(0,supp1Nmae,OBJPROP_PRICE);      g_rsPrice[4]= supp1;   }   if (ObjectFind(0,supp2Nmae)>=0)   {      supp2 = ObjectGetDouble(0,supp2Nmae,OBJPROP_PRICE);      g_rsPrice[5]= supp2;   }   if (ObjectFind(0,supp3Nmae)>=0)   {      supp3 = ObjectGetDouble(0,supp3Nmae,OBJPROP_PRICE);      g_rsPrice[6]= supp3;   }   int startY = 200;   int yInv=25;   string showTxt = "压力3:"+DoubleToStr(res3,Digits);   ObjectDelete("压力3");   LabelCreate(ChartID(),"压力3",0,10,startY,CORNER_LEFT_LOWER,showTxt,"Arial Bold",12,clrYellow,0,ANCHOR_LEFT_UPPER);   startY-=yInv;   showTxt = "压力2:"+DoubleToStr(res2,Digits);   ObjectDelete("压力2");   LabelCreate(ChartID(),"压力2",0,10,startY,CORNER_LEFT_LOWER,showTxt,"Arial Bold",12,clrYellow,0,ANCHOR_LEFT_UPPER);   startY-=yInv;   showTxt = "压力1:"+DoubleToStr(res1,Digits);   ObjectDelete("压力1");   LabelCreate(ChartID(),"压力1",0,10,startY,CORNER_LEFT_LOWER,showTxt,"Arial Bold",12,clrYellow,0,ANCHOR_LEFT_UPPER);   startY-=yInv;   showTxt = "中心位:"+DoubleToStr(center,Digits);   ObjectDelete("中心位");   LabelCreate(ChartID(),"中心位",0,10,startY,CORNER_LEFT_LOWER,showTxt,"Arial Bold",12,clrYellow,0,ANCHOR_LEFT_UPPER);   startY-=yInv;   showTxt = "支撑1:"+DoubleToStr(supp1,Digits);   ObjectDelete("支撑1");   LabelCreate(ChartID(),"支撑1",0,10,startY,CORNER_LEFT_LOWER,showTxt,"Arial Bold",12,clrYellow,0,ANCHOR_LEFT_UPPER);   startY-=yInv;   showTxt = "支撑2:"+DoubleToStr(supp2,Digits);   ObjectDelete("支撑2");   LabelCreate(ChartID(),"支撑2",0,10,startY,CORNER_LEFT_LOWER,showTxt,"Arial Bold",12,clrYellow,0,ANCHOR_LEFT_UPPER);   startY-=yInv;   showTxt = "支撑3:"+DoubleToStr(supp3,Digits);   ObjectDelete("支撑3");   LabelCreate(ChartID(),"支撑3",0,10,startY,CORNER_LEFT_LOWER,showTxt,"Arial Bold",12,clrYellow,0,ANCHOR_LEFT_UPPER);   startY-=yInv;}

相关学习资料