stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

How to send a pending order after open a trade
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4916
Page 1 of 2
Author:  fxcba [ Mon Sep 26, 2016 12:05 am ]
Post subject:  How to send a pending order after open a trade

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
Author:  renexxxx [ Mon Sep 26, 2016 6:33 am ]
Post subject:  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:

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
   }
(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.
Author:  fxcba [ Mon Sep 26, 2016 10:20 am ]
Post subject:  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
Author:  renexxxx [ Mon Sep 26, 2016 12:26 pm ]
Post subject:  How to send a pending order after open a trade

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
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.
Author:  fxcba [ Mon Sep 26, 2016 12:50 pm ]
Post subject:  How to send a pending order after open a trade

Thank you my friend I'll try it.
Author:  fxcba [ Wed Nov 02, 2016 4:36 pm ]
Post subject:  How to send a pending order after open a trade

Hello, it's me asking for some help :oops: again

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); 
Why in the above code I get this error?
'rsibuf' - parameter conversion not allowed R_Cross.mq4 71 23
Author:  tomele [ Wed Nov 02, 2016 5:38 pm ]
Post subject:  How to send a pending order after open a trade

Hi.

rsibuf is no array.
Author:  fxcba [ Wed Nov 02, 2016 6:22 pm ]
Post subject:  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?
Author:  tomele [ Wed Nov 02, 2016 6:39 pm ]
Post subject:  How to send a pending order after open a trade

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?
Declare rsibuf as array by "double rsibuf[]"
Then fill it with "rsibuf[shift]=iRSI(NULL,0,RSIbarsPeriod,PRICE_CLOSE,shift);"
Now you can do "iMAOnArray(rsibuf...)"
Author:  fxcba [ Wed Nov 02, 2016 6:45 pm ]
Post subject:  How to send a pending order after open a trade

Thank you very much tomele.
I can't get that stuff yet
Thanks again
All times are UTC Page 1 of 2