You can try using this concept :
In the "init" section reset a variable called "prevBars":
int prevBars=0;
in the "start" section do :
bool newBar
newBar=(Bars > prevBars);
if (newBar)
prevBars=Bars;
"newBar" will be TRUE once a new bar is opened, and then false until the next bar will appear.
A second option would be to use "time" functions:
A bar opens whenever your period goes from endOfPeriod to startofPeriod.
(closes when the opposite transition occurs)
Where endOfPeriod/startOfPeriod depend on the period of you chart.
For example:
On a H1 chart endOfPeriod will be (in seconds) : 3599,7199,10799 etc.
Or in a formula :
bool endOfPeriodH1=((TimeCurrent()%3600)==3599);
bool startOfPeriodH1=((TimeCurrent()%3600)==0);
I will let you do the math on a more general function for all time frames.
The problem with using "time" functions is that there can be a few ticks per second,
and the fact that you reached the "endOfPeriod" does not mean that the bar closed.
That is why you need the transition between endOf.. to startOf.. to indicate a closing/opening of a bar.
Hope this helps.
You can try using this concept :
In the "init" section reset a variable called "prevBars":
int prevBars=0;
in the "start" section do :
bool newBar
newBar=(Bars > prevBars);
if (newBar)
prevBars=Bars;
"newBar" will be TRUE once a new bar is opened, and then false until the next bar will appear.
A second option would be to use "time" functions:
A bar opens whenever your period goes from endOfPeriod to startofPeriod.
(closes when the opposite transition occurs)
Where endOfPeriod/startOfPeriod depend on the period of you chart.
For example:
On a H1 chart endOfPeriod will be (in seconds) : 3599,7199,10799 etc.
Or in a formula :
bool endOfPeriodH1=((TimeCurrent()%3600)==3599);
bool startOfPeriodH1=((TimeCurrent()%3600)==0);
I will let you do the math on a more general function for all time frames.
The problem with using "time" functions is that there can be a few ticks per second,
and the fact that you reached the "endOfPeriod" does not mean that the bar closed.
That is why you need the transition between endOf.. to startOf.. to indicate a closing/opening of a bar.
Hope this helps.
Hi TuTBaluT
i tried what you instructed for Bars, it gives 2 errors in compilation ['prevBars' - variable not defined ]
i tried second option period time, it did not work.
i will try again.
thanks for your help
For Mr. Kolier
i don't know how to make array functions!!!
Hi,
You should define the "prevBars" as an "int" type.
If you post the code here I can see what the problem is.
Hi,
You should define the "prevBars" as an "int" type.
If you post the code here I can see what the problem is.
Here is the EA without addition of your functions, you can try and see where is the problem.
this EA i found on internet, not me who wrote it, but i am using for testing with indicators.
Thanks in advance
Here is the EA without addition of your functions, you can try and see where is the problem.
this EA i found on internet, not me who wrote it, but i am using for testing with indicators.
Thanks in advance
Where exactly do you want to put the conditions of "opening bar" and "closing bar"?
Where exactly do you want to put the conditions of "opening bar" and "closing bar"?
under "Main Signal" where aroon indicator is written.
the Buy and Sell signal is from indicator. and closing positions is at end of Bar.
i managed to make EA close positions every end of Bar.
-----------------------------------------
datetime PreviousBarTime1;
datetime PreviousBarTime2;
---------------------
bool NewBarBuy()
{
if(PreviousBarTime1<Time[0])
{
PreviousBarTime1=Time[0];
return(true);
}
return(false);
--------------------------------------
double aroonup=iCustom(NULL,0,"Aroon",aro,0,0);
double aroondn=iCustom(NULL,0,"Aroon",aro,1,0);
if ( aroonup>70 ) BUY="true";
if ( aroonup<70 ) SELL="true";
---------------------------------
if(OrderType()==OP_BUY)
{ if (PreviousBarTime1<Time[0])
OrderClose(OrderTicket(),OrderLots(),Bid,3); continue;
----------------------------------
if(OrderType()==OP_SELL)
{if (PreviousBarTime1<Time[0])
OrderClose(OrderTicket(),OrderLots(),Ask,3); continue;
Thanks
Here is the EA without addition of your functions, you can try and see where is the problem.
this EA i found on internet, not me who wrote it, but i am using for testing with indicators.
Thanks in advance
Where do you find Aroon MQL implementation that works properly? I've not succeded.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All
how to do it in EA to open position when bar open and close position when bar close?
Thanks