[MT4-EA]EA研究-27-23 Rule
继续发mt4的EA研究指标
/ / --------托尼C'S原单码已被删除,它只是一个爆发后播放提示。 
  / /最突破失败,因为价格会返回到支撑位和阻力。 
  / /这是不是说的原单是一个坏主意,我添加了一个SliverTrend副本 
  / /作为一个过滤器,并且也注意到最silvertrend信号附近托尼的参考点开始。 
  / /所以这使得代码到一个很好的开端,在生产有利可图的EA。 
  / /我希望从这里,这个代码可以被带到一个新的水平(maumax又名bobammax)//+------------------------------------------------------------------+
//|                                                   27-23 Rule.mq4 |
//|                                                [email protected] |
//|                                             Version 1.0.12-09-04  |
// |   Made to trade by bobammax aka maumax                       |
//-------------------------------------------------------------------+
//-------- Tony C's orginal code has been removed, it only plays an alert after a breakout.
  // most breakouts fail because price will return back into support and resistance.
  //this is not to say the orginal is a bad idea, I have added a SliverTrend copy to
  //act as a filter, and also noticed most silvertrend signals start near Tony's reference point.
  // so this makes the code an excellent place to start, in  producing a profitable EA.
  // I hope from here ,this  code can be taken to a new level( maumax aka bobammax)
  
#property copyright "[email protected]"
#property link      ""
//extern double TakeProfit = 100;
//extern double Lots = 1;
//extern double TrailingStop = 15;
extern double InitialStop = 30;
extern double RefHour = 8;
extern double CloseHour = 9;
extern double TopPriceBuf = 27;
extern double BottomPriceBuf = 23;
extern double MaxSlippage = 5;
extern double EntryCap = 5;
//extern string WavFilePath="sound.wav";
#define MAGIC 493413
extern double StopLoss = 20;
extern double TakeProfit = 100;
extern double TrailingStop = 18;
extern color OpenBuy = Blue;
extern color CloseBuy = Aqua;
extern color OpenSell = Red;
extern color CloseSell = Violet;
extern color ModiBuy = Blue;
extern color ModiSell = Red;
extern string Name_Expert = "";
extern int Slippage = 3;
//extern bool UseSound = True;
//extern string NameFileSound = "alert.wav";
extern double Lots = 1;
double Points;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- TODO: Add your code here.
   Points = MarketInfo (Symbol(), MODE_POINT); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: Add your code here.
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  if(Bars<100){
      Print("bars less than 100");
      return(0);
   }
   if(StopLoss<10){
      Print("StopLoss less than 10");
      return(0);
   }
   if(TakeProfit<10){
      Print("TakeProfit less than 10");
      return(0);
   }
  
   double diCustom0=iCustom(NULL, 0, "BykovTrend_Sig",0, 0);
   double diCustom1=iCustom(NULL, 0, "BykovTrend_Sig",1,0);
   double diDeMarker0=iDeMarker(NULL,0,13,0);
   double diDeMarker1=iDeMarker(NULL,0,13,1);
   if(AccountFreeMargin()<(100*Lots)){
   
      Print("We have no money. Free Margin = ", AccountFreeMargin());
      return(0);
   }
