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
  #1131 (permalink)  
Old 08-07-2008, 04:26 PM
Member
 
Join Date: Feb 2008
Posts: 30
Berkis is on a distinguished road
Thumbs up Is this possible ?

Maybe someone can help me, i dont know if its possible or very hard to do it, but I would be very happy to have such tool. I need a simple EA or script with a help of MT4-LevelStop-Reverse indicator. I want my orders to be closed when i get opposite signal from indicator. If i have opened long order and get short signal the EA or script closes order and if i am short open order and get long sygnal the EA or script closes my short position. That's it

Thank you in advance
Attached Files
File Type: mq4 MT4-LevelStop-Reverse-vB0-4_Alert_mtf.mq4 (15.0 KB, 17 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1132 (permalink)  
Old 08-08-2008, 02:42 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Add Trade Hours

How do I setup Time Trading hours in an EA?

I was trying this;
int TradeHour;

if(Hour()<9 && Hour() >17) TradeHour = false;

but doesn't seem to be obeying the rule, it just trades whenever and I do have && TradeHour in my buy/sell statements.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1133 (permalink)  
Old 08-08-2008, 04:32 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 722
wolfe is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
How do I setup Time Trading hours in an EA?

I was trying this;
int TradeHour;

if(Hour()<9 && Hour() >17) TradeHour = false;

but doesn't seem to be obeying the rule, it just trades whenever and I do have && TradeHour in my buy/sell statements.

Thanks
Have you tried defining TradeHour as a boolean instead of an integer?
PHP Code:
bool TradeHour;

if ((
Hour()<9)  &&  (Hour() >17)){ TradeHour false;} 
Plus you may need the additional brackets.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1134 (permalink)  
Old 08-08-2008, 04:41 AM
Senior Member
 
Join Date: Nov 2006
Posts: 215
luxinterior is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
How do I setup Time Trading hours in an EA?

I was trying this;
int TradeHour;

if(Hour()<9 && Hour() >17) TradeHour = false;

but doesn't seem to be obeying the rule, it just trades whenever and I do have && TradeHour in my buy/sell statements.

Thanks
How can Hour() be less than 9 AND greater than 17?? Did you mean Or (||)?

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1135 (permalink)  
Old 08-08-2008, 04:46 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 722
wolfe is on a distinguished road
Quote:
Originally Posted by luxinterior View Post
How can Hour() be less than 9 AND greater than 17?? Did you mean Or (||)?

Lux
Good point luxinterior! That's a definite problem. I missed that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1136 (permalink)  
Old 08-08-2008, 05:44 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Sorry, I meant ||

and I was trying this to;
//+---------Trade hour variables------------------
// if (Hour() < StartHour) TradeHourS = false;
// if (Hour() > EndHour) TradeHourE = false;

So if StartHour=5 and EndHour=17 it should only trade within those hours correct?

But it trade anytime still ?? is it a problem using the Strategy Tester?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1137 (permalink)  
Old 08-08-2008, 05:50 AM
Senior Member
 
Join Date: Nov 2006
Posts: 215
luxinterior is on a distinguished road
Why not just use the example straight from the help file?

Code:
  bool is_siesta=false;
  if(Hour()>=12 || Hour()<17)
     is_siesta=true;
Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1138 (permalink)  
Old 08-08-2008, 10:58 AM
Junior Member
 
Join Date: Aug 2008
Posts: 7
gorgoroth is on a distinguished road
Returning string from a c/c++ DLL exported functions

Hi everyone,

I've developed a set of functions to manage configuration settings from an EA.
Those functions are exported by a c++ DLL and each of the exported function has the __stdcall calling convetion requested my MQL4.

My problem arises when a function need to return a string to the EA.

Naturally the function cannot:
- return a pointer to a local variabile (variable goes out of scope)
- return a pointer to a dll global variable (problems with concurrent access)
- return a pointer to a heap allocated string (need functions to free memory to be called from the EA: I don't not like this approach)

So i resolved to pass a string and string size from the EA. Es:

Code:
string buffer;

GetString( buffer, 30 );
and from the c++ dll, something like this

Code:
void __stdcall GetString( LPTSTR buffer, int BufSize )
{
    // Read a string from a some source
    ....
    // -1 to take into account the terminating null character
    StringCchCopy( buffer, BufSize-1, ReadStringFromASource );
}

Here starts the weird behaviour of MQL managing strings returned from a DLL.

using the following code:

Code:
string buffer;
GetString( buffer, 30 );
the first time buffer contains the right string. A first question arises: buffer is not initialized but after calling GetString it contains the string returned. I have to suppose that MQL allocates space for a string variable when it's declared.

Next time GetString() is called the string returned seems to be truncated to the length-1 of the previous string length and not resetted as expected because of the 'string buffer;' statement.

Tried even:

Code:
string buffer = "                              "; // 'allocate' 30 blank characters
GetString( buffer, StringLen(buffer) );
but after the first time, when the execution returns to this code, the assignment of buffer does not work any more and buffer still contains the previous read string, and it seems it can only contains the number of characters of his content.

At first I have thought that the null character is not handled very well by MQL and modified the c++ code like this ...

Code:
CopyMemory( buffer, ReadStringFromASource, min(BufferSize,ReadStringFromASourceLength) );
and not adding the terminating null character.

But when called from MQL, no string at all is returning.

Has someone an answer ?

Last edited by gorgoroth; 08-08-2008 at 11:28 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1139 (permalink)  
Old 08-08-2008, 11:37 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by luxinterior View Post
Why not just use the example straight from the help file?

Code:
  bool is_siesta=false;
  if(Hour()>=12 || Hour()<17)
     is_siesta=true;
Lux
yeah, I tried that to;
bool TradeHour=false;

if(Hour()>=12 || Hour()<17) TradeHour=true

but the OR line won't work because if Hour happens to be 22 then it satisfies the first part "if(Hour()>=12" and Still trades whenever it wants and I did add && TradeHour to by Buy/Sell statements. The second example I gave should to the trick, I don't get it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1140 (permalink)  
Old 08-08-2008, 11:48 AM
Junior Member
 
Join Date: Aug 2008
Posts: 7
gorgoroth is on a distinguished road
Quote:
Originally Posted by luxinterior View Post
Why not just use the example straight from the help file?

Code:
  bool is_siesta=false;
  if(Hour()>=12 || Hour()<17)
     is_siesta=true;
Lux
I think if your goal is to trade between 12:00 and 17:00 you simply have to do the following:

Code:
  bool TradingEnabled=false; // Global variable
...
...
  TradingEnabled=false; // Reset every tic run
  if(Hour()>=12 && Hour()<17)
     TradingEnabled=true;
...
...
    if( TradingEnabled ) 
    {
         // Trading logic here
    }
...
...
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 08:40 PM.



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