# Executing a Trade if previous 5 bids are positive

162

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:

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)
{

{

OrderSelect(ShortTicket,SELECT_BY_TICKET);

if(OrderCloseTime() == 0 && ShortTicket > 0)
{

}

OrderSelect(LongTicket,SELECT_BY_TICKET);
double OpenPrice = OrderOpenPrice();
Moderator
2333

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;

162

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!