加码类型自动交易EA Wave Power EA.mq4-MT4 EA-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

加码类型自动交易EA Wave Power EA.mq4

Wave Power EA 属于加码类型的自动交易策略。

源码:

//+---------------------------------------------------------------------+
//|                                                    Wave Power EA.mq4|
//|                                    Copyright 2008, Regeneration by K|
//+---------------------------------------------------------------------+
#property copyright "Copyright 2008, K LAM Wave Power EA V1.0A"
#property link      "http://www.125808047.com"

#define MAGICMA  20070424
#define Version  20090203

extern string Name_Expert= "Wave Power EA";
extern string OWN="Copyright 2008, K LAM";
extern string  sq="--WAVE SETTING--";
extern int    OpenOrdersBasedOn=16; 

extern string sb="--TRADE SETTING--";
extern double Lots = 1;     
extern int    TakeProfit = 32; 
extern double multiply = 2;  
extern int    MaxTrades = 12;  
extern int    Pips = 24; 
extern int    StopLoss = 0; 
extern bool   MyMoneyProfitTarget= False;  
extern double My_Money_Profit_Target= 100000; 

extern string MM="--Account Management--";  
extern string riskset="risk to calculate the lots size (0 Mini order)";
extern int    risk=0;
extern string magicnumber="--MAgic No--";
extern int    MagicNumber=20070424;

extern string  so="--CUTLOSS SETTING--";
extern bool SecureProfitProtection = False;
extern string OTP="Number of orders to enable the account protection";
extern int OrderstoProtect=4;
extern string SP="profit more than Rebound Point we close the orders";
extern double ReboundProfit2 = 18;
extern double ReboundProfit1 = 28;
extern bool LossProtection =False;
extern double TTLoss= 0;
extern string  ASP="if one will check profit from all symbols, if cero only this symbol";
extern bool AllSymbolsProtect=False;
extern string  EP="if true, then the expert will protect the account equity to the percent specified";
extern bool EquityProtection=False;
extern string  AEP="percent of the account to protect on a set of trades";
extern int AccountEquityPercentProtection=70;
extern string  AMP="if true, then the expert will use money protection to the USD specified";
extern bool TradeOnFriday = true; 

extern string  OtherSetting="--Others Setting--";
extern int OrdersTimeAlive=0;

extern bool ReverseCondition=False; 
extern bool SetLimitOrders=False;
extern bool HoldMulitSymbol=False; 

color ArrowsColorModify=Purple;
color ArrowsColorUp=Aqua;
color ArrowsColorDown=Red;
color ArrowsColor=Orange;

bool ContinueOpening=True;
bool OSymbolInStore = false;
bool  cg =  True;
string OSymbol = "GBPUSD";
string XSymbol = "GBPUSD";

datetime LastOrderOpenTime=0,CurrOrderOpenTime=0;

string StrOrderDirect = "Buy | Sell";

int anythings=2404;
int PreviousOpenOrders=0;
int OpenOrders=0;
int MarketOpenOrders=0, LimitOpenOrders=0;
int slippage=5;
int myOrderType=0;
int OrderTypeDirect=99;

double miniLot=0,maxLot=0;
double BuyPrice=0, SellPrice=0, LastPrice=0;
double lotsi=0, mylotsi=0;

double Profit=0;
double CurLot=0;

double PipValue=0;
double indexAOhigh=0;
double indexAOlow=0;

double TmpMark=0;
double MaxDrawdown=0,MaxLots=0;

double LowFreeMargin=0,LowAccountEquity=0,MaxBalance=0;
datetime StartDate,EndDate;

int OnInit()
{ 
double indexAO;  
int count;
int AOtimeframe=30;

double indexRate=0.7;

   StartDate = TimeCurrent();
   XSymbol=Symbol();
   LowAccountEquity = AccountEquity();
   LowFreeMargin = AccountFreeMargin();
   MaxBalance = AccountBalance();

   miniLot=MarketInfo(XSymbol,MODE_MINLOT);
   
   maxLot=MarketInfo(XSymbol,MODE_MAXLOT);
   
	if (risk==0) lotsi=miniLot;

	else lotsi=MathCeil(AccountBalance()*risk/1000)*miniLot;	
	lotsi =Lots;
		
   Print("AC Min Lot=",miniLot," Max Lot=",maxLot," Start Real Lot=",lotsi);

if(OpenOrdersBasedOn==10) { 
   for(count=0;count < Bars;count++) {
      indexAO=iAO(XSymbol,AOtimeframe, count);
      if(indexAO > indexAOhigh) indexAOhigh = indexAO;
      if(indexAO < indexAOlow) indexAOlow = indexAO;
      }
      Print("30 Bars =",iBars(XSymbol,30)," 60 Bars =",iBars(XSymbol,60));
      Print("High=",indexAOhigh," Low=",indexAOlow," Last=",indexAO);
}

indexAOhigh = indexAOhigh*indexRate;
indexAOlow = indexAOlow*indexRate;
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
   void OnDeinit(const int reason)
  {
   DeleteAllObjects();

   EndDate = TimeCurrent();
	if (risk==0) lotsi=miniLot;

	else lotsi=MathCeil(AccountBalance()*risk/10000)*miniLot;
	lotsi =Lots;	

   int Onefile = FileOpen( StringConcatenate( "WP EA(", AccountServer(), ").csv"), FILE_CSV | FILE_READ | FILE_WRITE,',');
   if ( Onefile < 0 ) { Print( "Write File Fail!! ", GetLastError(), "Error NO" ); }
   	
	FileSeek(Onefile, 0, SEEK_END);
   int fsize=FileSize(Onefile);
   
   if (fsize == 0)
   FileWrite(	Onefile,
	            "Symbol",
	            "Max Drawdown",
	            "Low Equity",
	            "Low FreeMargin",
	            "Max Lot Make",
	            "Total Trade",
	            "Account Balance",
	            "Max Balance",
	            "Start",
	            "End"
	            );

	FileWrite(	Onefile,
	            XSymbol,
	            MaxDrawdown,
	            NormalizeDouble(LowAccountEquity,2),
	            NormalizeDouble(LowFreeMargin,2),
	            MaxLots,
	            OrdersHistoryTotal(),
	            NormalizeDouble(AccountBalance(),2),
	            NormalizeDouble(MaxBalance,2),
	            TimeToStr(StartDate,TIME_DATE|TIME_MINUTES),
	            TimeToStr(EndDate,TIME_DATE|TIME_SECONDS)
	            );
	FileClose( Onefile );

if (false) {
   int handle = FileOpen( StringConcatenate( "WP EA(", XSymbol, ").csv"), FILE_CSV | FILE_WRITE,',');
	if ( handle < 0 ) { Print( "Write File Fail!! ", GetLastError(), "Error NO" ); }

	FileWrite(	handle,
	            "Symbol",
	            "Max Drawdown",
	            "Low Equity",
	            "Low FreeMargin",
	            "Max Lot Make",
	            "Total Trade",
	            "Account Balance",
	            "Max Balance",
	            "Start",
	            "End"
	            );

	FileWrite(	handle,
	            XSymbol,
	            MaxDrawdown,
	            NormalizeDouble(LowAccountEquity,2),
	            NormalizeDouble(LowFreeMargin,2),
	            MaxLots,
	            OrdersHistoryTotal(),
	            NormalizeDouble(AccountBalance(),2),
	            NormalizeDouble(MaxBalance,2),
	            TimeToStr(StartDate,TIME_DATE|TIME_MINUTES),
	            TimeToStr(EndDate,TIME_DATE|TIME_SECONDS)
	            );

	FileClose( handle ); }
	

   Print("AC Min Lot=",miniLot," Max Lot=",maxLot," End Real Lot=",lotsi);
   Print("Wow....New Drawdown Record at $",MaxDrawdown," Low Equity",LowAccountEquity," Low FreeMargin",LowFreeMargin,"Max Lot",MaxLots,"Account Balance",AccountBalance());
   
if(OpenOrdersBasedOn==10) {
   Print(XSymbol," 30M Bars =",iBars(XSymbol,30)," 60M Bars =",iBars(XSymbol,60));
   Print(XSymbol,"High=",indexAOhigh," Low=",indexAOlow);
   }
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void OnTick()
  {
   int cnt=0;
   string text="";
   OSymbolInStore = false;
   
   slippage =(Ask-Bid)/Point;
   PipValue=MarketInfo(XSymbol,MODE_TICKVALUE); 
   if (PipValue==0) PipValue=5;
      
      TmpMark = AccountEquity();
      if(TmpMark < LowAccountEquity) {LowAccountEquity=TmpMark;}

      TmpMark = AccountFreeMargin();
      if(TmpMark < LowFreeMargin) {LowFreeMargin=TmpMark;}
      
      TmpMark = AccountBalance();
      if(TmpMark > MaxBalance) {MaxBalance=TmpMark;}

	if (risk==0) lotsi=miniLot;
	else lotsi=MathCeil(AccountBalance()*risk/10000)*miniLot;
	
	lotsi =Lots;
	
   if(lotsi <= miniLot) lotsi = miniLot;
   if(lotsi >= maxLot) lotsi = maxLot;

   TmpMark=AccountProfit();
   if(TmpMark < 0 && MaxDrawdown>TmpMark) { //should be -
         MaxDrawdown=TmpMark;
         }

   OpenOrders=0;
   MarketOpenOrders=0;
   LimitOpenOrders=0;
   CurrOrderOpenTime=0;
   LastOrderOpenTime=0;
   
   for(cnt=0;cnt<OrdersTotal();cnt++)
   {
     if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
     {if(OrderSymbol()!=XSymbol) {OSymbolInStore = true; OSymbol = OrderSymbol();}
	   if (OrderSymbol()==XSymbol && OrderMagicNumber() == MagicNumber)
	   {
	     TmpMark+=OrderProfit(); 
	  	  if (OrderType()==OP_BUY || OrderType()==OP_SELL) 
	  	  {
	  	   MarketOpenOrders++;
	  	   if(OrderOpenTime()!=0) CurrOrderOpenTime=OrderOpenTime();
	  	   if(CurrOrderOpenTime > LastOrderOpenTime) LastOrderOpenTime=CurrOrderOpenTime;
	  	  }
	  	  if (OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYLIMIT) LimitOpenOrders++;
	  	  OpenOrders++;
	   }
	  }
   }
   
         if(TmpMark < 0 && MaxDrawdown>TmpMark) {
         MaxDrawdown=TmpMark;
         }

   if (PreviousOpenOrders>OpenOrders)
   {
    CloseAll(XSymbol,0); 
    DeleteQ(XSymbol,0);
   }
   if (OrdersTimeAlive>0 && LastOrderOpenTime!=0 && (TimeCurrent() - LastOrderOpenTime)>OrdersTimeAlive) // 172800 for 2 day
   {
    text = text + "\nClosing all orders because OrdersTimeAlive protection.";
    Print(TimeCurrent()," - ",LastOrderOpenTime," > ",OrdersTimeAlive);
    Print("Closing all orders because OrdersTimeAlive protection.");
    CloseAll(XSymbol,0);
    DeleteQ(XSymbol,0);
    
    PreviousOpenOrders=OpenOrders+1;
    ContinueOpening=False;
   }   
   if (EquityProtection && AccountEquity()<=AccountBalance()*AccountEquityPercentProtection/100) 
	 {
	 text = text + "\nEquityProtection activated. Closing all orders.";
	 Print("EquityProtection activated. Over ",AccountEquityPercentProtection,"%. Closing all orders. Balance: ",AccountBalance()," Equity: ", AccountEquity());
	 CloseAll(XSymbol,0);
    DeleteQ(XSymbol,0);
	 PreviousOpenOrders=OpenOrders+1;
	 ContinueOpening=False;
   }
   
   if (MyMoneyProfitTarget && AccountBalance() > My_Money_Profit_Target)
   {
    text = text + "\nMoneyProfitTarget reached. Closing all orders..";
    Print("MoneyProfitTarget reached. Closing all orders... Balance: ",AccountBalance()," Equity: ",AccountEquity(),"Last Profit ",AccountProfit());
    CloseAll(XSymbol,0);
    DeleteQ(XSymbol,0);
    
    PreviousOpenOrders=OpenOrders+1;
    ContinueOpening=False;
   }
    
  if((SecureProfitProtection && MarketOpenOrders>=OrderstoProtect) ||
    (LossProtection && MarketOpenOrders>=MaxTrades))
   {
	  Profit=0;
	  CurLot=0;
     for(cnt=0;cnt<OrdersTotal();cnt++)
     {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
       if ((OrderSymbol()==XSymbol && OrderMagicNumber()==MagicNumber) || AllSymbolsProtect)
        {
        Profit=Profit+OrderProfit()+OrderSwap();
        CurLot=CurLot+OrderLots();
        }
      }
     }

	  if(Profit>= ReboundProfit1*CurLot && SecureProfitProtection && MarketOpenOrders>=OrderstoProtect)
	    {
	     text = text + "\nRebound Profit Reach, Closing orders.";
	     Print("Rebound Profit Reach, Closing Balance: ",AccountBalance()," Equity: ", AccountEquity(),
	     "Rebound Over ",ReboundProfit1,"*",CurLot,"=",ReboundProfit1*CurLot," Profit: ",Profit);
	 CloseAll(XSymbol,0);
    DeleteQ(XSymbol,0);
    
	     PreviousOpenOrders=OpenOrders+1;
		  ContinueOpening=False;
		 }
   
	  if(Profit<= -(TTLoss*CurLot) && LossProtection && MarketOpenOrders>=MaxTrades)
	  	 {
	     text = text + "\nLoss Reach, Closing orders.";
	     Print("Loss Reach, Closing Balance: ",AccountBalance()," Equity: ", AccountEquity(),
	     "Loss Over ",TTLoss,"*",CurLot,"=",TTLoss*CurLot," Profit: ",Profit);
	     
    CloseAll(XSymbol,0);
    DeleteQ(XSymbol,0);
    
	     PreviousOpenOrders=OpenOrders+1;
	     ContinueOpening=False;
	  }
}
   if (!TradeOnFriday && DayOfWeek()==5)
   {
    text = text +"\nStop Open New orders because TradeOnFriday protection.";
    Print("Stop Open New orders because TradeOnFriday protection.");
   }

   OpenOrders=0;
   MarketOpenOrders=0;
   LimitOpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
     {if(OrderSymbol()!=XSymbol) {OSymbolInStore = true; OSymbol = OrderSymbol();}
	   if (OrderSymbol()==XSymbol && OrderMagicNumber() == MagicNumber)
	   {				
	  	  if (OrderType()==OP_BUY || OrderType()==OP_SELL) 
	  	  {
	  	   MarketOpenOrders++;
	  	   LastOrderOpenTime=OrderOpenTime();
	  	  }
	  	  if (OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYLIMIT) LimitOpenOrders++;
	  	  OpenOrders++;
	   }
	  }
   }
   PreviousOpenOrders=OpenOrders;
   
   if (OpenOrders>=MaxTrades) ContinueOpening=False;
      else ContinueOpening=True;

   if (LastPrice==0) 
   {
	  for(cnt=0;cnt<OrdersTotal();cnt++)
	  {	
	    if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
        {if(OrderSymbol()!=XSymbol) {OSymbolInStore = true; OSymbol = OrderSymbol();}
		  if (OrderSymbol()==XSymbol && OrderMagicNumber() == MagicNumber) 
		  {
			LastPrice=OrderOpenPrice();
			myOrderType=OrderType();
		  }
		 }
	  }
   }

  switch (OpenOrdersBasedOn)
  {
     case 1: {if (MADirected()==OP_BUY) OrderTypeDirect=OP_BUY;
              if (MADirected()==OP_SELL) OrderTypeDirect=OP_SELL; 
     }
       break;
     case 2: {if (EMADirected()==OP_BUY) OrderTypeDirect=OP_BUY;
              if (EMADirected()==OP_SELL) OrderTypeDirect=OP_SELL;
     }
       break;
     case 3: {if (SEMADirected()==OP_BUY) OrderTypeDirect=OP_BUY;
              if (SEMADirected()==OP_SELL) OrderTypeDirect=OP_SELL;
     }
       break;
     case 4: {if (StochDirected()==OP_BUY) OrderTypeDirect=OP_BUY;
              if (StochDirected()==OP_SELL) OrderTypeDirect=OP_SELL;
     }
       break;
     case 5: {if (SMADirected()==OP_BUY) OrderTypeDirect=OP_BUY;
              if (SMADirected()==OP_SELL) OrderTypeDirect=OP_SELL;
     }
       break;
     case 6: {
              OrderTypeDirect=MA5Directed();
     }
       break;
     case 7: {if (StepMAStochDirected()==OP_BUY) OrderTypeDirect=OP_BUY;
              if (StepMAStochDirected()==OP_SELL) OrderTypeDirect=OP_SELL; 
              }
       break;
     case 8: {
                     OrderTypeDirect=IMA_RSIDirected();
     }
       break;
     case 9: {OrderTypeDirect=CCIDirected();
     }
     
       break;
     case 10: {OrderTypeDirect=AODirected();
     }
       break;            
     case 16:
       OrderTypeDirect=StochDirected();
       break;
     case 17:
       OrderTypeDirect=MACD();
       break;
     default: OrderTypeDirect=99;
       break;
  }

   if (OpenOrders<1) 
   {
     myOrderType=OrderTypeDirect;
	  if (ReverseCondition)
	  {
	  	  if (myOrderType==OP_BUY) myOrderType=OP_SELL;
		  else if(myOrderType==OP_SELL) myOrderType=OP_BUY;
	  }
   }   
   
   if (ReverseCondition)
   {
    if (OrderTypeDirect==OP_BUY) OrderTypeDirect=OP_SELL;
    else if (OrderTypeDirect==OP_SELL) OrderTypeDirect=OP_BUY;
   }
   
      if(!IsTesting())
      {
             StrOrderDirect = "Watch......type="+OpenOrdersBasedOn;
             if (OrderTypeDirect==OP_BUY) StrOrderDirect = "Buy.. Type="+OpenOrdersBasedOn;
             if (OrderTypeDirect==OP_SELL) StrOrderDirect = "SELL.. Type="+OpenOrdersBasedOn;
             if (OrderTypeDirect==99 && OpenOrders<1) text=text + "\nNo conditions to open trades";
             if (OSymbolInStore && HoldMulitSymbol) text=text + "\nHold trading! Other Symbol in Store "+OSymbol;             
             Comment(XSymbol," Ver=",Version,"\nLast Price=",LastPrice," Previous Open\'s=",PreviousOpenOrders,
             " Continue Opening=",ContinueOpening,"\nOrder Direct=",StrOrderDirect,"\nLOT=",lotsi,text,
             "\nSPREAD=",MarketInfo(XSymbol,MODE_SPREAD));
      }
      
      if(OSymbolInStore && HoldMulitSymbol)  return;

      if (OpenOrders<1) OpenMarketOrders();
      else
         if (SetLimitOrders) OpenLimitOrders();
         else OpenMarketOrders();
  }
//+------------------------------------------------------------------+
void DrawDirect(int goto)
{
if(IsTesting()) return;
   if(goto==OP_BUY)
     {
     anythings++;
     ObjectCreate(DoubleToStr(anythings,0), OBJ_ARROW, 0, iTime(XSymbol,0,0), Bid);
     ObjectSet(DoubleToStr(anythings,0),OBJPROP_ARROWCODE,SYMBOL_ARROWUP);
     ObjectSet(DoubleToStr(anythings,0),OBJPROP_COLOR,Blue);
     }
   if(goto==OP_SELL)
     {
     anythings++;
     ObjectCreate(DoubleToStr(anythings,0), OBJ_ARROW, 0, iTime(XSymbol,0,0), Ask);
     ObjectSet(DoubleToStr(anythings,0),OBJPROP_ARROWCODE,SYMBOL_ARROWDOWN);
     ObjectSet(DoubleToStr(anythings,0),OBJPROP_COLOR,Red);
     }
   if(goto==99)
     {
     anythings++;
     ObjectCreate(DoubleToStr(anythings,0), OBJ_ARROW, 0, iTime(XSymbol,0,0), Ask);
     ObjectSet(DoubleToStr(anythings,0),OBJPROP_ARROWCODE,3);
     ObjectSet(DoubleToStr(anythings,0),OBJPROP_COLOR,Red);
     }
}

