Download MetaTrader 5

Executing a Trade if previous 5 bids are positive

To add comments, please log in or register
Download MetaTrader 5 and start trading today!
C0mput3r
168
C0mput3r 2016.11.23 13:06 

Hi Guys,

I was wondering if anyone could help me with my EA. I want my code to enter a long position if each of the previous 5 bids are all higher than the previous bid.

In otherwords:

Enter long buy if: PrevBid5<PrevBid4

PrevBid4<PrevBid3

PrevBid3<PrevBid2

PrevBid2<PrevBid1

PrevBid1< Bid 

 At the moment my code runs on previous close of candles but I have not idea how to change to positive bids?

Here is a section of my code, any help will be greatly appreciated!!!

// External variables
extern double LotSize = 1;
extern double StopLoss = 10;
extern double TakeProfit = 1;
extern double TrailingStopLimit = 0;
extern double TrailingStopStop = 0;
extern int MagicNumber = 23310;


// Global variables
int LongTicket;
int ShortTicket;
double RealPoint;



// Init function
int init()
        {
      RealPoint = RealPipPoint(Symbol());
    
        }


// Start function
int start()
        {
  
                          
                // Long
                
                OrderSelect(LongTicket,SELECT_BY_TICKET);
                if(OrderCloseTime() != 0 || LongTicket == 0)
                {
                
                    
bool buy_condition_1 = ((Close[4]<Close[3])&&(Close[3]<Close[2])&&(Close[2]<Close[1]));
                                
                if( buy_condition_1   )
                        {
                                
                                OrderSelect(ShortTicket,SELECT_BY_TICKET);
                                
                                if(OrderCloseTime() == 0 && ShortTicket > 0)
                                        {
                                                                                        
                                                bool Closed = OrderClose(ShortTicket,OrderLots(),Ask,0,Red);
                                        }                              

                                
                                
                                
                                
                                LongTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,0,0,0,"Buy Order",MagicNumber,0,Green);
                                
                                
                                OrderSelect(LongTicket,SELECT_BY_TICKET);
                                double OpenPrice = OrderOpenPrice();
honest_knave
Moderator
2159
honest_knave 2016.11.23 14:13  

You have a few different approaches.

You could use arrays to store the values of the old bids, but I think it is easier to use a counter and compare each bid as it comes in:

   static int    count   = 0;
   static double lastBid = 0;

   if(Bid > lastBid) { count++;   }
   else              { count = 0; }  

   if(count >= 5)
     {
      printf("%i consecutive higher bids!",count);
      count = 0;
     }

   lastBid = Bid;


 

C0mput3r
168
C0mput3r 2016.11.23 14:28  
honest_knave:

You have a few different approaches.

You could use arrays to store the values of the old bids, but I think it is easier to use a counter and compare each bid as it comes in:

   static int    count   = 0;
   static double lastBid = 0;

   if(Bid > lastBid) { count++;   }
   else              { count = 0; }  

   if(count >= 5)
     {
      printf("%i consecutive higher bids!",count);
      count = 0;
     }

   lastBid = Bid;


 

Thanks honest_knave!! I'll give it a try and let you know if it works!
To add comments, please log in or register