This project is read-only.

OrderSend gets "stuck"

Dec 20, 2012 at 9:54 PM
Edited Dec 20, 2012 at 9:58 PM

I've set up my entire system but I'm having a problem at this one point.  In my expert, I have three functions, Buy, Sell and Close which I call when initiating trades.  Without this.OrderSend, these methods execute perfectly, this is the code:

public void Buy(double lots, string tradeSource)
{
DateTime dateTime = DateTime.Now;

string trade_type = "LONG";
client1.SendMessage("MT4-" + pSymbol, "TM-" + pSymbol, dateTime.ToString() + "," + trade_type + ",Price:" + logPrice + "," + tradeSource);

}

But when I add OrderSend, the methods execute until the OrderSend part, then stop - that is, the method stops executing, for some reason and the order doesn't get opened on MetaTrader.

public void Buy(double lots, string tradeSource)
{

System.Windows.Forms.Messagebox.Show("Start Buy", "MB1");
DateTime dateTime = DateTime.Now;
double logPrice = 0;

Ticket = this.OrderSend(this.Symbol(), ORDER_TYPE.OP_BUY, lots, this.Ask(), 0, 0, 0);

System.Windows.Forms.Messagebox.Show("Buy Success", "MB2");

string trade_type = "LONG";
client1.SendMessage("MT4-" + pSymbol, "TM-" + pSymbol, dateTime.ToString() + "," + trade_type + ",Price:" + logPrice + "," + tradeSource);
}

Ticket is a global integer that I initialize to 0 in the Init function.   I left the message boxes in for error tracing.  MB1 executes, MB2 doesn't.  I can't seem to find any error logs and I've run out of ideas as to what could be causing this. Can anyone help?

I'm using 2.0 beta, but I've tried on both 1.2.4 and 1.2.3 and I kept on having the same problem.

Thanks.

Seth.

Dec 21, 2012 at 3:59 PM

About to look at sending orders - can one only send an order when a quote is fired? Kinda like it works in MT4? Or is it possible to store the last <QuoteListener mql> object and use this. i.e. I have an external app with its own Order Manager which could trigger a new order outside of the context of the tick event.

Seth is your OrderSend being triggered within the Quote_Received event?

Kick

Dec 22, 2012 at 8:35 AM
Edited Dec 22, 2012 at 8:36 AM

Hi Kick

No, it's not being triggered within the quote received event.  I've just overhauled my code to use WCF.  In my last expert, I had the expert poll a MySql database for trades every time the Start() method fired.  I had OrderSend in it's own methods - that is, I had a method for buy, short and close and these were called depending on the trade signal received from MySql.

Also, the WCF I set up is the "standard" Windows one, where I've set up my own server and the expert and my charting package are the clients.  I'm not using the WCF from the TradePlatform libraries, so I don't use QuoteListener mql.  My setup works perfectly until I add OrderSend.  It's weird, it doesn't bring up any errors, it just doesn't execute.

Seth

Dec 26, 2012 at 11:31 AM

I think it has too, like happens in MT4 itself - but this is in effect the Start event so you should be fine. Maybe try use the Quote_Received event and do the order send from the mql parameter received.

Jan 2, 2013 at 9:37 PM

 

Hi Kick

Managed to change my code around, now I have my TradePlatform dll check for a text file each time start is called.  It works brilliantly.  It's just on Enter Long and Enter Short trades, it just doesn't open the trade, so my Ticket variable isn't being changed (I haven't written any error handling code in the trade methods to check if a trade ticket is assigned).  It's late now, I've been at it for over two hours.  Tomorrow I'll write some error handling code, see if it's anything I can pick up then report back.

Thanks for your ideas.

Seth

Jan 3, 2013 at 9:29 AM

 

Ok, I don't really know what I did...but it's working now.

Reminds me of a funny picture I saw of a programmer who's looking confused and the caption says, "I don't know why my code doesn't work."  Then the next frame has the exact same picture except the caption this time is, "I don't know why my code works."  Guess it happens like that sometimes.

Thanks for all the advice, Kick.  Turns out the OrderSend DOES only work during the Start() method call.  

Seth