//---- TODO: Add your code here.
   RefreshRates();
   int BarsInADay=24*60/Period();
   int n=MathFloor(BarsInADay*0.7);
   double RefPrice, BuyPrice, SellPrice, LongStopPrice, ShortStopPrice, TodaysRefPrice, TodaysBuyPrice, TodaysSellPrice;
   for(int i=0;i<=200;i++){
      if(TimeHour(Time)!=RefHour || TimeMinute(Time) !=0) continue;
      
      RefPrice=Open;
      BuyPrice=RefPrice+(TopPriceBuf*Points);
      SellPrice=RefPrice-(BottomPriceBuf*Points);
      LongStopPrice=BuyPrice-(InitialStop*Points);
      ShortStopPrice=SellPrice+(InitialStop*Points);
            
      if(TimeDayOfYear(Time)==TimeDayOfYear(CurTime())){
         TodaysRefPrice=RefPrice;
         TodaysBuyPrice=BuyPrice;
         TodaysSellPrice=SellPrice;
         }
         
      int x=MathMax(i-n,0);
      string DateString=TimeDay(Time)+"/"+TimeMonth(Time);
      double TrendLineBeginTime=Time;
      double TrendLineEndTime=Time[x];
      ObjectCreate(DateString+" RefPrice",OBJ_TREND,0,TrendLineBeginTime,RefPrice,TrendLineEndTime,RefPrice);
      ObjectSet(DateString+" RefPrice",OBJPROP_TIME1,TrendLineBeginTime);
      ObjectSet(DateString+" RefPrice",OBJPROP_TIME2,TrendLineEndTime);
      ObjectSet(DateString+" RefPrice",OBJPROP_PRICE1,RefPrice);
      ObjectSet(DateString+" RefPrice",OBJPROP_PRICE2,RefPrice);
      ObjectSet(DateString+" RefPrice",OBJPROP_COLOR,MediumBlue);
      ObjectSet(DateString+" RefPrice",OBJPROP_WIDTH,2);
      ObjectSet(DateString+" RefPrice",OBJPROP_RAY,0);
      
      ObjectCreate(DateString+" BuyPrice",OBJ_TREND,0,TrendLineBeginTime,BuyPrice,TrendLineEndTime,BuyPrice);
      ObjectSet(DateString+" BuyPrice",OBJPROP_TIME1,TrendLineBeginTime);
      ObjectSet(DateString+" BuyPrice",OBJPROP_TIME2,TrendLineEndTime);
      ObjectSet(DateString+" BuyPrice",OBJPROP_PRICE1,BuyPrice);
      ObjectSet(DateString+" BuyPrice",OBJPROP_PRICE2,BuyPrice);      
      ObjectSet(DateString+" BuyPrice",OBJPROP_COLOR,LimeGreen);
      ObjectSet(DateString+" BuyPrice",OBJPROP_WIDTH,3);
      ObjectSet(DateString+" BuyPrice",OBJPROP_RAY,0);
      
      ObjectCreate(DateString+" SellPrice",OBJ_TREND,0,TrendLineBeginTime,SellPrice,TrendLineEndTime,SellPrice);
      ObjectSet(DateString+" SellPrice",OBJPROP_TIME1,TrendLineBeginTime);
      ObjectSet(DateString+" SellPrice",OBJPROP_TIME2,TrendLineEndTime);
      ObjectSet(DateString+" SellPrice",OBJPROP_PRICE1,SellPrice);
      ObjectSet(DateString+" SellPrice",OBJPROP_PRICE2,SellPrice);     
      ObjectSet(DateString+" SellPrice",OBJPROP_COLOR,FireBrick);
      ObjectSet(DateString+" SellPrice",OBJPROP_WIDTH,3);   
      ObjectSet(DateString+" SellPrice",OBJPROP_RAY,0); 
      
      ObjectCreate(DateString+" LongStopPrice",OBJ_TREND,0,TrendLineBeginTime,LongStopPrice,TrendLineEndTime,LongStopPrice);
      ObjectSet(DateString+" LongStopPrice",OBJPROP_TIME1,TrendLineBeginTime);
      ObjectSet(DateString+" LongStopPrice",OBJPROP_TIME2,TrendLineEndTime);
      ObjectSet(DateString+" LongStopPrice",OBJPROP_PRICE1,LongStopPrice);
      ObjectSet(DateString+" LongStopPrice",OBJPROP_PRICE2,LongStopPrice);     
      ObjectSet(DateString+" LongStopPrice",OBJPROP_COLOR,LimeGreen);
      ObjectSet(DateString+" LongStopPrice",OBJPROP_WIDTH,1);
      ObjectSet(DateString+" LongStopPrice",OBJPROP_RAY,0);
      
      ObjectCreate(DateString+" ShortStopPrice",OBJ_TREND,0,TrendLineBeginTime,ShortStopPrice,TrendLineEndTime,ShortStopPrice);
      ObjectSet(DateString+" ShortStopPrice",OBJPROP_TIME1,TrendLineBeginTime);
      ObjectSet(DateString+" ShortStopPrice",OBJPROP_TIME2,TrendLineEndTime);
      ObjectSet(DateString+" ShortStopPrice",OBJPROP_PRICE1,ShortStopPrice);
      ObjectSet(DateString+" ShortStopPrice",OBJPROP_PRICE2,ShortStopPrice);
      ObjectSet(DateString+" ShortStopPrice",OBJPROP_COLOR,Red);
      ObjectSet(DateString+" ShortStopPrice",OBJPROP_WIDTH,1);
      ObjectSet(DateString+" ShortStopPrice",OBJPROP_RAY,0);
      }
      
   Comment( "\n","Today\'s Info:\n\n",
         "RefPrice: ",TodaysRefPrice,"\n",
         "BuyPrice: ",TodaysBuyPrice,"\n",
         "SellPrice: ",TodaysSellPrice,"\n");
         
         if (!ExistPositions()){
  
  
    if (( diCustom0TodaysSellPrice||Open[0]>TodaysSellPrice) && Close[0]<=TodaysSellPrice)//--this is TonyC's orginal code
      {
   //)&& {
      //PlaySound(WavFilePath);
      //Alert(Symbol()," Price went Below SellPrice");
     OpenSell();
      }}
  if(( diCustom1>TodaysRefPrice)&& ( diDeMarker1 > 0.3))// TodaysBuyPrice 
   //if((Open[1]=TodaysBuyPrice)// Tony C's orginal code
       {
   //&&  {
      //PlaySound(WavFilePath);
    //  Alert( Symbol()," Price went Above BuyPrice");
       
  
    OpenBuy(); 
      }
      }
    TrailingPositionsBuy(TrailingStop);
   TrailingPositionsSell(TrailingStop);
   return (0);
