Simplify, the values you're passing to the OrderModify().
bool OrderModify(
int ticket,
double price,
double stoploss,
double takeprofit,
datetime expiration,
color arrow_color
)
int myTicket=x[j];
double myPrice=Ask + 2*iATR(NULL,PERIOD_M5,14,NULL)...........<What> try OrderOpenPrice().
At this point, appears like you forgot the Price parameter and jumped to OrderStopLoss.
double Sl=Ask-2*iATR(NULL,PERIOD_M5,14,NULL);
double Tp=Ask + 2*iATR(NULL,PERIOD_M5,14,NULL);
Anyways, your command should look more like:
OrderModify(myTicket, OrderOpenPrice(), Sl, Tp, 0, 0);As is, its just messy.
x[i] = OrderSend(NULL,OP_BUYSTOP, lots, Ask, 0, iLow(NULL, PERIOD_M5,1), 1000,NULL,CLR_NONE);
i++;
for(j=0; j < i; j++)
OrderModify(x[j], Ask + 2*iATR(NULL,PERIOD_M5,14,NULL), Ask-2*iATR(NULL,PERIOD_M5,14,NULL),0, NULL, CLR_NONE);
I use an array to store the pending stops ticket numbers, and then used ordermodify to modify the trade. Is there anything wrong?
What happens to your array if the EA. MT4 or PC crash ? is it stored in a file that you re-load when your EA restarts ?
What if the OrderSend() fails ? you will have a ticket number of -1 in your array . . . read this: What are Function return values ? How do I use them ?
Don't use NULL for Expiration, use 0
Hi Ubzen, thanks. I am trying to modify using at the start of current candle, change the pending order open price; that's why I used Ask and Bid. So I can use orderopenprice in its place?
hi Raptor, thanks. So I should have a line to check the ticket to be more than 1 before I put it into the array, is the so?
The error flag you received is more than likely generated because of the Null in Expiration. Using Ask+Whatever to modify OrderOpenPrice isn't itself a bad thing. I'm just recommending making the code more readable. That way it's easier to Print the value of one variable instead of a whole mathematical equation. Couple of other things you'll need to change as you grow.
OrderSend(NULL,OP_BUYSTOP, lots, Ask, 0, iLow(NULL, PERIOD_M5,1), 1000,NULL,CLR_NONE);
- Don't use Null for Symbol. Use Symbol() instead. [More Readable].
- What broker lets you place a Pending Order @ Ask? Wouldn't Work or Becomes Mkt_Order.
- iLow(NULL, PERIOD_M5,1), another function as parameter. Create Variable Called StopLoss.
- 1000 is that your TakeProfit? Or is that your Magic#? Clarify again with variables.
- Are you checking that the OrderSend worked? Are your Ticket Array Numbers > Zero?
for(j=0; j < i; j++) OrderModify(x[j], Ask + 2*iATR(NULL,PERIOD_M5,14,NULL), Ask-2*iATR(NULL,PERIOD_M5,14,NULL),0, NULL, CLR_NONE);
- Are you checking OrderSelect before OrderModify()?
- Are you checking the Broker's Stop_Level Requirements?
- Are you making sure the New Values are Different than Current Values?
- Are you making sure its still a Pending Order, for Modifying the OrderOpenPrice?
- Are you checking Return Values and Error# or GetLastError()?
- Are you making extensive use of Print/Comment/Alert?
- Use Print to verify CheckPoints...& Display Expected Values.
Well there's probably many more things wrong with your codes.
Work them out one Error# at a time.
Hi Ubzen, many thanks for the advice.
Would take note of what you said; yup ok realised that the pending order at Ask is wrong.
1000 is just because I want to close the trade using other methods; I should use NULL instead?
may I know why is there a need to check order select before order modify?
if the pending orders are executed, am I required to use a different code if I want to modify the SL?
Thanks
hi Raptor, thanks. So I should have a line to check the ticket to be more than 1 before I put it into the array, is the so?
Amongst other things yes, did you replace NULL with 0 ? did you code checks on the return values and report all errors ? how are you recovering if your EA has to stop and restart ?
1000 is just because I want to close the trade using other methods; I should use NULL instead?
may I know why is there a need to check order select before order modify?
if the pending orders are executed, am I required to use a different code if I want to modify the SL?
1) NULL=Indicates empty state of the string. TakeProfit is not a String so don't use Null. Most people leave it as Zero or give it a Realistic Value like 300 Pips away. I understood the reason why you_did_it. The point I was trying to make is that you should not be hard-coding numbers, use variables-names instead. Rather than 1000 I would have liked to see Take_Profit. I had to Review the OrderSend Command and Think about which Parameters could be Omitted to realize that your 1000 was a High_TakeProfit instead of the Magic_#. If you want help from others, making your codes Reader-Friendly helps.
2) Because [in your case] you need to check that you have the correct OrderType among other things. Checkout the example provided in Document. It OrderSelects before OrderModify.
3) For a Non-Pending Order, If you want to modify the Stop-Loss but you submit a Code which looks like yours with a Value of Ask+whatever as Price, it'll Fail. This is another reason why you need to OrderSelect because you need the OrderOpenPrice(). Look at the example within the Document Link again.
Thanks both for your advice. I will look into them.
i am now getting another error when I backtest - invalid price 1.24985571 for OrderSend function - OrderSend error 4107.
Is it because there are too many decimal places?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
x[i] = OrderSend(NULL,OP_BUYSTOP, lots, Ask, 0, iLow(NULL, PERIOD_M5,1), 1000,NULL,CLR_NONE);
i++;
for(j=0; j < i; j++)
OrderModify(x[j], Ask + 2*iATR(NULL,PERIOD_M5,14,NULL), Ask-2*iATR(NULL,PERIOD_M5,14,NULL),0, NULL, CLR_NONE);
I use an array to store the pending stops ticket numbers, and then used ordermodify to modify the trade. Is there anything wrong?
Thanks.