加码策略自动交易EA GoblinFibo1.2.A.mq4-MT4 EA-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

加码策略自动交易EA GoblinFibo1.2.A.mq4

GoblinFibo1.2.A EA是采用指标Turbo_JVELTurbo_JRSX的信号触发开仓交易,带有加码策略。测试前需要将两个指标先行放置到指标文件夹。

源码:

//+-----------------------------------------------------------------------+
//|                                                   GoblinFibo1.2.A.mq4 |
//|                                      Copyright 2005, Alejandro Galindo|
//+-----------------------------------------------------------------------+
#property copyright "Copyright 2005, Alejandro Galindo"
#property link      "http://www.125808047.com"

extern double    TakeProfit = 32;
extern double    Lots = 0.1;
extern double    InitialStop = 1; 
extern double    TrailingStop = 17;

extern bool      FiboProgression=True;
extern int       MaxTrades=13;
extern int       Pips=18;
extern int       SecureProfit=10;
extern int       AccountProtection=0; 
extern int       OrderstoProtect=0; 
                                            
extern double    EquityProtectionLevel;
extern double    MaxLossPerOrder;                                   
extern int       ReverseCondition=0; 
extern int       mm=0; 
extern int       risk=12;
extern int       AccountisNormal=0;                   
extern int       Magic = 123987;
                                
int              OpenOrders=0, cnt=0;
int              slippage=5;
double           sl=0, tp=0;
double           BuyPrice=0, SellPrice=0;
double           lotsi=0, mylotsi=0;
int              mode=0, myOrderType=0;
bool             ContinueOpening=True;
double           LastPrice=0;
int              PreviousOpenOrders=0;
double           Profit=0;
int              LastTicket=0, LastType=0;
double           LastClosePrice=0, LastLots=0;
double           Pivot=0;
double           PipValue=0;
string           text="", text2="";
double           DnTrendVal=0,UpTrendVal=0,TrendVal=0;
string           TrendTxt="analyzing...";
int              RSX_Period=17;
int              trendtype=0;
bool             AllowTrading=true;
bool             cg=false;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{  
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void OnTick()
{ 
   if (AllowTrading==false) {return;}
   
   if (AccountisNormal==1)
   {
	  if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000); }
		else { lotsi=Lots; }
   } else {  // then is mini
    if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000)/10; }
		else { lotsi=Lots; }
   }
   
   if (MathAbs(MaxLossPerOrder) > 0)
    {
     for(cnt=OrdersTotal();cnt>=0;cnt--) 
      {
       RefreshRates();
       cg=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
       if (OrderSymbol() == Symbol())
        {
         if (OrderType() == OP_BUY && OrderMagicNumber() == Magic && OrderProfit() <=  MathAbs(MaxLossPerOrder) * (-1)) { cg=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,White); }
         if (OrderType() == OP_SELL && OrderMagicNumber() == Magic && OrderProfit() <= MathAbs(MaxLossPerOrder) * (-1)) { cg=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,White); }
        }
      }
    }
      
   if(EquityProtectionLevel > 0 && AccountEquity() <= EquityProtectionLevel)
     {
      AllowTrading = false;
      Print("Min. Equity Level Reached - Trading Halted For ",Symbol());
      Alert("Min. Equity Level Reached - Trading Halted For ",Symbol());
      for(cnt=OrdersTotal();cnt>=0;cnt--)
       {
	     cg=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  	  mode=OrderType();
		  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) 
		   {
		    if (mode==OP_BUY) { cg=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); }
			 if (mode==OP_SELL) { cg=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); }
		   }
	    }
     }      

   if (lotsi>100){ lotsi=100; }
   
   OpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     cg=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
	  {				
	  	  OpenOrders++;
	  }
   }     
   
   PipValue = MarketInfo(Symbol(),MODE_TICKVALUE);
   if (PipValue==0) { PipValue=5; }
   
   if (PreviousOpenOrders>OpenOrders) 
   {	  
	  for(cnt=OrdersTotal();cnt>=0;cnt--)
	  {
	     cg=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  	  mode=OrderType();
		  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) 
		  {
			if (mode==OP_BUY) { cg=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); }
			if (mode==OP_SELL) { cg=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); }
		 }
	  }
   }

   PreviousOpenOrders=OpenOrders;
   if (OpenOrders>=MaxTrades) 
   {
	  ContinueOpening=False;
   } else {
	  ContinueOpening=True;
   }

   if (LastPrice==0) 
   {
	  for(cnt=0;cnt<OrdersTotal();cnt++)
	  {	
	    cg=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
		 mode=OrderType();	
		 if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) 
		 {
			LastPrice=OrderOpenPrice();
			if (mode==OP_BUY) { myOrderType=2; }
			if (mode==OP_SELL) { myOrderType=1;	}
		 }
	  }
   }

   if (OpenOrders<1) 
   {
     myOrderType=OpenOrdersBasedOnTrendRSX();
 	  if (ReverseCondition==1)
	  {
	  	  if (myOrderType==1) { myOrderType=2; }
		  else { if (myOrderType==2) { myOrderType=1; } }
	  }
   }
   
   Check_Trend();
   for(cnt=OrdersTotal();cnt>=0;cnt--)
   {
     cg=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) 
	  {	
	  	  if (OrderType()==OP_SELL) 
	  	  {			
	  	  	  if (TrailingStop>0) 
			  {
				  if (OrderOpenPrice()-Ask>=(TrailingStop+Pips)*Point) 
				  {						
					 if (OrderStopLoss()>(Ask+Point*TrailingStop))
					 {			
					    cg=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderClosePrice()-TakeProfit*Point-TrailingStop*Point,800,Purple);
	  				 }
	  			  }
			  }
	  	  }
   
	  	  if (OrderType()==OP_BUY)
	  	  {
	  		 if (TrailingStop>0) 
	  		 {
			   if (Bid-OrderOpenPrice()>=(TrailingStop+Pips)*Point) 
				{
					if (OrderStopLoss()<(Bid-Point*TrailingStop)) 
					{					   
					   cg=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderClosePrice()+TakeProfit*Point+TrailingStop*Point,800,Yellow);
					}
  				}
			 }
	  	  }
   	}
   }
   
   Profit=0;
   LastTicket=0;
   LastType=0;
	LastClosePrice=0;
	LastLots=0;	
	for(cnt=0;cnt<OrdersTotal();cnt++)
	{
	  cg=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) 
	  {			
	  	   LastTicket=OrderTicket();
			if (OrderType()==OP_BUY) { LastType=OP_BUY; }
			if (OrderType()==OP_SELL) { LastType=OP_SELL; }
			LastClosePrice=OrderClosePrice();
			LastLots=OrderLots();
			if (LastType==OP_BUY) 
			{
				//Profit=Profit+(Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))*PipValue*Ord(cnt,VAL_LOTS);				
				if (OrderClosePrice()<OrderOpenPrice()) 
					{ Profit=Profit-(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
				if (OrderClosePrice()>OrderOpenPrice()) 
					{ Profit=Profit+(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
			}
			if (LastType==OP_SELL) 
			{
				if (OrderClosePrice()>OrderOpenPrice()) 
					{ Profit=Profit-(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
				if (OrderClosePrice()<OrderOpenPrice()) 
					{ Profit=Profit+(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
			}
	  }
   }
	
	Profit=Profit*PipValue;
	text2="Profit: $"+DoubleToStr(Profit,2)+" +/-";
   if (OpenOrders>=(MaxTrades-OrderstoProtect) && AccountProtection==1) 
   {	    
	     if (Profit>=SecureProfit) 
	     {
	        cg=OrderClose(LastTicket,LastLots,LastClosePrice,slippage,Yellow);		 
	        ContinueOpening=False;
	     }
   }

      if (!IsTesting()) 
      {
	     if (myOrderType==3) { text="No conditions to open trades"; }
	     else { text="                         "; }
	     Comment("LastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,"   Trend Direction: ",TrendTxt,"  Slope == ",TrendVal,"\nContinue opening=",ContinueOpening," OrderType=",myOrderType,"\n",text2,"\nLots=",lotsi,"\n",text);
      }

      if (myOrderType==1 && ContinueOpening) 
      {	
	     if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1) 
	     {		
		    SellPrice=Bid;				
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=SellPrice-TakeProfit*Point; }	
		    if (InitialStop==0) { sl=0; }
		    else { sl=NormalizeDouble(SellPrice+InitialStop*Point + (MaxTrades-OpenOrders)*Pips*Point, Digits);  }
		    if (OpenOrders!=0) 
		    {
			   mylotsi=lotsi;			
			   for(cnt=1;cnt<=OpenOrders;cnt++)
			   {
			     if (FiboProgression)  
			       mylotsi=MathRound(MathPow(1.6180339,cnt+1)/MathSqrt(5))*lotsi;  // Fibonacci progression by Tross
              else  
                mylotsi=NormalizeDouble(mylotsi*2,2);   // Martingale progression
			   }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    cg=OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,sl,tp,"RF1",Magic,0,Red);		    		    
	     }
      }
      
      if (myOrderType==2 && ContinueOpening) 
      {
	     if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1) 
	     {		
		    BuyPrice=Ask;
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=BuyPrice+TakeProfit*Point; }	
		    if (InitialStop==0)  { sl=0; }
		    else { sl=NormalizeDouble(BuyPrice-InitialStop*Point - (MaxTrades-OpenOrders)*Pips*Point, Digits); }
		    if (OpenOrders!=0) {
			   mylotsi=lotsi;			
			   for(cnt=1;cnt<=OpenOrders;cnt++)
			   {
			     if (FiboProgression)  
			       mylotsi=MathRound(MathPow(1.6180339,cnt+1)/MathSqrt(5))*lotsi;  // Fibonacci progression by Tross
              else  
                mylotsi=NormalizeDouble(mylotsi*2,2);   // Martingale progression
			   }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    cg=OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,slippage,sl,tp,"RF1",Magic,0,Blue);		    
	     }
      }   
  }
  
int OpenOrdersBasedOnTrendRSX()
{
      myOrderType=3;
   
      Check_Trend();
         
      double rsxcurr = iCustom(Symbol(),Period(),"Turbo_JRSX",RSX_Period,0,0);
      double rsxprev = iCustom(Symbol(),Period(),"Turbo_JRSX",RSX_Period,0,1);
      if ((rsxcurr > rsxprev) && (trendtype == 2 || trendtype == 3)) { myOrderType = 2; }
      if ((rsxcurr < rsxprev) && (trendtype == 2 || trendtype == 1)) { myOrderType = 1; }
      return(myOrderType);
}

void Check_Trend()
{
  UpTrendVal = iCustom(Symbol(),Period(), "Turbo_JVEL",7,-100,0,0);
  DnTrendVal = iCustom(Symbol(),Period(), "Turbo_JVEL",7,-100,1,0);
  TrendVal = (UpTrendVal + DnTrendVal);
  if(TrendVal <= -0.09)
      {
       trendtype = 1;
       TrendTxt = "Strong Downtrend";
      } 
  if(TrendVal > -0.09 && TrendVal < 0)
      {
       trendtype = 2;
       TrendTxt = "Weak Downtrend/Ranging";
      }
  if(TrendVal > 0 && TrendVal < 0.09)
      {
       trendtype = 2;
       TrendTxt = "Weak Uptrend/Ranging";
      } 
  if(TrendVal >= 0.09)
      {
       trendtype = 3;
       TrendTxt = "Strong Uptrend";  
      }
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 加码策略自动交易EA GoblinFibo1.2.A.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