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
  #1141 (permalink)  
Old 08-08-2008, 12:14 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by gorgoroth View Post
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
    }
...
...
Am I not doing the same thing by doing this?;
if (Hour() < 12 && Hour() > 17) TradeHour = false;

Meaning, if hour is between 12 and 17 TradeHour=true , correct?
(Adding && TradeHour in my Buy/Sell statement)

Last edited by matrixebiz; 08-08-2008 at 12:19 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1142 (permalink)  
Old 08-08-2008, 12:18 PM
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
How can Hour() be less than 9 AND greater than 17?? Did you mean Or (||)?

Lux
Oh, and I did mean && because your right the hour can't be less than 9 AND greater than 17 which makes the statement false but if Hour is 10 then it is not less than 9 AND not greater than 17 so statement turns true.
Maybe doing it that way confuses MT4 buy anyway this way works;
int TradeHour;

TradeHour = ((Hour()>=StartHour) && (Hour()<EndHour));

Thanks

Last edited by matrixebiz; 08-08-2008 at 12:33 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1143 (permalink)  
Old 08-08-2008, 12:39 PM
Junior Member
 
Join Date: Aug 2008
Posts: 7
gorgoroth is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
Am I not doing the same thing by doing this?;
if (Hour() < 12 && Hour() > 17) TradeHour = false;

Meaning, if hour is between 12 and 17 TradeHour=true , correct?
(Adding && TradeHour in my Buy/Sell statement)
Negating the following statement:

Code:
if(Hour()>=12 && Hour()<17) 
    TradingEnabled=true;
is

Code:
if(Hour()<12 || Hour()>=17)
    TradingEnabled=false;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1144 (permalink)  
Old 08-08-2008, 02:57 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
One more thing how do I add a re-entry delay to the code so that if a trade was just opened and closed, to wait like 60 min, then check again if trade conditions are met still.
Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1145 (permalink)  
Old 08-08-2008, 08:01 PM
Junior Member
 
Join Date: Aug 2008
Posts: 7
gorgoroth is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
One more thing how do I add a re-entry delay to the code so that if a trade was just opened and closed, to wait like 60 min, then check again if trade conditions are met still.
Thank you
It's not clear what is your request.

Do you want to wait for 60 minutes between a trade condition check and the next one ?

If this is your request, may be this should work:

Code:
// Global variable
bool TradingEnabled = true; // flag to enable/disabled trading logic
bool TradingCheckDone = false; // flag to know if a a check was just done
datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....
if( !TradingCheckDone )
{
    // Default: We assume that trading logic must run ...
    TradingEnabled = true;
    // ... but only between 12:00:00 and 16:59:59
    if(Hour()<12 || Hour()>=17)
        TradingEnabled=false;
    // We must remember a check was just done
    TradingCheckDone = true;
    // We must even know when it was done
    LastCheckTime = TimeCurrent();
} else
{
    // if a hour has passed since the last check, it's time to retry 
    if( TimeCurrent() - LastCheckTime >= 3600 )
    {
        TradingCheckDone = false;
    }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1146 (permalink)  
Old 08-08-2008, 08:08 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by gorgoroth View Post
It's not clear what is your request.

Do you want to wait for 60 minutes between a trade condition check and the next one ?

If this is your request, may be this should work:

Code:
// Global variable
bool TradingEnabled = true; // flag to enable/disabled trading logic
bool TradingCheckDone = false; // flag to know if a a check was just done
datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....
if( !TradingCheckDone )
{
    // Default: We assume that trading logic must run ...
    TradingEnabled = true;
    // ... but only between 12:00:00 and 16:59:59
    if(Hour()<12 || Hour()>=17)
        TradingEnabled=false;
    // We must remember a check was just done
    TradingCheckDone = true;
    // We must even know when it was done
    LastCheckTime = TimeCurrent();
} else
{
    // if a hour has passed since the last check, it's time to retry 
    if( TimeCurrent() - LastCheckTime >= 3600 )
    {
        TradingCheckDone = false;
    }
}
No, only if a Trade just happened and closed then I want the EA to wait an hour then check if trade conditions are still met, if they are, then ok, trade again but if not so be it. This code will do what I want then? Will this work in the tester due to the TimeCurrent check?

EDIT: not every hour do the check just after a trade is closed then wait an hour for a condition check and that is it. Then if in a day another Trade is generated and closed then wait again an hour and if no signal then that's it no more waiting checks until the next trade open and close.
Thank you

Attached is a little EA if you could modify it with the right settings that I mentioned. Thanks
Attached Files
File Type: mq4 OZFx_Method.mq4 (10.3 KB, 5 views)

Last edited by matrixebiz; 08-08-2008 at 08:43 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1147 (permalink)  
Old 08-11-2008, 02:30 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Buy_Limit and Buy_Stop

What is the difference between a Limit order and a Stop order?
Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1148 (permalink)  
Old 08-12-2008, 08:52 AM
Junior Member
 
Join Date: Aug 2008
Posts: 7
gorgoroth is on a distinguished road
Quote:
Originally Posted by gorgoroth View Post
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 ?
No one has problems returning string from DLLs ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1149 (permalink)  
Old 08-12-2008, 11:29 AM
Senior Member
 
Join Date: Oct 2006
Posts: 104
antone is on a distinguished road
I need help..

Can anyone show me a code? to attach to my EA..

One order per signal.. cause sometimes i have 3 signal cause of different TF.. i want all signal to open..

or a code that would take one order per bar but each Timeframe attach to one EA.. don't want to open alot of chart..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1150 (permalink)  
Old 08-12-2008, 12:35 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
What is wrong with my BuyStop?
Code:
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);
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 12:13 PM.



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