Any help would be appreciated.
It may not be your actual problem, but I would start with the following line:
if (OrderType()!=OP_BUY || OrderType()!=OP_SELL)
This condition is always true. It is meaningless. For example, if OrderType() is "buy", then the condition means "if buy is not buy or buy is not sell...".
I suspect that what you actually mean is a way of ignoring open trades and only looking at pending orders:
if (OrderType()!=OP_BUY && OrderType()!=OP_SELL)
For the record, because of the numeric values of OP_BUY (0) and OP_SELL (1), you will often see the same condition written as follows in MQL4 code:
if (OrderType() > OP_SELL) // i.e. value of OrderType() must be 2 or more; one of the OP_ limit or stop values
me think that well there isn't a an OrderOpenPrice() since it has not yet opened. If thats the case then how do i reference the Price of a Pending Order?
OrderOpenPrice() gives you either the future entry price of a pending order, or the fill price of an open trade, depending on the prior OrderSelect() context. You are looking at the correct value.
I don't immediately see a problem in the code which you have posted which will cause it to increase the entry price of a pending order rather than decreasing it. Your broker won't like you, because you are repeatedly deleting and replacing orders each time there is the tiniest downward movement in the price. But I'm failing to see an actual problem in the logic (assuming that "gap" is constant across each pass through this code). Someone else may do better.
Rather than always deleting and replacing, it would be preferable to do the following:
- If RSI is above 50...
- If the current order is a sell stop, delete and replace with a buy stop
- If the current order is a buy stop, and the revised entry price is lower, use OrderModify() to change the entry price and s/l, rather than deleting and replacing.
The only difference between that and your current route is that it will not re-evaluate the lot size on each downward movement in the price. In effect, it will only re-evaluate the lot size when the RSI signal changes from >50 to <50.
- The OOP is the pending price and will become the open price when triggered.
- Your posted code doesn't have a OrderModify in it. Don't delete and create a new one. Find the pending price see if you want to move it lower (buy stop) modify it. Look at any trailing SL code and reverse the logic.
- Alternatively, Humans can't watch the screen 24/7 so they use pending orders; EAs can, so no need for pending orders, have it
wait until the market reaches the trigger price and open an order.
OrderOpenPrice() gives you either the future entry price of a pending order, or the fill price of an open trade, depending on the prior OrderSelect() context. You are looking at the correct value.
I don't immediately see a problem in the code which you have posted which will cause it to increase the entry price of a pending order rather than decreasing it. Your broker won't like you, because you are repeatedly deleting and replacing orders each time there is the tiniest downward movement in the price. But I'm failing to see an actual problem in the logic (assuming that "gap" is constant across each pass through this code). Someone else may do better.
Rather than always deleting and replacing, it would be preferable to do the following:
- If RSI is above 50...
- If the current order is a sell stop, delete and replace with a buy stop
- If the current order is a buy stop, and the revised entry price is lower, use OrderModify() to change the entry price and s/l, rather than deleting and replacing.
The only difference between that and your current route is that it will not re-evaluate the lot size on each downward movement in the price. In effect, it will only re-evaluate the lot size when the RSI signal changes from >50 to <50.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am trying to Modify or Delete the old Order and Create a new Order for a Pending order if prices moves in my favor giving me a better entry price.
Initially I want to open a BuyStop 5pips above the current Ask. Then if price moves lower keep reducing the gap maintaining a 5 pip gap. If price moves up, then do not change the "Trigger Price"
I am unable to make it do this as reading the journal entries sometimes it is also increasing the price of the trigger when it should only ever reduce it.
Any help would be appreciated. As it seems that I am using OrderOpenPrice() for a pending order, making me think that well there isn't a an OrderOpenPrice() since it has not yet opened. If thats the case then how do i reference the Price of a Pending Order?