bool ExistPositions() {
	for (int i=0; itrailingStop*Point) { 
                  if (OrderStopLoss()trailingStop*Point) { 
                  if (OrderStopLoss()>Ask+trailingStop*Point || OrderStopLoss()==0)  
                     ModifyStopLoss(Ask+trailingStop*Point); 
               } 
            } 
         } 
      } 
   } 
} 
void ModifyStopLoss(double StopLoss) { 
   bool fm;
   fm = OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,OrderTakeProfit(),0,CLR_NONE); 
   //if (fm && UseSound) PlaySound(NameFileSound); 
} 
void OpenBuy() { 
   double Lot, Stop, Take; 
   string Comm; 
   Lot = GetSizeLot(); 
   Stop = GetStopLossBuy(); 
   Take = GetTakeProfitBuy(); 
   Comm = GetCommentForOrder(); 
   OrderSend(Symbol(),OP_BUY,Lot,Ask,Slippage,Stop,Take,Comm,MAGIC,0,OpenBuy); 
   //if (UseSound) PlaySound(NameFileSound); 
} 
void OpenSell() { 
   double Lot, Stop, Take; 
   string Comm; 
   Lot = GetSizeLot(); 
   Stop = GetStopLossSell(); 
   Take = GetTakeProfitSell(); 
   Comm = GetCommentForOrder(); 
   OrderSend(Symbol(),OP_SELL,Lot,Bid,Slippage,Stop,Take,Comm,MAGIC,0,OpenSell); 
   //if (UseSound) PlaySound(NameFileSound); 
} 
string GetCommentForOrder() { 	return(Name_Expert); } 
double GetSizeLot() { 	return(Lots); } 
double GetStopLossBuy() { 	return (Bid-StopLoss*Point);} 
double GetStopLossSell() { 	return(Ask+StopLoss*Point); } 
double GetTakeProfitBuy() { 	return(Ask+TakeProfit*Point); } 
double GetTakeProfitSell() { 	return(Bid-TakeProfit*Point); } 
      
             
//----
   return(0);
  
//+------------------------------------------------------------------+    











