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;
static double lastBid = 0;
if(Bid > lastBid) { count++; }
else { count = 0; }
if(count >= 5)
{
printf("%i consecutive higher bids!",count);
count = 0;
}
lastBid = Bid;
honest_knave:
Thanks honest_knave!! I'll give it a try and let you know if it works!
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;
static double lastBid = 0;
if(Bid > lastBid) { count++; }
else { count = 0; }
if(count >= 5)
{
printf("%i consecutive higher bids!",count);
count = 0;
}
lastBid = Bid;
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!!!
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();