
11-30-2005, 01:29 AM
|
 |
Senior Member
|
|
Join Date: Oct 2005
Posts: 994
|
|
Worked?
Quote:
|
Originally Posted by codersguru
Hi yanuv_av,
I'm so sorry for the delay in replaying you; I've spent all the day fixing my damn car to reach my office and reply your questions  .
Now you have an EA and want to close the order after 30 bars (or whatever count you want), Right?
Well
Place this function on the top of start() function:
PHP Code:
bool BarsCountDown(int count)
{
static bool first_call = true;
static int start_bar = 0;
if(first_call)
{
start_bar=Bars;
first_call=false;
}
if(Bars == (start_bar+count))
{
Print("(TRUE) Bars= " + Bars + " : start_bars = " + start_bar);
first_call=true;
return (true);
}
else
{
Print("(FALSE) Bars= " + Bars + " : start_bars = " + start_bar);
return (false);
}
}
How to use this function:
bool BarsCountDown(30);
The line above returns false if the current bar hasn't exceeded the number 30 from the first call of the function (the 30 bars not yet counted)
And returns true if the current bar has exceeded the 30 bars
So, when you get true, close the position
In your start() function you may use code like this:
PHP Code:
start()
{
....
if(BarsCountDwon(30))
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // close position
.....
}
I hope you've got it.
|
yanuv_av,
Did that work for you?
|