void OpenMarketOrders()
{         
   bool result;
   int count=0,OrderComplete=0;
   int err;
   double slx,tpx;
   double ticketno=-1;
   
if (!TradeOnFriday && DayOfWeek()==5)
	  {
	    Comment("TradeOnfriday is False, Not Open Order!!!");
	  }
                     
      if (myOrderType==OP_SELL && ContinueOpening) 
      {	      
	     if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1) 
	     {  
	     if (OpenOrders >= 5) { 
	     BuyPrice=Ask;
		    LastPrice=0;
		    if (TakeProfit>0) {
		          tpx=BuyPrice+TakeProfit*Point;
		          if (OpenOrders == OrderstoProtect-1) tpx=BuyPrice+ReboundProfit1*Point;
		          if (OpenOrders > OrderstoProtect-1) tpx=BuyPrice+ReboundProfit2*Point;
		          }
		       else tpx=0;
		    if (StopLoss>0) slx=BuyPrice-StopLoss*Point;
		       else slx=0;
		    if (OpenOrders!=0) 
		       mylotsi=NormalizeDouble(lotsi*MathPow(multiply,OpenOrders),2);
		       else mylotsi=lotsi;
		    if (mylotsi>100) mylotsi=100;
		    
		    if(mylotsi <= miniLot) mylotsi = miniLot;
		    if(mylotsi >= maxLot) mylotsi = maxLot;		    
          if(AccountFreeMarginCheck(XSymbol,OP_BUY,mylotsi)<=0 || GetLastError()==134) return;
		    ticketno=OrderSend(XSymbol,OP_BUY,mylotsi,BuyPrice,slippage,slx,tpx,Name_Expert+Version,MagicNumber,0,ArrowsColorUp);
		    if(ticketno != -1) OrderComplete=1;
		    if (mylotsi>MaxLots) MaxLots=mylotsi; 
                     } else {
		    SellPrice=Bid;
		    LastPrice=0;
		    if (TakeProfit>0) {
		          tpx=SellPrice-TakeProfit*Point;
		          if (OpenOrders == OrderstoProtect-1) tpx=SellPrice-ReboundProfit1*Point;
		          if (OpenOrders > OrderstoProtect-1) tpx=SellPrice-ReboundProfit2*Point;
	             }
		       else tpx=0;
		    if (StopLoss>0) slx=SellPrice+StopLoss*Point;
		       else slx=0;
		    if (OpenOrders!=0) 
		       mylotsi=NormalizeDouble(lotsi*MathPow(multiply,OpenOrders),2);
		       else mylotsi=lotsi;
		    if(mylotsi>100) mylotsi=100;
		    
		    if(mylotsi <= miniLot) mylotsi = miniLot;
		    if(mylotsi >= maxLot) mylotsi = maxLot;
          if(AccountFreeMarginCheck(XSymbol,OP_SELL,mylotsi)<=0 || GetLastError()==134) return;
		    ticketno=OrderSend(XSymbol,OP_SELL,mylotsi,SellPrice,slippage,slx,tpx,Name_Expert+Version,MagicNumber,0,ArrowsColorDown);
		    if(ticketno != -1) OrderComplete=1;
		    if (mylotsi>MaxLots) MaxLots=mylotsi; 
		    }
	     }
      }
      
      if (myOrderType==OP_BUY && ContinueOpening)
      {
	     if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1) 
	     {
	     if (OpenOrders >= 5) {
		    SellPrice=Bid;
		    LastPrice=0;
		    if (TakeProfit>0) {
		          tpx=SellPrice-TakeProfit*Point;
		          if (OpenOrders == OrderstoProtect-1) tpx=SellPrice-ReboundProfit1*Point;
		          if (OpenOrders > OrderstoProtect-1) tpx=SellPrice-ReboundProfit2*Point;
	             }
		       else tpx=0;
		    if (StopLoss>0) slx=SellPrice+StopLoss*Point;
		       else slx=0;
		    if (OpenOrders!=0) 
		       mylotsi=NormalizeDouble(lotsi*MathPow(multiply,OpenOrders),2);
		       else mylotsi=lotsi;
		    if(mylotsi>100) mylotsi=100;
		    
		    if(mylotsi <= miniLot) mylotsi = miniLot;
		    if(mylotsi >= maxLot) mylotsi = maxLot;
          if(AccountFreeMarginCheck(XSymbol,OP_SELL,mylotsi)<=0 || GetLastError()==134) return;

		    ticketno=OrderSend(XSymbol,OP_SELL,mylotsi,SellPrice,slippage,slx,tpx,Name_Expert+Version,MagicNumber,0,ArrowsColorDown);
		    if(ticketno != -1) OrderComplete=1;
		    if (mylotsi>MaxLots) MaxLots=mylotsi; 
                     } else {
		    BuyPrice=Ask;
		    LastPrice=0;
		    if (TakeProfit>0) {
		          tpx=BuyPrice+TakeProfit*Point;
		          if (OpenOrders == OrderstoProtect-1) tpx=BuyPrice+ReboundProfit1*Point;
		          if (OpenOrders > OrderstoProtect-1) tpx=BuyPrice+ReboundProfit2*Point;
		          }
		       else tpx=0;
		    if (StopLoss>0) slx=BuyPrice-StopLoss*Point;
		       else slx=0;
		    if (OpenOrders!=0) 
		       mylotsi=NormalizeDouble(lotsi*MathPow(multiply,OpenOrders),2);
		       else mylotsi=lotsi;
		    if (mylotsi>100) mylotsi=100;
		    
		    if(mylotsi <= miniLot) mylotsi = miniLot;
		    if(mylotsi >= maxLot) mylotsi = maxLot;		    
          if(AccountFreeMarginCheck(XSymbol,OP_BUY,mylotsi)<=0 || GetLastError()==134) return;
		    
		    ticketno=OrderSend(XSymbol,OP_BUY,mylotsi,BuyPrice,slippage,slx,tpx,Name_Expert+Version,MagicNumber,0,ArrowsColorUp);
		    if(ticketno != -1) OrderComplete=1;
		    if (mylotsi>MaxLots) MaxLots=mylotsi;
		    }
	     }
      }
      Sleep(1000);
      RefreshRates();
      
