Download MetaTrader 5

Experts: News Trader EA

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
185374
MetaQuotes Software Corp.  

News Trader EA:

This EA is supposed to trade news and high market spikes.

Author: Marco Garbuglia

Tjipke de Vries
6372
Tjipke de Vries  

You can trie to make it only trade in the longertrend direction

and trie to implement a moneymanagement system based risk per trade on it

and do some optimizing on the parameters

Use Forum if you get problems and don't know how to go on...

//+------------------------------------------------------------------+
//|(VolumeEA)                                     News Trader EA.mq4 |
//|                                            Copyright © 2012, nxk |
//|                                        Copyright © 2012, deVries |
//|                                                                  |
//|                                                                  |
//| Made this to improve this          http://codebase.mql4.com/8106 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, nxk"
#property copyright "Copyright © 2012, deVries"
#property link      "http://codebase.mql4.com/8106"
extern string EAComment="Volume.EA";
extern int    MagicNumber=454;
extern double StopLossPips=40;
extern double TakeProfitPips=400;
extern int    Slippage.Pips=3;
extern double Lots=0.01;
extern double Factor=1.55;
extern double BreakEven=40;
extern double Trailing_Stop=35;     //350 looks like 5 digit
extern double Trailing_Step=1;
extern int    StoptradingHour=23;
extern double CCILevel1=50;
extern double CCILevel2=190;
extern double CCILevel3=-50;
extern double CCILevel4=-190;
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     ordini=1;
bool    CheckforOpen=false;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (Digits % 2 == 1)  // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
     {pips2dbl = Point*10; pips2points = 10;   Digits.pips = 1;}
     else {pips2dbl = Point;    pips2points =  1;   Digits.pips = 0;}
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {  
//----
   if(NewBar()==true && Volume[1]>Volume[2]*Factor){CheckforOpen=true;}
   if(ordini>0){
     int sells=0;
     int buys=0; 
     for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) 
       if (OrderSelect(iPos, SELECT_BY_POS)                        // Only my orders w/
        &&  OrderMagicNumber()  == MagicNumber                  // my magic number
        &&  OrderSymbol()       == Symbol())                    //chart.symbol    my pair.
      {
       double SL=OrderStopLoss();
       double FP=OrderTakeProfit();
       if(Trailing_Stop>0 && BreakEven==0){BreakEven=Trailing_Stop;}
       if(OrderType()==OP_SELL)
          {
           sells++;
           double pAsk=MarketInfo(OrderSymbol(), MODE_ASK);
           if(TakeProfitPips>0 && pAsk<=OrderOpenPrice()-TakeProfitPips * pips2dbl)
              {
               OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage.Pips * pips2points,Red);
               return(0);
              } 
           if(SL==0 && FP==0 && (StopLossPips>0||TakeProfitPips>0))
              {SL=OrderOpenPrice()+StopLossPips * pips2dbl;FP=OrderOpenPrice()-(2*TakeProfitPips * pips2dbl);}
           if(BreakEven>0 && SL>OrderOpenPrice() && OrderOpenPrice()-pAsk > BreakEven*pips2dbl)
              {SL=OrderOpenPrice();}
           if(SL<=OrderOpenPrice() && SL-pAsk>=(Trailing_Stop+Trailing_Step)*pips2dbl)
              {SL=pAsk+Trailing_Stop*pips2dbl;}
          }
       if(OrderType()==OP_BUY)
          {
           buys++; 
           double pBid=MarketInfo(OrderSymbol(), MODE_BID);
           if(TakeProfitPips>0 && pBid>=OrderOpenPrice()+TakeProfitPips * pips2dbl)
              {
               OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage.Pips * pips2points,Green);
               return(0);
              } 
           if(SL==0 && FP==0 && (StopLossPips>0||TakeProfitPips>0))
              {SL=OrderOpenPrice()-StopLossPips * pips2dbl;FP=OrderOpenPrice()+(2*TakeProfitPips * pips2dbl);}
           if(BreakEven>0 && SL<OrderOpenPrice() && pBid-OrderOpenPrice() > BreakEven*pips2dbl)
              {SL=OrderOpenPrice();}
           if(SL>=OrderOpenPrice() && pBid-SL>=(Trailing_Stop+Trailing_Step)*pips2dbl)
              {SL=pBid-Trailing_Stop*pips2dbl;}
          }
       if(SL != OrderStopLoss()||FP != OrderTakeProfit())
          {OrderModify(OrderTicket(),OrderOpenPrice(),SL,FP,0,Blue);}
       if (TimeHour(MarketInfo(Symbol(),MODE_TIME))==23)
          {OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage.Pips * pips2points,Yellow);}   
      }
    }
  ordini=buys+sells;
      if (CheckforOpen)
         {
          if (TimeHour(MarketInfo(Symbol(),MODE_TIME))>=StoptradingHour)
             {
              CheckforOpen=false;
              return(0);
             } 
          double Commodity.channel=iCCI(NULL,0,14,PRICE_TYPICAL,0);
          double Price,Sl,Tp;
          int    Dir,Ticket;
          color  Color;
          if (Open[1]<Close[1] && Commodity.channel>CCILevel1 && Commodity.channel<CCILevel2)    
             {Dir=0;Price=Ask; Sl=Ask-StopLossPips * pips2dbl; Tp=Ask+(2*TakeProfitPips * pips2dbl); Color=Green;}
          if (Open[1]>Close[1] && Commodity.channel>CCILevel4 && Commodity.channel<CCILevel3)    
             {Dir=1;Price=Bid; Sl=Bid+StopLossPips * pips2dbl; Tp=Bid-(2*TakeProfitPips * pips2dbl); Color=Red;}
          if (Price>0){Ticket=OrderSend(Symbol(),Dir,Lots,Price,Slippage.Pips * pips2points,0,0,EAComment,MagicNumber,0,Color);}
          if(Ticket>0)
            {
             if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES))
                {
                 ordini++;
                 CheckforOpen=false;
                 OrderModify(Ticket,OrderOpenPrice(),Sl,Tp,0,Color);
                }
            } 
         }    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| NewBar                                                           |
//| Returns true when new bar gets first tick                        |
//| Returns false otherwise                                          |
//| Speed up backtest when there are no open trades                  |
//+------------------------------------------------------------------+
bool NewBar()
{
   static datetime dt = 0;
   
   if (Time[0] != dt)
   {
      dt = Time[0];
      return(true);
   }
   return(false);
}
//+------------------------------------------------------------------+  
/*
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){                                                 OptParameters();
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl, Bid + TakeProfitPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
    /* On ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
*/
Sergey Golubev
Moderator
96871
Sergey Golubev  

Forum on trading, automated trading systems and testing trading strategies

Press review

newdigital, 2014.06.06 09:25

3 Steps to Trade Major News Events (based on dailyfx article)

Talking Points:

  • News releases can be stressful on traders
  • Develop a plan before the event arrives
Major news releases can be stressful on traders. That stress can show up for a variety of trading styles.
Perhaps you are already in a good position with a good entry and you are afraid the news release may take a bite out of your good entry.

Perhaps you want to enter into a new position as prices are near a technically sound entry point, but you are uncertain if the technical picture will hold up through the volatile release. Therefore, you agonize over the decision of whether to enter now or after the news event.

Maybe, you like to be in the action and initiating new positions during the release. The fast paced volatility during the news release still gets makes your palms sweat as you place trades.

As you can see, news events stress traders in a variety of ways.

Today, we are going to cover three steps to trade news events.


Step 1 - Have a Strategy

It sounds simple, yet the emotion of the release can easily draw us off course. We see prices moving quickly in a straight line and are afraid to miss out or afraid to lose the gains we have been sitting on. Therefore, we make an emotional decision and act.

Having a strategy doesn’t have to be complicated. Remember, staying out of the market during news and doing nothing is a strategy.

A strategy for the trader with a floating profit entering the news event could be as simple as “I am going to close off half my position and move my stop loss to better than break even.”

For the trader wanting to initiate a new position that is technically based, they may decide to wait until at least 15 minutes after the release, then decide if the set-up is still valid.

The active news trader may realize they need a plan of buy and sell rules because they trade based on what ‘feels good.’

Step 2 - Use Conservative Leverage

If you are in the market when the news is released, make sure you are implementing conservative amounts of leverage. We don’t know where the prices may go and during releases, prices tend to move fast. Therefore, de-emphasize the influence of each trade on your account equity by using low amounts of leverage.

Our Traits of Successful Traders research found that traders who implement less than ten times effective leverage tend to be more profitable on average.


3 - Don’t Deviate from the Strategy

If you have taken the time to think about a strategy from step number one and if you have realized the importance of being conservatively levered, then you are 90% of the way there! However, this last 10% can arguably be the most difficult. Whatever your plan is, stick to it!

If I put together a plan to lose 20 pounds of body weight that includes eating healthier and exercising, but I continue to eat high fat and sugar foods with limited exercise, then I am only setting myself up for frustration.

You don’t have to be stressed or frustrated through fundamental news releases.


To add comments, please log in or register