need a little help.

 

My problem in brief:

1. At the opening time of the bar i ==> Time[i] ==> buy/sell conditions are met and an order is opened.

2. The order closes (hits t/p or s/l) before closing the bar i; (Time[i] )

3. While we are still in bar i and after the order is closed, buy/sell conditions are met again! ==> BUT I DON'T WANT ANOTHER ORDER TO BE OPENED AT THE BAR i (I mean I need only one order in the bar that meets my entry conditions)

I've tried the code written below, but it doesn't work. Any clue?

datetime time;
...
if(entry condition)
   {
     if(time!=Time[0])
        {
          OrderSend(..);
          time=Time[0];
        }
    }
...
 

Humm, using short st/tp are we here buddy? This has always worked for me. Maybe something else in your code is wrong.

if(Band_TimeStamp!=Time[0])
{
   //----------Buy Order
   if(Band_Direction==1)
   {
         OrderSend(Symbol(),OP_BUY,Lots,
         Price_Buy,4,
         Price_Buy-(Band_StopLoss*Point),
         Price_Buy+(Band_TakeProfit*Point),
         "Band Long",Band_Magic,0,Green);
         Band_TimeStamp=Time[0];
   }
}
 
I suppose I found the answer. Just tell me where should I declare the "time" variable? Local or global? (I'm a noob coder)
 

OH.... sorry I've been having one too many lemonades :) You're gonna need this: Inside the start() is fine but obviously b4 and outside the if statement. You could also use Global Variables and they don't have to be static as they save their value, I think. Non static variable don't save the value and thats the reason u had problems lol.

static datetime Band_TimeStamp;
 
Got it. Either "static" or "Global" variable type solves the problem. Thanks