if(OrderComplete==0) return;
 if(ContinueOpening) {
 if(myOrderType==OP_BUY || myOrderType==OP_SELL) {
   for(count=OrdersTotal()-1;count>=0;count--) {
     if(OrderSelect(count,SELECT_BY_POS,MODE_TRADES)==false) break;
	  if(OrderSymbol() == XSymbol && OrderMagicNumber() == MagicNumber) // && Reversed==False) 
	    { 
         if(NormalizeDouble(tpx, Digits)==NormalizeDouble(OrderTakeProfit(), Digits) 
         && NormalizeDouble(slx, Digits)==NormalizeDouble(OrderStopLoss(), Digits)) continue;
         else {
            if(slx==0)
            result=OrderModify(OrderTicket(),OrderOpenPrice(),0,tpx,0,ArrowsColorModify);
            else
            result=OrderModify(OrderTicket(),OrderOpenPrice(),slx,tpx,0,ArrowsColorModify);


            if(!result)
              { err=GetLastError();
                if(!IsTesting()) Print("LastError = ",err); 
                }
                if(!IsTesting()) Print("Ticket ",OrderTicket()," modified.");
            }
	  }
   }
}
}
}

void OpenLimitOrders()
{
double slx,tpx;
               
      if (myOrderType==OP_SELL && ContinueOpening) 
      {	
		    SellPrice = LastPrice+Pips*Point;
		    LastPrice=0;
		    if (TakeProfit>0) tpx=SellPrice-TakeProfit*Point;
		       else tpx=0;
		    if (StopLoss>0) slx=SellPrice+StopLoss*Point;
		       else slx=0;
		    if (OpenOrders!=0) 
		       mylotsi=NormalizeDouble(lotsi*MathPow(multiply,OpenOrders),2);
		       else mylotsi=lotsi;
		    if (mylotsi>100) mylotsi=100;

		    if(mylotsi <= miniLot) mylotsi = miniLot;
		    if(mylotsi >= maxLot) mylotsi = maxLot;		    
          if(AccountFreeMarginCheck(XSymbol,OP_BUY,mylotsi)<=0 || GetLastError()==134) return;
		    cg = OrderSend(XSymbol,OP_SELLLIMIT,mylotsi,SellPrice,slippage,slx,tpx,Name_Expert+Version,MagicNumber,0,ArrowsColor);		    		    
      }
      
      if (myOrderType==OP_BUY && ContinueOpening) 
      {
		    BuyPrice=LastPrice-Pips*Point;
		    LastPrice=0;
		    if (TakeProfit>0) tpx=BuyPrice+TakeProfit*Point;
		       else tpx=0;
		    if (StopLoss>0) slx=BuyPrice-StopLoss*Point;
		       else slx=0;
		    if (OpenOrders!=0) 
		       mylotsi=NormalizeDouble(lotsi*MathPow(multiply,OpenOrders),2);
		       else mylotsi=lotsi;
		    if (mylotsi>100) mylotsi=100;
		    if(mylotsi <= miniLot) mylotsi = miniLot;
		    if(mylotsi >= maxLot) mylotsi = maxLot;		    
          if(AccountFreeMarginCheck(XSymbol,OP_BUY,mylotsi)<=0 || GetLastError()==134) return;
		    cg=OrderSend(XSymbol,OP_BUYLIMIT,mylotsi,BuyPrice,slippage,slx,tpx,Name_Expert+Version,MagicNumber,0,ArrowsColor);		    
      }   
}

void DeleteAllObjects()
{
 int    obj_total=ObjectsTotal();
 string name;
 for(int i=0;i<obj_total;i++)
 {
  name=ObjectName(i);
  if (name!="")
   ObjectDelete(name);
 }
 ObjectDelete("FLP_txt");
 ObjectDelete("P_txt");
}

void CloseAll(string SymbolToClose,int MagicNo) 
{
bool   result;
int cmd,error;
int cnt;
int CloseNo;
   CloseNo=OrdersTotal();
   if(CloseNo==0) return;
   for(cnt=OrdersTotal();cnt > 0;cnt--) {
      if(OrderSelect(cnt-1,SELECT_BY_POS, MODE_TRADES)==true) {
      if((SymbolToClose=="All") || 
         (OrderSymbol()==SymbolToClose && MagicNo == 0) ||
         (OrderSymbol()==SymbolToClose && OrderMagicNumber() == MagicNo)) {
            while(true) {
            cmd=OrderType();
             if(cmd==OP_BUY)
               result=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,ArrowsColor);
             if(cmd==OP_SELL)
               result=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,ArrowsColor);

               if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
               else error=0;
               if(error==129 || error==135) RefreshRates();
               else break;
            }//while
         }//if
      } else Print( "Error when order select ", GetLastError());//OrderSelect
      }//for
   CloseNo=CloseNo-OrdersTotal(); 
   if(!IsTesting()) Print(CloseNo," Orders Closed");
}

void DeleteQ(string SymbolToClose,int MagicNo)
{
int cnt;
int CloseNo,mode;

   CloseNo=OrdersTotal();
   if(CloseNo==0) return;
   for(cnt=OrdersTotal()-1;cnt>=0;cnt--) //last to frist
      {
      cg=OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES);
      mode=OrderType();
      if((SymbolToClose=="All") || 
         (OrderSymbol()==SymbolToClose && MagicNo == 0) ||
         (OrderSymbol()==SymbolToClose && OrderMagicNumber() == MagicNo)) {
             if(mode==OP_SELLLIMIT || mode==OP_BUYLIMIT || mode==OP_BUYSTOP || mode==OP_SELLSTOP)
               cg=OrderDelete(OrderTicket());
             }
      }
   CloseNo=CloseNo-OrdersTotal();
   if(!IsTesting()) Print(CloseNo," Queue Orders Removed");
}

int StochDirected()
{
int    K_Period = 14;
int    D_Period = 3;
int    Slow_Period = 3;
int    Stoch_TF = 60;
int    Ma_TF = 60; 
int    shift=1;
int    H_level = 92; 
int    L_level = 8; 

int stochMAmode = 3;
int mamode;
int SDirect=99;

  switch (stochMAmode) {
     case 0: mamode=MODE_SMA;
       break; 	
     case 1: mamode=MODE_EMA;
       break; 
     case 2: mamode=MODE_SMMA;
       break; 
     case 3: mamode=MODE_LWMA;
       break;        
     default: mamode=MODE_SMA;
       break;
  }
    	double stom1=iStochastic(XSymbol,Stoch_TF,K_Period,D_Period,Slow_Period,mamode,0,MODE_MAIN,shift);
   	double stom2=iStochastic(XSymbol,Stoch_TF,K_Period,D_Period,Slow_Period,mamode,0,MODE_MAIN,shift+1);
   	double stos1=iStochastic(XSymbol,Stoch_TF,K_Period,D_Period,Slow_Period,mamode,0,MODE_SIGNAL,shift);
   	double stos2=iStochastic(XSymbol,Stoch_TF,K_Period,D_Period,Slow_Period,mamode,0,MODE_SIGNAL,shift+1);

      double madirect=iMA(XSymbol,Ma_TF,72,0,MODE_SMA,PRICE_TYPICAL,0); // 72 3 day 144 x Ma_TF 144H 6 day!!

      if(stom1<stos1 && stom2>=stos2 && stom2>H_level)
        {
        SDirect=OP_SELL;
        DrawDirect(OP_SELL); }

      if(stom1>stos1 && stom2<=stos2 && stom2<L_level)
        { 
        SDirect=OP_BUY;
        DrawDirect(OP_BUY); }
    
return(SDirect);
}

int MADirected()
{
int   per_SMA5 = 15;
int   per_SMA20 = 20;
int   per_SMA40 = 25;
int   per_SMA60 = 50;
int   MaDirect=99;
double SMA5, SMA20, SMA40, SMA60, SMA40_prew;

  SMA5 = iMA(XSymbol,PERIOD_H1,per_SMA5,0,MODE_SMA,PRICE_MEDIAN,1);
  SMA20 = iMA(XSymbol,PERIOD_H1,per_SMA20,0,MODE_SMA,PRICE_MEDIAN,1);
  
  SMA40_prew = iMA(XSymbol,PERIOD_H1,per_SMA40,0,MODE_SMA,PRICE_MEDIAN,2);
  SMA40 = iMA(XSymbol,PERIOD_H1,per_SMA40,0,MODE_SMA,PRICE_MEDIAN,1);
  SMA60 = iMA(XSymbol,PERIOD_H1,per_SMA60,0,MODE_SMA,PRICE_MEDIAN,1);

  if(SMA5>SMA20 && SMA20>SMA40 && (SMA40-SMA60)>=0.0001 && SMA40_prew<=SMA60)  
     { MaDirect=OP_BUY;
       DrawDirect(OP_BUY);
     }

  if(SMA5<SMA20 && SMA20<SMA40 && (SMA60-SMA40)>=0.0001 && SMA40_prew>=SMA60) 
     { MaDirect=OP_SELL;
       DrawDirect(OP_SELL);
     }

return(MaDirect);
}

int EMADirected()
{
int    EDirect    =99; 
int    ShortEma   =19;
int    LongEma    =110; 
double SEma, LEma,EMA1,EMA2,LWMA1,LWMA2;

  SEma = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);
  LEma = iMA(XSymbol,PERIOD_H1,LongEma,0,MODE_EMA,PRICE_CLOSE,0);
  
  EMA1  = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_EMA,PRICE_CLOSE,1);
  EMA2  = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_EMA,PRICE_CLOSE,2);
  LWMA1 = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_LWMA,PRICE_CLOSE,1);
  LWMA2 = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_LWMA,PRICE_CLOSE,2); 

  if(LWMA1 > EMA1 && LWMA1 > LWMA2 && EMA1 > EMA2)
     { EDirect=OP_BUY;
       DrawDirect(OP_BUY);
     }

  if(LWMA1 < EMA1 && LWMA1 < LWMA2 && EMA1 < EMA2)
     { EDirect=OP_SELL;
       DrawDirect(OP_SELL);
     }
return(EDirect);
}

