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
  #791 (permalink)  
Old 04-01-2008, 05:42 AM
Senior Member
 
Join Date: Sep 2007
Posts: 310
jturns23 is on a distinguished road
Hiding Stoploss

Could anyone tell how how to hide stoplosses and trailing stops in an EA? (I don't like the idea of brokers seeing my stoplosses or trailing stops, it's like a target for them). Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #792 (permalink)  
Old 04-01-2008, 08:09 AM
Member
 
Join Date: Jan 2006
Posts: 56
hiachiever is on a distinguished road
Quote:
Originally Posted by jturns23 View Post
Could anyone tell how how to hide stoplosses and trailing stops in an EA? (I don't like the idea of brokers seeing my stoplosses or trailing stops, it's like a target for them). Thanks.
Simple in your code you define a stopvalue and a target value.
Then after you place a trade obtain the price that you entered the trade at, and then with each new each tick check to see if either your stop or your target has been hit.

If has been hit then have the EA execute the OrderClose function.

Personally, I still have a stop that the broker can see though it is set a long way from the price action 50-100 pips. In this way if the terminal goes down for some reason, you are at least protected against any sudden moves.

Cheers,
Hiachiever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #793 (permalink)  
Old 04-01-2008, 11:10 AM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by jturns23 View Post
Could anyone tell how how to hide stoplosses and trailing stops in an EA? (I don't like the idea of brokers seeing my stoplosses or trailing stops, it's like a target for them). Thanks.
What you are seeking to implement are most often called 'soft-stops', where you dynamically track P&L, closing order(s) when the required target(s) are reached - as opposed to placing 'hards-stops', which the broker can see and spike...

A hard-stop of some degree is essential imo (for the 'just-in-case' scenario..) but even this won't save you if you have a completely unscrupulous broker - such as Fxopen: -

Brokers Scam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #794 (permalink)  
Old 04-02-2008, 03:39 AM
Junior Member
 
Join Date: Mar 2008
Posts: 8
ys16 is on a distinguished road
a difficult question!

dear all

I am new for programming on MT4. I finished an EA code but when I tested it, there were some errors One is, my code want to open 4 orders nearly at the same time and at the same price, but my EA just sometimes can open altogether but the other situations are, the orders were just opened one by one and at different price.

Do you think I can solve this problem by using

if(IsTradeAllowed()==false) Sleep(10000);

could you all help me to fix this problem?

Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #795 (permalink)  
Old 04-02-2008, 10:47 AM
Junior Member
 
Join Date: Mar 2008
Posts: 8
ys16 is on a distinguished road
This is my function to close all positions. I think it is very simple. but the EA always spend long time to close all positions which means the close price may vary.

could you help me solve the problem?

thanks in advance!


void close_all_position_now(int total_order)
{
int ticket=0;
double volume=0, price=0;
for(int i=0;i<total_order;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false )
break;

// OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber()==magic_number && OrderType()==0)
{
ticket=OrderTicket();
volume=OrderLots();
price=Bid;
OrderClose(ticket,volume,price,slippage,CLR_NONE);
}
else if (OrderMagicNumber()==magic_number && OrderType()==1)
{
ticket=OrderTicket();
volume=OrderLots();
price=Ask;

OrderClose(ticket,volume,price, slippage,CLR_NONE);
}
else if(OrderMagicNumber()==magic_number && OrderType()>=2)
{
ticket=OrderTicket();
OrderDelete(ticket);
}


}
}

Last edited by ys16; 04-02-2008 at 11:04 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #796 (permalink)  
Old 04-02-2008, 05:39 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by ys16 View Post
... but the EA always spend long time to close all positions which means the close price may vary.
...}
The ways to close many positions a the same price are only two:
1) They have the same TP (or SL).
2) Open an opposite position with a size of the total lots you want to close. Later you can do some CloseBy().

Opennig several positions at the same price is the same problem : or you use pendings, or you open only one position of the total of lots, and you manage eventually partial closings.

Last edited by Michel; 04-02-2008 at 05:41 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #797 (permalink)  
Old 04-02-2008, 11:11 PM
Junior Member
 
Join Date: Mar 2008
Posts: 8
ys16 is on a distinguished road
Quote:
Originally Posted by Michel View Post
The ways to close many positions a the same price are only two:
1) They have the same TP (or SL).
2) Open an opposite position with a size of the total lots you want to close. Later you can do some CloseBy().

Opennig several positions at the same price is the same problem : or you use pendings, or you open only one position of the total of lots, and you manage eventually partial closings.


Dear Michel,
Thank you very much. how about the cost? do I need to pay for the spread of the opposite positions?

what is the reason that the EA cannot close all positions at the very short time? is it because that the close orders need some time to be executed.
sometimes, the 3 positions could be closed after one price change but sometimes only 1 position can be closed.

Do you have some resources related to MQL4 programming? I did not know the time scale to execute the EA.

I really know the C programming because I am an engineer, but my EA cannot fully execute what I have programmed.

How about
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==magic_number && OrderType()==OP_BUY)

Do you think this kind of function takes very long time to execute which is longer than the each cycle of EA.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #798 (permalink)  
Old 04-03-2008, 09:09 AM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by ys16 View Post
Dear Michel,
Thank you very much. how about the cost? do I need to pay for the spread of the opposite positions?

what is the reason that the EA cannot close all positions at the very short time? is it because that the close orders need some time to be executed.
sometimes, the 3 positions could be closed after one price change but sometimes only 1 position can be closed.

Do you have some resources related to MQL4 programming? I did not know the time scale to execute the EA.

I really know the C programming because I am an engineer, but my EA cannot fully execute what I have programmed.

How about
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==magic_number && OrderType()==OP_BUY)

Do you think this kind of function takes very long time to execute which is longer than the each cycle of EA.
Many brokers allow a "full hedging", this means that the used margin is calculated on the difference between the long positions and the shorts ones. Therefore there is no used margin for a fully hedged position, and you can close both (one by the other one) without additional spread. So you spend only one spread if you cole a position normally or by opening an opposite one.

About the time, the execution time of the code is very fast and has nothing to do with the broker's dealing desk time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #799 (permalink)  
Old 04-03-2008, 09:49 AM
MrM MrM is offline
Member
 
Join Date: Jul 2007
Posts: 75
MrM is on a distinguished road
expert on offline chart

Hi,

I'm trying to use an EA on offline chart (for example such as created by period_converter). They don't recive ticks which needs to use while() loop inside. However, after a few minutes the offline charts shows "Waiting for update" and is not updated anymore. I suspect it is a kind of deadlock, because when I open another offline chart then it is updated correctly, and when I close it the original chart is OK for a while untill the next "Waiting for update" lockout.

Am I doing something wrong or is this a problem of MT4?
__________________
tensigma.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #800 (permalink)  
Old 04-06-2008, 01:08 PM
arsenic786's Avatar
Member
 
Join Date: Mar 2007
Posts: 86
arsenic786 is on a distinguished road
Thumbs up Help Needed

Hello all coders,

Please tell me the code how can I check the price according to candles. I mean how can I check that the current candle touches the MA line or not? and how Can I code that the current candle has open, high, low and close below the MA line. You help will be much appreciated.

Best Regards.......!
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:28 PM.



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