how do i compare 2 bars ?

 
  • i want to count how many bars went green on the last 5 bars, how do i do it ?
 

I'm assuming your talking candles...


int greenBarsCount = 0;

for(int c = 0; c < 5; c++){
   if(Close[c] > Open[c]) greenBarsCount++;
}

Comment(greenBarsCount);
 

i have writing this code but it open 0 position and return an error 0, can anyone tell me what is wrong ? i trying to check if there are 2 or more green (red) candles together then put them in a function how can i do it

int start()
  {
//----
int gb10 = 0;
int ticket;
for (int c = 0; c < 5; c++)            //check for if there are 2 or more greend candles
{ if (Close[c] > Open[c]) gb10++;
}

     if (gb10 > 2)         // if there are then send buy orders
   {
      
      ticket=OrderSend(Symbol(), OP_BUY, lot, Bid,3, 0, Ask+takeprofit*Point,"", 12345,0,Red);
       } 
       if (ticket >0)
         {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
            Print("buy order open :", OrderOpenPrice());
         }
            else Print ("error opening buy order :", GetLastError());
            return(0);                         // it end up giving me the error message
//----
   return(0);
  }
 

Off the bat:


for an OP_BUY you need to use Ask not Bid.


Make sure your lots are correct, meaning you have enough margin.


StopLoss should be NULL.


Should be gb10 >= 2.


Look at the journal tab and see if it lists an error.

 
jmca wrote >>

Off the bat:

for an OP_BUY you need to use Ask not Bid.

Make sure your lots are correct, meaning you have enough margin.

StopLoss should be NULL.

Should be gb10 >= 2.

Look at the journal tab and see if it lists an error.

thank you for the reply, i dont know why how can i make such mistakes, simply and easy guess i will have to keep learning :-) everything runs fine now

Reason: