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
counter?
I've been programming indicators for so many months that I'm a little deficient in experts but I'm intending to solve that. Along the way I need a little help. In my expert that I threw together I have it check at bar close if there is a condition that would warrant closing the trade.
I start with a global variable,
datetime PreviousBar; // record candle/bar time[/CODE]
and set one bool in init()
{
do_this = true;
}
[/CODE]
blah blah boring stuff.... etc, etc
then in the main loop I have:
[CODE]
if(do_this == true)
{
PreviousBar = Time[0];
do_this= false; // so it does this only once only
}
if(NewBar() == true)
{
if(TotalOpenOrders() == blah blah close my order you crazy monkey)
}
and outside the main loop I have:
[CODE]//--- returns true if current bar just formed
bool NewBar()
{
if(PreviousBar<Time[0])
{
PreviousBar = Time[0];
return(true);
}
else
{
return(false);
}
return(false);
}OK so it is setup to do once per bar. What I want to do is have a function that increments 90 seconds or 60 seconds or whatever, then sets a bool to true after it's incremented that time. Basically I want to check the indicators every 60, 90, 120 seconds or whatever instead of at bar close. How do I do that?
Thanks for any help,
- nittany1
I've been programming indicators for so many months that I'm a little deficient in experts but I'm intending to solve that. Along the way I need a little help. In my expert that I threw together I have it check at bar close if there is a condition that would warrant closing the trade.
I start with a global variable,
datetime PreviousBar; // record candle/bar time[/CODE]
and set one bool in init()
{
do_this = true;
}
[/CODE]
blah blah boring stuff.... etc, etc
then in the main loop I have:
[CODE]
if(do_this == true)
{
PreviousBar = Time[0];
do_this= false; // so it does this only once only
}
if(NewBar() == true)
{
if(TotalOpenOrders() == blah blah close my order you crazy monkey)
}
and outside the main loop I have:
[CODE]//--- returns true if current bar just formed
bool NewBar()
{
if(PreviousBar<Time[0])
{
PreviousBar = Time[0];
return(true);
}
else
{
return(false);
}
return(false);
}OK so it is setup to do once per bar. What I want to do is have a function that increments 90 seconds or 60 seconds or whatever, then sets a bool to true after it's incremented that time. Basically I want to check the indicators every 60, 90, 120 seconds or whatever instead of at bar close. How do I do that?
Thanks for any help,
- nittany1This should do it. Remember that MT uses tick-based execution so per-second-accuracy is not possible (unless you loop everything in the Init() sub.).
if (CallIndicatorsCheck())
{
// your code here
}
bool CallIndicatorsCheck()
{
static datetime Oldtime;
int Secs = 90;
bool Flag;
if (CurrTime() >= Oldtime) {
Oldtime = CurrTime() + Secs;
Flag = true; }
return(Flag);
}
Comment placement
Could someone show me the code to place a comment in theUPPER RIGHTcorner of the screen, rather than the default upper left?
Thanks!
Could someone show me the code to place a comment in theUPPER RIGHTcorner of the screen, rather than the default upper left? Thanks!
You can't. From MQL4 manual:
If you need by death you could could create objects.
Could someone show me the code to place a comment in theUPPER RIGHTcorner of the screen, rather than the default upper left? Thanks!
LinusGuy is right; there's no direct way. The easy workaround is to pad your Comment with spaces --
Comment(" hello world!");
willl offset the text to the right.
You can also put in line feeds to drop down the page.
Comment("\n\n\n\n\nyour text");
or combine linefeeds and space to print at the lower right-hand corner of the screen.
mog
LinusGuy is right; there's no direct way. The easy workaround is to pad your Comment with spaces --
Comment(" hello world!");
willl offset the text to the right.
You can also put in line feeds to drop down the page.
Comment("\n\n\n\n\nyour text");
or combine linefeeds and space to print at the lower right-hand corner of the screen.
mogThanks for the help. I'll try it!
no new trade for X bars after a losing trade
hi team - hoping someone can help please..
how do i stop a new trade from commencing for 10 bars if the last trade was a loss?
cheers
The function below will return true while the account history has a loss trade that closed at or after the opening of the 10:th past bar (current bar is 0),
and return false otherwise.
{
datetime since = Time[ bar+10 ];
for ( int i = OrdersHistoryTotal() - 1; i >= 0; i-- ) {
if ( ! OrderSelect( i, SELECT_BY_POS, MODE_HISTORY )
continue;
if ( OrderProfit() = since )
return( true );
}
return( false );
}
[/PHP]
If you add that function to your EA, then include a statement like the following in the start() function, then Bob's your uncle.
[PHP]if ( postMortem() ) return( 0 );thx very much for that - i will try it
regards
guys, do you have the same problem?
I have coded an expert. I want to open a position when the price is the same that one indicator. To do this i use the following sentence:
//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);
if (close[1]indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]<indicatornow) OpenSELL();
but with this satatement, the expert opens positions not only when the price cross the indicator, it opens position above the indicator too. I want that the expert open position ONLY when it cross the indicator, so i tried that:
//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);
if (close[1]<indicatorpast && close[0]==indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]==indicatornow) OpenSELL();
But this statement it is not performing.
Do you know what is happen? Because i think there arent errors in the statement.
Regards.