int SEMADirected()
{
int    SEDirect   =99; 
int    ShortEma   =19;
int    LongEma    =110;
double SEma, LEma,EMA1,EMA2,LWMA1,LWMA2;
double S1M, S1S, S2M, S2S, S3M, S3S, S4M, S4S;
bool   UseEMAFilter=true;
bool   Buy,Sell;
  SEma = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);
  LEma = iMA(XSymbol,PERIOD_H1,LongEma,0,MODE_EMA,PRICE_CLOSE,0);
  
  EMA1  = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_EMA,PRICE_CLOSE,1);
  EMA2  = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_EMA,PRICE_CLOSE,2);
  LWMA1 = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_LWMA,PRICE_CLOSE,1);
  LWMA2 = iMA(XSymbol,PERIOD_H1,ShortEma,0,MODE_LWMA,PRICE_CLOSE,2); 

  Sell=   LWMA1 < EMA1 && LWMA1 < LWMA2 && EMA1 < EMA2 ; 
  Buy=    LWMA1 > EMA1 && LWMA1 > LWMA2 && EMA1 > EMA2 ;
  if (!UseEMAFilter) {
   Buy = true;
   Sell = true;
   }
  
   S1M=iStochastic(XSymbol,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S1S=iStochastic(XSymbol,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S2M=iStochastic(XSymbol,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S2S=iStochastic(XSymbol,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S3M=iStochastic(XSymbol,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   S3S=iStochastic(XSymbol,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   S4M=iStochastic(XSymbol,PERIOD_H1,14,3,3,MODE_SMA,0,MODE_MAIN,0);
   S4S=iStochastic(XSymbol,PERIOD_H1,14,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   
   if(S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S && Buy)
     { SEDirect=OP_BUY;
       DrawDirect(OP_BUY);
     }

   if(S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S && Sell)  
     { SEDirect=OP_SELL;
       DrawDirect(OP_SELL);
     }
     
return(SEDirect);
}

int SMADirected()
{
int    SMADirect  =99; 
int    TimeF      =60;
double ima13,ima21,ima5,IndexMa;

 ima13 =iMA(XSymbol,TimeF,13,0,MODE_SMA,PRICE_CLOSE,0);
 ima21 =iMA(XSymbol,TimeF,21,0,MODE_SMA,PRICE_CLOSE,0);
 ima5  =iMA(XSymbol,TimeF,5,0,MODE_SMMA,PRICE_MEDIAN,0);
 IndexMa=(ima13-ima21)*10000;
 Comment("Index Ma =",IndexMa);
 
   if(IndexMa > 1)
     { SMADirect=OP_BUY;
       DrawDirect(OP_BUY);
     }

   if(IndexMa < -1)
     { SMADirect=OP_SELL;
       DrawDirect(OP_SELL);
     }
return(SMADirect);
}

int MA5Directed()
{
int    MA5Direct  =99; 
int    TimeF      =60;
double ima5,IndexMa;

 ima5  =iMA(XSymbol,TimeF,5,0,MODE_SMMA,PRICE_MEDIAN,0);
 IndexMa=(Low[0]-ima5)*100;
     
   if(IndexMa < -1)
     {  MA5Direct=OP_BUY;
        DrawDirect(OP_BUY);
     }

   if(IndexMa > 1)
     {  MA5Direct=OP_SELL;
        DrawDirect(OP_SELL);
     }

return(MA5Direct);
}

int StepMAStochDirected()
{

int PeriodWATR=10;
double Kwatr=1.0000;
int HighLow=0;
int NumberOfBarsToCalculate = 500;
double LineMinBuffer[];
double LineMidBuffer[];

int    StepDirect  =99;
double IndexMa;
   int      i,shift,TrendMin,TrendMax,TrendMid;
   double   SminMin0,SmaxMin0,SminMin1,SmaxMin1,SumRange,dK,WATR0,WATRmax,WATRmin;
   double   SminMax0,SmaxMax0,SminMax1,SmaxMax1,SminMid0,SmaxMid0,SminMid1,SmaxMid1;
   double   linemin,linemax,linemid,Stoch1,Stoch2,bsmin,bsmax;
   
   double prev_y = 0,prev_b = 0;
   	
   for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--)
   {
	SumRange=0;
	for (i=PeriodWATR-1;i>=0;i--)
	    { 
       dK = 1+1.0*(PeriodWATR-i)/PeriodWATR;
       SumRange+= dK*MathAbs(High[i+shift]-Low[i+shift]);
       }
	WATR0 = SumRange/PeriodWATR;
	
	WATRmax=MathMax(WATR0,WATRmax);
	if (shift==NumberOfBarsToCalculate-1-PeriodWATR) WATRmin=WATR0;
	WATRmin=MathMin(WATR0,WATRmin);
	
	int StepSizeMin=MathRound(Kwatr*WATRmin/Point);
	int StepSizeMax=MathRound(Kwatr*WATRmax/Point);
	int StepSizeMid=MathRound(Kwatr*0.5*(WATRmax+WATRmin)/Point);
		
	if (HighLow>0)
	  {
	  SmaxMin0=Low[shift]+2*StepSizeMin*Point;
	  SminMin0=High[shift]-2*StepSizeMin*Point;
	  
	  SmaxMax0=Low[shift]+2*StepSizeMax*Point;
	  SminMax0=High[shift]-2*StepSizeMax*Point;
	  
	  SmaxMid0=Low[shift]+2*StepSizeMid*Point;
	  SminMid0=High[shift]-2*StepSizeMid*Point;
	  
	  if(Close[shift]>SmaxMin1) TrendMin=1; 
	  if(Close[shift]<SminMin1) TrendMin=-1;
	  
	  if(Close[shift]>SmaxMax1) TrendMax=1; 
	  if(Close[shift]<SminMax1) TrendMax=-1;
	  
	  if(Close[shift]>SmaxMid1) TrendMid=1; 
	  if(Close[shift]<SminMid1) TrendMid=-1;
	  }
	 
	if (HighLow == 0)
	  {
	  SmaxMin0=Close[shift]+2*StepSizeMin*Point;
	  SminMin0=Close[shift]-2*StepSizeMin*Point;
	  
	  SmaxMax0=Close[shift]+2*StepSizeMax*Point;
	  SminMax0=Close[shift]-2*StepSizeMax*Point;
	  
	  SmaxMid0=Close[shift]+2*StepSizeMid*Point;
	  SminMid0=Close[shift]-2*StepSizeMid*Point;
	  
	  if(Close[shift]>SmaxMin1) TrendMin=1; 
	  if(Close[shift]<SminMin1) TrendMin=-1;
	  
	  if(Close[shift]>SmaxMax1) TrendMax=1; 
	  if(Close[shift]<SminMax1) TrendMax=-1;
	  
	  if(Close[shift]>SmaxMid1) TrendMid=1; 
	  if(Close[shift]<SminMid1) TrendMid=-1;
	  }
	 	
	  if(TrendMin>0 && SminMin0<SminMin1) SminMin0=SminMin1;
	  if(TrendMin<0 && SmaxMin0>SmaxMin1) SmaxMin0=SmaxMin1;
		
	  if(TrendMax>0 && SminMax0<SminMax1) SminMax0=SminMax1;
	  if(TrendMax<0 && SmaxMax0>SmaxMax1) SmaxMax0=SmaxMax1;
	  
	  if(TrendMid>0 && SminMid0<SminMid1) SminMid0=SminMid1;
	  if(TrendMid<0 && SmaxMid0>SmaxMid1) SmaxMid0=SmaxMid1;
	  
	  if (TrendMin>0) linemin=SminMin0+StepSizeMin*Point;
	  if (TrendMin<0) linemin=SmaxMin0-StepSizeMin*Point;
	  
	  if (TrendMax>0) linemax=SminMax0+StepSizeMax*Point;
	  if (TrendMax<0) linemax=SmaxMax0-StepSizeMax*Point;
	  
	  if (TrendMid>0) linemid=SminMid0+StepSizeMid*Point;
	  if (TrendMid<0) linemid=SmaxMid0-StepSizeMid*Point;
	  
	  bsmin=linemax-StepSizeMax*Point;
	  bsmax=linemax+StepSizeMax*Point;
	  Stoch1=NormalizeDouble((linemin-bsmin)/(bsmax-bsmin),6);
	  Stoch2=NormalizeDouble((linemid-bsmin)/(bsmax-bsmin),6);
	  prev_y = (Stoch1 - Stoch2);
	  if(prev_y<0.0){
	     LineMinBuffer[shift] = prev_y;
	     LineMidBuffer[shift] = 0;
	     }
	  else if(prev_y>0.0){
	     LineMidBuffer[shift] = prev_y;
	     LineMinBuffer[shift] = 0;
	     }
	  SminMin1=SminMin0;
	  SmaxMin1=SmaxMin0;
	  
	  SminMax1=SminMax0;
	  SmaxMax1=SmaxMax0;
	  
	  SminMid1=SminMid0;
	  SmaxMid1=SmaxMid0;
	 }
	 
	 IndexMa = prev_y*10;
	 
	    if(IndexMa > 2) {
	        StepDirect=OP_BUY;
	        DrawDirect(OP_BUY);
	        }
	       else { if(IndexMa < -2) {
	        StepDirect=OP_SELL;
	        DrawDirect(OP_SELL);
	        }
	          else {
	            StepDirect=99;
	            DrawDirect(99);
	          }
	        }
	return(StepDirect);
}


int IMA_RSIDirected()
{
int    RSIDirect  =99; 
int RSIOMA          = 3;
int RSIOMA_MODE     = MODE_EMA;
int RSIOMA_PRICE    = PRICE_CLOSE;

int Ma_RSIOMA       = 21,Ma_RSIOMA_MODE  = MODE_EMA;
int MainTrendLong   = 50;
int MainTrendShort  = 50;
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];

double bdn[],bup[];
double sdn[],sup[];

double marsioma[];

int i;
int MAFastPeriod=3;
int MAFastShift=0;
int MAFastMethod=MODE_SMA;
int MAFastPrice=PRICE_CLOSE;

int MASlowPeriod=8;
int MASlowShift=0;
int MASlowMethod=MODE_SMA;
int MASlowPrice=PRICE_CLOSE;
int rete;

double rel,negative,positive;

double macd = iMACD(XSymbol,0,5,13,1,PRICE_CLOSE,MODE_MAIN,0);
int    counted_bars=IndicatorCounted();

  double fast1=iMA(XSymbol,0,MAFastPeriod,MAFastShift,MAFastMethod,MAFastPrice,1);
  double fast2=iMA(XSymbol,0,MAFastPeriod,MAFastShift,MAFastMethod,MAFastPrice,2);
  double slow1=iMA(XSymbol,0,MASlowPeriod,MASlowShift,MASlowMethod,MASlowPrice,1);
  double slow2=iMA(XSymbol,0,MASlowPeriod,MASlowShift,MASlowMethod,MASlowPrice,2);

  if (fast1>slow1&&fast2<slow2) rete = OP_BUY;
  if (fast1<slow1&&fast2>slow2) rete = OP_SELL;
   
   if(Bars<=RSIOMA) return(99);
   if(counted_bars<1)
      for(i=1;i<=RSIOMA;i++) RSIBuffer[Bars-i]=0.0;
   i=Bars-RSIOMA-1;
   
   int ma = i;
   
   if(counted_bars>=RSIOMA) i=Bars-counted_bars-1;
   
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-RSIOMA-1)
        {
         int k=Bars-2;
         while(k>=i)
           {
            double cma = iMA(XSymbol,0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,k);
            double pma = iMA(XSymbol,0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,k+1);
            
            rel=cma-pma;
            
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIOMA;
         negative=sumn/RSIOMA;
        }
      else
        {
         double ccma = iMA(XSymbol,0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,i);
         double ppma = iMA(XSymbol,0,RSIOMA,0,RSIOMA_MODE,RSIOMA_PRICE,i+1);

         rel=ccma-ppma;
         
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(PosBuffer[i+1]*(RSIOMA-1)+sump)/RSIOMA;
         negative=(NegBuffer[i+1]*(RSIOMA-1)+sumn)/RSIOMA;
        }
      PosBuffer[i]=positive;
      NegBuffer[i]=negative;
      if(negative==0.0) RSIBuffer[i]=0.0;
      else
      {
          RSIBuffer[i]=100.0-100.0/(1+positive/negative);
          
          bdn[i] = 0;
          bup[i] = 0;
          sdn[i] = 0;
          sup[i] = 0;
          
          if(RSIBuffer[i]>MainTrendLong)
          bup[i] = -10;
          
          if(RSIBuffer[i]<MainTrendShort)
          bdn[i] = -10;
          
          if(RSIBuffer[i]<30 && RSIBuffer[i]>RSIBuffer[i+1])
          sup[i] = -10;
          
          if(RSIBuffer[i]>70 && RSIBuffer[i]<RSIBuffer[i+1])
          sdn[i] = -10;
      }
      i--;
     }
   for(;ma>=0;ma--)     
     {
         marsioma[ma] = iMAOnArray(RSIBuffer,0,Ma_RSIOMA,0,Ma_RSIOMA_MODE,ma); 
     }
string tripo;

if (rel > 0 && macd > 0) tripo = "BUY";
if (rel < 0 && macd < 0) tripo = "SELL";

   RSIDirect = 99;
   if (rel > 0 && rete == OP_BUY) RSIDirect = OP_BUY;
   if (rel < 0 && rete == OP_SELL) RSIDirect = OP_SELL;
	return(RSIDirect);
}

int CCIDirected()
{
int CCIDirect=99;
int CCIPeriod1=15;
int CCIPeriod2=20;
int CCItimeframe=60;

double indexCCI1=iCCI(XSymbol,CCItimeframe,CCIPeriod1,PRICE_TYPICAL,0);
double indexCCI2=iCCI(XSymbol,CCItimeframe,CCIPeriod2,PRICE_TYPICAL,1);

  if (indexCCI1 < -120) CCIDirect = OP_BUY;
  if (indexCCI1 > 120) CCIDirect = OP_SELL;
	return(CCIDirect);
}

int AODirected()
{
int AODirect=99;
int AOtimeframe=30;

double indexAO0=iAO(XSymbol, AOtimeframe, 0);
double indexAO1=iAO(XSymbol, AOtimeframe, 1);
double indexAO2=iAO(XSymbol, AOtimeframe, 2);
double indexAO3=iAO(XSymbol, AOtimeframe, 3);

if (indexAO0 < indexAOlow)
         AODirect = OP_BUY;
if (indexAO0 > indexAOhigh)
        AODirect = OP_SELL;
	return(AODirect);
}

int MACD()
{
   int MACDDirect=99;      
   if (iMACD(Symbol(),0,14,26,9,PRICE_CLOSE,MODE_MAIN,0)>
       iMACD(Symbol(),0,14,26,9,PRICE_CLOSE,MODE_MAIN,1)) { MACDDirect=OP_BUY; }
   if (iMACD(Symbol(),0,14,26,9,PRICE_CLOSE,MODE_MAIN,0)<
       iMACD(Symbol(),0,14,26,9,PRICE_CLOSE,MODE_MAIN,1)) { MACDDirect=OP_SELL; }
	return(MACDDirect);
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 加码类型自动交易EA Wave Power EA.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