Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4






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
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-2007, 05:41 AM
Junior Member
 
Join Date: Aug 2006
Posts: 3
joko75 is on a distinguished road
How to stop expert advisor from trading, when profit is made

Hi I have written a code for auto trade in Expert Adviser. My autotrade work fine. it open trade and close trade.
My problem is, when a buy / sell position is closed. The EA automatically open another position in fewminitues, or in few hours time. That cause me to lost a lot of money, as the EA trade too frequently and too unecessary.

How to I stop the EA from executing buy & sell order, when I have made my profit for the day.
I have use the Sleep(1440000) command, but it doestn't work at all.
Example, if I have already made 50 pips profit for the day. I want to stop the EA from trading further.

As I cannot monitor the system 24 hrs a day, thus I written a automation program. I do expect some command to stop the EA from executing trade, once the profit is made for the day.

Susilo
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-26-2007, 06:20 AM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 438
ryanklefas is on a distinguished road
The only way I can think of it to read the order history and disallow new trades if orders have been placed within X hours. I'm sure there is an easier way to do it, but I don't know of any.
__________________
"Don't work harder, work smarter." -- my Java professor

Advertise on The All New FireCell Network
"Where online investing makes sense"

Coder for Hire:
http://firecell.info
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-27-2007, 02:51 AM
Senior Member
 
Join Date: Aug 2006
Posts: 104
tururo is on a distinguished road
Before placing an order, read all the completed orders for the day, adding up OrderProfit(). The profit will be in dollars. If the target has been reached then don't open another order.
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-27-2007, 03:05 AM
Junior Member
 
Join Date: May 2007
Posts: 21
eastcity is on a distinguished road
ryanklefas,

couldn't your Swiss Army EA be used for this purpose?

(by the way, this is my first post....)
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-27-2007, 03:44 AM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 438
ryanklefas is on a distinguished road
Quote:
Originally Posted by eastcity
ryanklefas,

couldn't your Swiss Army EA be used for this purpose?

(by the way, this is my first post....)
Yes and no. It COULD be used in that fashion, but it doesn't currently read historic orders and also has no direct control over other EAs; I may in time be able to make it capable of telling other EAs what they can and cannot do.
__________________
"Don't work harder, work smarter." -- my Java professor

Advertise on The All New FireCell Network
"Where online investing makes sense"

Coder for Hire:
http://firecell.info
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
  #6 (permalink)  
Old 05-27-2007, 05:10 AM
lowphat's Avatar
Senior Member
 
Join Date: Sep 2005
Posts: 200
lowphat is on a distinguished road
one way is to declair a bool at the top or in init? to kill it after one trade if it won or lost but there is prolly a better way
then hitting the reset button i would think should start it over to make one trade again
int init()
bool stoptrade=false
_____________________


if (stoptrade==false)
{
if (logic)sell
if (logic)buy
stoptrade=true
}

Last edited by lowphat; 05-27-2007 at 05:14 AM.
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
  #7 (permalink)  
Old 05-27-2007, 05:48 AM
ryanklefas's Avatar
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 438
ryanklefas is on a distinguished road
Quote:
Originally Posted by lowphat
one way is to declair a bool at the top or in init? to kill it after one trade if it won or lost but there is prolly a better way
then hitting the reset button i would think should start it over to make one trade again
int init()
bool stoptrade=false
_____________________


if (stoptrade==false)
{
if (logic)sell
if (logic)buy
stoptrade=true
}
Simple. And it could work. Then you could reset the boolean when a new day starts, at say:

Hour()==0 and Minute()==0.
__________________
"Don't work harder, work smarter." -- my Java professor

Advertise on The All New FireCell Network
"Where online investing makes sense"

Coder for Hire:
http://firecell.info
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
  #8 (permalink)  
Old 05-27-2007, 09:42 AM
HerbertH's Avatar
Member
 
Join Date: May 2006
Posts: 88
HerbertH is on a distinguished road
Quote:
Originally Posted by ryanklefas
Simple. And it could work. Then you could reset the boolean when a new day starts, at say:

Hour()==0 and Minute()==0.
Ryan, ticks do not always arrive at least once every minute. When that happens at 00:00, this would skip this EA to trade that day.

Perhaps it's batter to compare the daily bar timestamp: iTime(NULL,PERIOD_D1,0)


Lowphat's code would then be something like:


int init()
bool stoptrade=false;
datetime DailyBar=0;

if (stoptrade==false && DailyBar != iTime(NULL,PERIOD_D1,0))
{
if (logic)sell
if (logic)buy
stoptrade=true
DailyBar=iTime(NULL,PERIOD_D1,0);
}
__________________
Better being out wishing to be in, than being in wishing to be out.....
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
  #9 (permalink)  
Old 05-27-2007, 12:51 PM
european's Avatar
Senior Member
 
Join Date: Apr 2006
Posts: 282
european is on a distinguished road
if init() executes only once when EA started then it is of no use if one wants an EA to resume working say in 10 minutes.

Unfortunately there is also a problem with OrderCloseTime() when a new tick happens immediately after an order was closed.

euro
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
  #10 (permalink)  
Old 05-27-2007, 01:16 PM
HerbertH's Avatar
Member
 
Join Date: May 2006
Posts: 88
HerbertH is on a distinguished road
Quote:
Originally Posted by european
if init() executes only once when EA started then it is of no use if one wants an EA to resume working say in 10 minutes.

Unfortunately there is also a problem with OrderCloseTime() when a new tick happens immediately after an order was closed.

euro
Init() is only used to initialize the variables. This is intended to only be executed once.
To use this mechanism for shorter periods of restart time you could use the lower bartime like 15 or 30 minutes. e.g. iTime(NULL,PERIOD_M15,0)

For the OrderCloseTime() you are right; when just before the bar changes, the order is closed.
This depends however on how "next period" is defined.
If you want to restart at 24:00 just use the daily bar.
If you want to restart 24 hours after the last order was closed, then use 24 "hour-bars"

Cheers
__________________
Better being out wishing to be in, than being in wishing to be out.....
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

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
CCI Expert Advisor rodrigokaus Expert Advisors - Metatrader 4 26 07-20-2009 06:36 AM
RSI Expert Advisor TF2K Suggestions for Trading Systems 5 03-21-2009 05:24 PM
rocks advisor 100% profit yossi1177 Expert Advisors - Metatrader 4 15 07-05-2007 03:08 AM
What Expert Advisor are they using? fikko Expert Advisors - Metatrader 4 4 07-01-2006 09:47 AM


All times are GMT. The time now is 01:15 PM.



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