Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (1) Thread Tools Display Modes
  #661 (permalink)  
Old 02-02-2008, 05:41 PM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by nittany1 View Post
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,

Code:
//--- Global variable
datetime PreviousBar;   // record candle/bar time
and set one bool in init()

Code:
int init()
  {
   do_this = true;
  }
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
This 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);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #662 (permalink)  
Old 02-04-2008, 02:03 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 722
wolfe is on a distinguished road
Comment placement

Could someone show me the code to place a comment in the UPPER RIGHT corner of the screen, rather than the default upper left?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #663 (permalink)  
Old 02-04-2008, 02:27 AM
Linuxser's Avatar
Moderator
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 3,319
Blog Entries: 46
Linuxser has disabled reputation
Quote:
Originally Posted by wolfe View Post
Could someone show me the code to place a comment in the UPPER RIGHT corner of the screen, rather than the default upper left?

Thanks!
You can't. From MQL4 manual:

Quote:
void Comment( ...)The function outputs the comment defined by the user in the left top corner of the chart.

If you need by death you could could create objects.
__________________
Elite Manual Trading | Portfolio | Calendar | Suggestions to improve the forum | My Blog

Remember: Signatures must have three lines as maximum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #664 (permalink)  
Old 02-04-2008, 03:24 AM
mog's Avatar
mog mog is offline
Junior Member
 
Join Date: Oct 2005
Posts: 11
mog is on a distinguished road
Quote:
Originally Posted by wolfe View Post
Could someone show me the code to place a comment in the UPPER RIGHT corner 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(" <lots of spaces> 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #665 (permalink)  
Old 02-04-2008, 06:33 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 722
wolfe is on a distinguished road
Quote:
Originally Posted by mog View Post
LinusGuy is right; there's no direct way. The easy workaround is to pad your Comment with spaces --
Comment(" <lots of spaces> 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
Thanks for the help. I'll try it!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #666 (permalink)  
Old 02-04-2008, 08:30 AM
Junior Member
 
Join Date: Apr 2007
Posts: 2
mikerawson is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #667 (permalink)  
Old 02-04-2008, 08:59 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
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.

PHP Code:
bool postMortem()
{
    
datetime since Timebar+10 ];
    for ( 
int i OrdersHistoryTotal() - 1>= 0i-- ) {
        if ( ! 
OrderSelectiSELECT_BY_POSMODE_HISTORY )
            continue;
        if ( 
OrderProfit() < && OrderCloseTime() >= since )
            return( 
true );
    }
    return( 
false );

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 Code:
if ( postMortem() ) return( ); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #668 (permalink)  
Old 02-04-2008, 07:10 PM
Junior Member
 
Join Date: Apr 2007
Posts: 2
mikerawson is on a distinguished road
thx very much for that - i will try it
regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #669 (permalink)  
Old 02-06-2008, 08:29 PM
Junior Member
 
Join Date: Apr 2007
Posts: 17
la totona is on a distinguished road
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]<indicatorpast && close[0]>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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #670 (permalink)  
Old 02-08-2008, 05:07 AM
SIDDESH's Avatar
Member
 
Join Date: Nov 2006
Location: mumbai
Posts: 64
SIDDESH is on a distinguished road
Height of previous bar

Hi,

Can you please give the code for previous bar.

This can be used in the EA to limit placing the orders when the previous bar is more than certain height.

Regards,

SIDDESH
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 09:28 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.