Navigation´╝ÜHome > Content >

smartass2.mq4

Time: 2016-12-12 | Download file:smartass2.mq4

//---- Trades limits
extern   double    Lots = 1;
extern   double    TakeProfit = 1500;
extern   double    TrailingStop = 2000; 
extern   double    StopLoss = 200;
extern   int       Slippage = 5;
extern   double    MaximumRisk        = 0.3;
extern   int       StartTrading = 0;
extern   int       EndTrading   = 24;
extern   bool      UseMM=false;


//--- Global variables
extern int      MagicNumber = 655321;
string   ExpertComment = "SMARTASS";
int      NumberOfTries = 5;

//+------------------------------------------------------------------
int init()
{
   return(0);
}

int deinit() 
{
   return(0);
}
//+------------------------------------------------------------------

bool isNewSymbol(string current_symbol)
  {
   //loop through all the opened order and compare the symbols
   int total  = OrdersTotal();
   for(int cnt = 0 ; cnt < total ; cnt++)
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      string selected_symbol = OrderSymbol();
      if (current_symbol == selected_symbol && OrderMagicNumber()==MagicNumber)
      return (False);
    }
    return (True);
}

//+------------------------------------------------------------------+
int start()
  {
   
    if (Hour()< StartTrading || Hour()>(EndTrading-1))
   {
     CloseOrder(OP_BUY);
     CloseOrder(OP_SELL);

      return(0);
   }
   
   int cnt, ticket, total,n,trend;
   bool up1,up2,down1,down2,up3,down3;
   bool BuyCondition = false , SellCondition = false , CloseBuyCondition = false , CloseSellCondition = false ;
   double signal,signal1,signal2;
   if(Bars<50) {Print("bars less than 50"); return(0);}

   //Symbo settings:
   RefreshRates();
   Slippage = MarketInfo(Symbol(),MODE_SPREAD);
      
      
      
      double ma1=iMA(NULL,0,5,0,MODE_EMA,PRICE_TYPICAL,1);
      double ma2=iMA(NULL,0,12,0,MODE_EMA,PRICE_TYPICAL,1);
      
      double ma1last=iMA(NULL,0,5,0,MODE_EMA,PRICE_TYPICAL,2);
      double ma2last=iMA(NULL,0,12,0,MODE_EMA,PRICE_TYPICAL,2);
      
      double stoch_main = iStochastic(NULL,0,20,6,16,MODE_EMA,0,MODE_MAIN,1);
      double stoch_sig = iStochastic(NULL,0,20,6,16,MODE_EMA,0,MODE_SIGNAL,1);
      double stoch_main1 = iStochastic(NULL,0,20,6,16,MODE_EMA,0,MODE_MAIN,2);
      double stoch_sig1 = iStochastic(NULL,0,20,6,16,MODE_EMA,0,MODE_SIGNAL,2);

      
      double macd_main=iMACD(NULL,0,13,21,8,PRICE_CLOSE,MODE_MAIN,1); 
      double macd_sig=iMACD(NULL,0,13,21,8,PRICE_CLOSE,MODE_SIGNAL,1); 
      double macd_main1=iMACD(NULL,0,13,21,8,PRICE_CLOSE,MODE_MAIN,2); 
      double macd_sig1=iMACD(NULL,0,13,21,8,PRICE_CLOSE,MODE_SIGNAL,2); 
      
      double sar1=iSAR(NULL,0,0.0026,0.5,1);
      double sar2=iSAR(NULL,0,0.0026,0.5,2);

     if ((stoch_main>stoch_sig && macd_main>macd_sig)) up1=true; else up1=false;
     if ((stoch_mainstoch_sig1 && macd_main1>macd_sig1)) up2=true; else up2=false;
     if ((stoch_main10)
   {
      if(OrderMagicNumber() == MagicNumber)
      {
         if(type==OP_BUY)
         {
            if(Bid-OrderOpenPrice()>Point*TrailingStop)
            {
               if(OrderStopLoss()(Point*TrailingStop))
            {
               if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
               }
            }
         }
      }
   }
}

Recommend