How to code? - page 80

 
 

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.

 
jturns23:
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

 
jturns23:
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: -

https://www.forex-tsd.com/forum/commercial-talks/9512-complaints-and-brokers-scam#comment_273270

 

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!

 

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);

}

}

}

 
ys16:
... 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.

 
Michel:
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.

 
ys16:
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.

 

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?

Reason: