ordersend() coding help... - page 3

 
mugged:

Raptor, if you dont mind... how were you planning on checking for connectivity via php?

What I had in mind was this:

The EA will send a small file via FTP every 2 mins (could be 5 mins, 30 mins, whatever your tolerance is . . * ) to my Hosted Webserver, running on that Webserver will be a Cron job that looks for the file received via FTP and checks if it has been updated in the last 2 mins * if it hasn't it sends me an alert email.

 
SDC:
I"ve always done it that way because that is how they do it in the MQL4 book examples but now I'm thinking that doesnt look correct, surely if you open on the Ask price you want to take profit at that price + your TP amount, and you want to stop out at that price - your SL amount ?

If you want to stop at price-x. What does that mean? Do you want to stop when the Bid reaches price-x (or when the Ask reaches it.)

If you want a 3 pips SL on a buy and use Ask - 3*pips2dbl. The moment you open you are now 1 pip away (assuming a 2 pip spread.) Again depends on your definition

If you mean when Bid reaches price-x, on a buy your SL would be price-x. But on a Sell you still want to stop at price-x but the trigger price must be relative to the ask. price-x+spread.

What do you do when the spread changes? On a Sell, that means to close at the same position (a Bid) you must modify TP/SL. Depends on your definition.

What I do is do ALL calculations relative to the Bid, and adjust at the end.

//want to open at P
if (OP == OP_BUY)  double bid.to.open = Ask-Bid, bid.to.stop = 0,       DIR=+1.;
else                      bid.to.open = 0;       bid.to.stop = Ask-Bid; DIR=-1.;
:
if ((Bid - P) *DIR >= 0.){ // Time to open
  double openPrice = Bid + bid.to.open,
  OrderSend(NULL, OP, v, Bid+bid.to.open...)
 
WHRoeder:

My approach is to just report the error and return.

My concern is that I have an open order with SL & TP = 0 and my EA has no connection to the Internet . . . . I'd rather be alerted to this possibility even if my EA is on a VPS or my own colocated server.
 

Not disagreeing with that, I did say "report the error."

There's just nothing the EA can do with isConnected()==false but wait.

There's just nothing the EA can do with ERR_TRADE_TIMEOUT but wait and then see.

Returning from start and waiting for the next tick and then recovering is the easiest.

 
WHRoeder:
Not disagreeing with that, I did say "report the error." There's just nothing the EA can do with isConnected()==false or ERR_TRADE_TIMEOUT but wait for the next tick and then see.
Sure, I was just making sure you understood what I was getting at, at some point I'd like a watchdog to tell me that something is not right . . . hence the cron job and PHP idea.
 
mugged:

Raptor, if you dont mind... how were you planning on checking for connectivity via php?

Maybe something like this . . .

<?php
$to = "recipient@example.com";
$subject = "EA is silent";
$body = "EA has stopped responding . . . ";

$file = 'somefile.txt';
$filetime = filemtime($file);
$timetwomins = time()-120; // two mins ago

if ($filetime < $timetwomins) {
   mail($to, $subject, $body)
}
?>
 

i guess what I will do is have an email alert just before the order triggers and then another one that confirms the stop has been changed.

so if i get the first one and the corresponding modify email doesn't come through then I know there are issues.

 
mugged:

i guess what I will do is have an email alert just before the order triggers and then another one that confirms the stop has been changed.

so if i get the first one and the corresponding modify email doesn't come through then I know there are issues.

i think send a mail after the order triggers & another one confirms the stop has been changed
 
qjol:
i think send a mail after the order triggers & another one confirms the stop has been changed

My only concern with sending the email after is what if the order triggers and then your connection dies before the mail can be sent...

The other way you have the first mail telling you something is about to trigger, and then the 2nd one confirming the stop modify.

 
RaptorUK:

Maybe something like this . . .


Raptor, I like this idea. Ive thought about it in the past but had no idea of how to go about doing it.

What I have right now is just the EA sending an email every hour confirming it is up and running. I would just need some way of checking for that mail and if it doesnt come in then send a warning. Same idea different approach i guess.