• Sign up >>

Opening Pending Order ???

To add comments, please log in or register
Filip
11
Filip  
Hello,
I have only the below code in the start() function of EA, but the problem is that the code always throws the error message - "Error". Could somebody give me any advice? How can I open pending order ? Thank you.

int Ticket=OrderSend(Symbol(),OP_BUYSTOP,0.1,1.2175,0,0,0,"macd sample",16384,0,CLR_NONE); if(Ticket<0) { Alert("Error!"); return(0); }
Fishtank
17
Fishtank  
This is the sample from the help file in the API

ticket=OrderSend(Symbol(),OP_BUYSTOP,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384, 0,Green);

If you cut and past that into your code it will work. Then you can make changes to it to make it more like how you want it. Only change one thing at a time though and test it to see if it still works.

You will learn the basics of it pretty quick that way.

First thing I would change on your code though is the Slippage value. Change that to 5 or so.

One thing that took me a day or two to realise at the start is that 0 slippage means the price of the pair has to hit directly on your 1.2175. Just because the bar passes through that point, doesn't mean the price hit it. It can skip your price and continue in the direction you want without triggering your trade.
Filip
11
Filip  
Yes, I have that kind of problem... I wanted to start my trade at ,let's say, 1. 2175, and when the Bid becomes 1.2175 the trade is not triggered, it's triggered at 1.2176.
So you say if I change the slippage value from 0 to 5, the trade will be triggered when the Bid becomes 1.2175 ???
Thank you!
Filip
11
Filip  
In fact it is the OrderClose() function, which doesn't work properly.

OrderClose(Ticket,0.1,Bid,3,CLR_NONE);


If I want to close the order at Bid, it doesn't close at Bid price but at the Bid + 0.0001. Why it happens that way?
cockeyedcowboy
524
cockeyedcowboy  
Minev:
Hello,
I have only the below code in the start() function of EA, but the problem is that the code always throws the error message - "Error". Could somebody give me any advice? How can I open pending order ? Thank you.

int Ticket=OrderSend(Symbol(),OP_BUYSTOP,0.1,1.2175,0,0,0,"macd sample",16384,0,CLR_NONE); if(Ticket<0) { Alert("Error!"); return(0); }
to get error message chenge the alert statement to

Alert( "Error", GetLastError() );

this will show the error that was generated.
also you may want to change the

if( Ticket < 0 ) {

to

if( Ticket < 1 ) {

as one is not an error that will cause any problems.

The CockeyedCowboy
Fishtank
17
Fishtank  
unfortunately i didn't mean it would enter at 1.2175, I meant it would enter within 5 price points of 1.2175, if the Slippage was set to 5.

Normally a few pips either side of your entry point is not a big deal, and if the trade can ONLY enter at 1.2175, you will probabaly miss alot of opportunities that you want to trade on.

Say the market was moving upward, and each tick the pice moved as follows:

1.2167
1.2171
1.2174
1.2176
1.2182

Your trade will not be triggered with 0 slipp, even though the BAR on the chart did move through the 1.2175 price point.
Which is why you will have 0 as a value for your ticket, and why you will get an error returned as a result, and CockeyedCowboy was right, you probably want to use his suggestion as well.
To add comments, please log in or register