Hello all, I've made an EA (a very basic one) but it opens trades as I want to, now I want the EA put a pending order if a trade is opened. I've been searching in forum with no success yet, if this has been discussed please guide me and if is not, any advise is wellcome.
Thank you
How to send a pending order after open a trade
-
- Trader
- Posts: 46
- Joined: Wed Aug 21, 2013 10:10 pm
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
How to send a pending order after open a trade
Sending a pending order (BUY STOP, BUY LIMIT, SELL STOP or SELL LIMIT) is as easy as sending a market order. Of course you need to be aware that for a BUY STOP order the STOP price must be above the current market price, and for a BUY LIMIT order the LIMIT price must be below the current market price.
Say that you want to place a BUY STOP order after you have successfully placed a BUY (market) order, you do something like this:
(give the OrderSend parameters appropriate values).
Of course, it is prudent to build in fault tolerant code, such that the OrderSend()'s are retried if they fail. Or you can make use of the OrderReliable library.
Hopefully, this is not too confusing.
Say that you want to place a BUY STOP order after you have successfully placed a BUY (market) order, you do something like this:
Code: Select all
int ticket = OrderSend( _Symbol, OP_BUY, lotSize, Ask, slippage, stopLoss, takeProfit, "MyComment", magicNumber, 0, clrGreen ); // This is the Market Order
if ( ticket > 0 ) {
ticket = OrderSend( _Symbol, OP_BUYSTOP, pendingLotSize, pendingPrice, slippage, pendingStopLoss, pendingTakeProfit, "PendingComment", magicNumber, 0, clrGreen ); // The is the pending BUY STOP order
}
Of course, it is prudent to build in fault tolerant code, such that the OrderSend()'s are retried if they fail. Or you can make use of the OrderReliable library.
Hopefully, this is not too confusing.
-
- Trader
- Posts: 46
- Joined: Wed Aug 21, 2013 10:10 pm
How to send a pending order after open a trade
hello renexxx, thank you for your kind answer, I'm afraid I wasn't clear on my request.
My EA opens on the market trades correctly as I wish, now I want to: after a trade is open to put a new pending order using the code you provide. I don't know how to make EA recognize the new open trade and subsenquentely launch the pending order. In fact is a recovery loss order so if trade goes wrong and SL is hit that order is activated but if TP is hit or trade is closed on profit that order must be cancelled, may be there is a code for that. Thank you again
My EA opens on the market trades correctly as I wish, now I want to: after a trade is open to put a new pending order using the code you provide. I don't know how to make EA recognize the new open trade and subsenquentely launch the pending order. In fact is a recovery loss order so if trade goes wrong and SL is hit that order is activated but if TP is hit or trade is closed on profit that order must be cancelled, may be there is a code for that. Thank you again
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
How to send a pending order after open a trade
I think the question is about how to detect if an existing order has hit TP or SL. Unfortunately, Empty4 doesn't send an event, can you listen for, and handle in a OnTakeProfit() or OnStopLoss() event handler. Instead, you need to 'poll' constantly, to see if the status of in existing order has changed. The attached code is an example of how you can do this. Hope this helps.fxcba » Mon Sep 26, 2016 8:20 pm wrote:In fact is a recovery loss order so if trade goes wrong and SL is hit that order is activated but if TP is hit or trade is closed on profit that order must be cancelled, may be there is a code for that. Thank you again
You do not have the required permissions to view the files attached to this post.
-
- Trader
- Posts: 46
- Joined: Wed Aug 21, 2013 10:10 pm
How to send a pending order after open a trade
Thank you my friend I'll try it.
-
- Trader
- Posts: 46
- Joined: Wed Aug 21, 2013 10:10 pm
How to send a pending order after open a trade
Hello, it's me asking for some help again
Why in the above code I get this error?
'rsibuf' - parameter conversion not allowed R_Cross.mq4 71 23
Code: Select all
for(shift=limit; shift>=0; shift--)
{
rsibuf= iRSI(NULL,0,RSIbarsPeriod,PRICE_CLOSE,shift);
b4ma=iMAOnArray(rsibuf,0,MAperiod,0,MODE_SMA,shift+1);
nowma=iMAOnArray(rsibuf,0,MAperiod,0,MODE_SMA,shift);
'rsibuf' - parameter conversion not allowed R_Cross.mq4 71 23
- tomele
- Administrator
- Posts: 1166
- Joined: Tue May 17, 2016 3:40 pm
- Location: Germany, Forest of Odes, Defending the Limes
How to send a pending order after open a trade
Hi.
rsibuf is no array.
rsibuf is no array.
Happy pippin, Thomas
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
-
- Trader
- Posts: 46
- Joined: Wed Aug 21, 2013 10:10 pm
How to send a pending order after open a trade
Hello tomele, thank you for your answer, please can you give me a little more detail?, how do I need to declare rsi on iMAOnArray?
- tomele
- Administrator
- Posts: 1166
- Joined: Tue May 17, 2016 3:40 pm
- Location: Germany, Forest of Odes, Defending the Limes
How to send a pending order after open a trade
Declare rsibuf as array by "double rsibuf[]"fxcba » 02 Nov 2016, 19:22 wrote:Hello tomele, thank you for your answer, please can you give me a little more detail?, how do I need to declare rsi on iMAOnArray?
Then fill it with "rsibuf[shift]=iRSI(NULL,0,RSIbarsPeriod,PRICE_CLOSE,shift);"
Now you can do "iMAOnArray(rsibuf...)"
Happy pippin, Thomas
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so. (Mark Twain)
Keep the coder going: Donate
-
- Trader
- Posts: 46
- Joined: Wed Aug 21, 2013 10:10 pm
How to send a pending order after open a trade
Thank you very much tomele.
I can't get that stuff yet
Thanks again
I can't get that stuff yet
Thanks again