Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-24-2009, 04:51 AM
Junior Member
 
Join Date: Mar 2009
Posts: 1
samuelabyrd is on a distinguished road
EA Opening Too Many Trades

Hello all, first of all I've searched this site for an answer to my question and not found a clear answer.

I'm using Expert Advisor Builder for Meta Trader 4 Expert Advisor Builder for MetaTrader 4 to create an EA. The problem I have is that the EA opens a trade whenever:

A. the defined rules for opening a trade at the beginning of a new bar (ex. 1 hour) are true.

AND

B. if a trade opened as a result of the above has closed, and the defining bar (ex. 1 hour) is still active.

I'd like to know how to script or define additional rules so the EA will not continually open trades, within the same bar, if a trade had already been opened based upon the rules. I guess another way to state it is how do limit the EA to opening no more than one trade per hour or defined time frame or bar.

Thanks in advance to anyone who can offer a clear concise solution.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 05-24-2009, 05:13 AM
auto's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Tokyo
Posts: 237
auto is on a distinguished road
Lightbulb Hourly Magic

There are many way to do it .. but the simplest way to limit 1 trade per hour is to use ..

int Fixed = 100;
int MagicNumber = Fixed + Hour();


and check for orders with that magic no. before sending new orders.

regards.
__________________
TAME THE BEAST - Free EA & Indicators
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 05-24-2009, 11:05 AM
davidke20's Avatar
Senior Member
 
Join Date: Sep 2006
Location: 38° 53′ 51.61″ N, 77° 2′ 11.58″ W
Posts: 1,492
davidke20 is on a distinguished road
Code:
 
extern double TakeProfit=10;
extern double StopLoss=10;
extern MagicNumber=772188;
datetime Stamp=0;
 
int start()
{
  double MA1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0);
  double MA2=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
  double MA3=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,1);
  double MA4=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);
// MA crossed
if(MA1>MA2 && MA3<MA4 && Stamp!=iTime(NULL,0,0))
{
   result=OrderSend(OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,NULL,MagicNumber,0,Red)
   if(result>1)
Stamp=iTime(NULL,0,0);
return(0);
}
}
The Stamp will limit you 1 trade / bar. Hope this help.

Regards,

David
__________________
"All through time, people have basically acted and reacted the same way in the market as a result of: greed, fear, ignorance, and hope. That is why the numerical formations and patterns recur on a constant basis." - Jesse Lauriston Livermore

THE FOREX KNIGHT
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 05-24-2009, 11:25 AM
auto's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Tokyo
Posts: 237
auto is on a distinguished road
Quote:
Originally Posted by davidke20
The Stamp will limit you 1 trade / bar.
.. as long as the MT4 is not restarted.
__________________
TAME THE BEAST - Free EA & Indicators
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 05-25-2009, 09:47 AM
davidke20's Avatar
Senior Member
 
Join Date: Sep 2006
Location: 38° 53′ 51.61″ N, 77° 2′ 11.58″ W
Posts: 1,492
davidke20 is on a distinguished road
Quote:
Originally Posted by auto View Post
.. as long as the MT4 is not restarted.
Yes. MT4 restart may cause it to fire up another trade if it happened within the same hour. However, this can avoid complication of having different magic number every hour. Such as:

Magic + 13 hour = 18000 + 13 = 18013

If current hour is 14:00, magic number had automatically changed to 18014. Trailing stop not function until next day's 13:00. No worries, this is not a debate. May be you prefer changing magic number.

Regards,

David
__________________
"All through time, people have basically acted and reacted the same way in the market as a result of: greed, fear, ignorance, and hope. That is why the numerical formations and patterns recur on a constant basis." - Jesse Lauriston Livermore

THE FOREX KNIGHT
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
I need an indie that reads the closed trades in the history tab... not open trades ElectricSavant Indicators - Metatrader 4 28 01-30-2009 04:12 AM
Trade after opening? AirforceMook Suggestions for Trading Systems 0 06-15-2008 11:13 PM
Market opening and close indicator svirgo Indicators - Metatrader 4 0 06-22-2007 07:59 PM
Market opening times SloForeX Indicators - Metatrader 4 1 04-20-2007 09:49 AM
Problem Opening Sell Trades With Stop Loss sbwent Metatrader 4 2 03-12-2007 12:44 AM


All times are GMT. The time now is 04:34 PM.



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