HELP ME PLEASE!!! OrderModify error 1...

 

Hi.

I'm having a problem coding an EA that when is earning my "TrailingStopValue", the EA modify the stoploss to breakeven+maximalcurrencyspread. In my attempts, after backtesting is logging an error modify 1.

This is my source code without changes...

//Trailing stop to CLOSEBUY
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid
- Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;

...... and....

//Trailing stop to CLOSESELL
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop))
|| (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask
+ Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;

Can you help me? Many thanks.

 

I understand your return code for your Modify order = 1. If it is the case this means there is no error.
What's your TrailingStop value?
 
Jacques366:

Hi Jacques366.

My TrailingStop is 170. I only want to move my stoploss to breakeven and nothing more. then the EA must recognize that if the stoploss is already the OrderOpenPrice+MaxCurrencySpread, the equation is false and ordermodify shouldn't be executed, and the EA will close by takeprofit or by closebuy/sell parameters.

Thank you.

 

I have read your code once more and found it ok.

Are you sure it is not working :

- what is the error code in return of the OrderModify?

- Make sure to correctly handle it.

- perform a GetLastError(); before your OrderModify, it will clear the register from previous error.

 

//Trailing stop
if(UseTrailingStop && TrailingStop > 0 && OrderStopLoss() != OrderOpenPrice() - Point * MaxCurrencySpread) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop))
|| (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()
- Point * MaxCurrencySpread
, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;


The first code is my base of work. here are my tried modifications. this case is for sell position.

When activated the TS function works but my journal is filled with this warning: 2009.01.06 20:02:01 2001.03.16 09:34 Aries v0 EURUSD,M5: OrderModify error 1

I want to avoid it obviously.

Thanks for your interest.

 
I tried with my EA to see what is written in the journal for a OrderModify because I think I had this error in the past but it is no more the case, modification is recorded with no error.
Try to display all the new and previous values just before the order to see if something comes out of this. I hope it is not coming from the platform you are using that displays error 1 when it is ok.