Order Modify Error

 

Hello

 

i have a problem with order modify, i try to place some order and with short order i get sometimes wrong

my code

 The Long order will always be modified right, the short order i get sometimes, not always an error with invalid stop.

the calculation of the stop is right.

does someone can help?

      if(PositionsTotal()!= 0 )
        {
         if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && PositionGetDouble(POSITION_SL)!= TL_Long )
           {
            PositionModify(_Symbol,TL_Long,0);
             Print(TL_Long," Long");
             
           }
           
           
         if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && PositionGetDouble(POSITION_SL)!= TL_Short)
           {
            PositionModify(_Symbol,TL_Short,0);
            Print(TL_Short);
           }

        }
 
amando:

Hello

 

i have a problem with order modify, i try to place some order and with short order i get sometimes wrong

my code

What is PositionModify() ?

the calculation of the stop is right., 

It is not as you get an error.

What is current price (Bid/Ask) when you modify your SL ? Did you check the stopslevel ?

 

PositionModif its easy, i take it over an include file

 

bool PositionModify(const string symbol,const double sl,const double tp)
  {

   MqlTradeRequest m_request = {0};
   MqlTradeResult result;

//--- setting request
   
   m_request.action=TRADE_ACTION_SLTP;
   m_request.symbol=symbol;
   m_request.sl    = sl;
   m_request.tp    = tp;
//--- action and return the result
   return(OrderSend(m_request,result));
  }

 

The stop Level i checked, i add the Stop Level to the normal stop if its to close, what i do not understand, why on a short order, mt5 want to place the long Stoploss?

 
amando:

PositionModif its easy, i take it over an include file

 

 

The stop Level i checked, i add the Stop Level to the normal stop if its to close, what i do not understand, why on a short order, mt5 want to place the long Stoploss?

You don't check the stopslevel, your stoploss can't be too close to Ask price for a sell. Please answer my previous question  :

Forum on trading, automated trading systems and testing trading strategies

Order Modify Error

angevoyageur, 2014.12.05 22:25

What is PositionModify() ?

It is not as you get an error.

What is current price (Bid/Ask) when you modify your SL ? Did you check the stopslevel ?


 

yes, the stoplevels are right, after your first comment i checked it out and saw the stoplevel is 0 in the market, now i modify it by myself to 50 pips ( i always comment with 5 digits broker)

 

double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
      double TL_Long=NormalizeDouble(Open0-(Range*Faktor_Modify)-SpreadPoint,_Digits);
      double TL_Short=NormalizeDouble(Open0+(Range*Faktor_Modify)+SpreadPoint,_Digits);
     
       if(TL_Long-Ask<=StopLevel*_Point) TL_Long=TL_Long-StopLevel*_Point;
       if(Bid-TL_Short<=StopLevel*_Point) TL_Short=TL_Short+StopLevel*_Point;

      if(PositionsTotal()!=0)
        {
         Print("I'm Here");
         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && PositionGetDouble(POSITION_SL)!=TL_Long)
           {
            PositionModify(_Symbol,TL_Long,0);
            Print(TL_Long," Long");
            Print("StopLevel: ",StopLevel);

           }

         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && PositionGetDouble(POSITION_SL)!=TL_Short)
           {
            Print("I'm Here Short");
            PositionModify(_Symbol,TL_Short,0);
            Print(TL_Short);
           }

        }

 This is my acutal code, the only problem is really the short order

 

on the long side, it will be modified absolutly right, but for short order i dont come to the selection

 

here is the copy of the journal, as you can see, it do not go to the selection for the short order

 2014.12.06 14:46:54 Core 1 final balance 10593.52

2014.12.06 14:46:54 Core 1 2014.12.04 23:59:59   order performed buy 1.66 at 1.23792 [#3 buy 1.66 EURUSD at 1.23792]

2014.12.06 14:46:54 Core 1 2014.12.04 23:59:59   deal performed [#3 buy 1.66 EURUSD at 1.23792]

2014.12.06 14:46:54 Core 1 2014.12.04 23:59:59   deal #3 buy 1.66 EURUSD at 1.23792 done (based on order #3)

2014.12.06 14:46:54 Core 1 2014.12.04 23:59:59   position closed due end of test at 1.23792 [sell 1.66 EURUSD 1.24233 sl: 1.24883]

2014.12.06 14:46:54 Core 1 2014.12.04 07:00:00   StopLevel: 50

2014.12.06 14:46:54 Core 1 2014.12.04 07:00:00   1.22871 Long

2014.12.06 14:46:54 Core 1 2014.12.04 07:00:00   failed modify sell 1.66 EURUSD sl: 1.24883, tp: 0.00000 -> sl: 1.22871, tp: 0.00000 [Invalid stops]

2014.12.06 14:46:54 Core 1 2014.12.04 07:00:00   I'm Here

2014.12.06 14:46:54 Core 1 2014.12.03 07:00:00   StopLevel: 50

2014.12.06 14:46:54 Core 1 2014.12.03 07:00:00   1.2352 Long

2014.12.06 14:46:54 Core 1 2014.12.03 07:00:00   failed modify sell 1.66 EURUSD sl: 1.24883, tp: 0.00000 -> sl: 1.23520, tp: 0.00000 [Invalid stops]

2014.12.06 14:46:54 Core 1 2014.12.03 07:00:00   I'm Here

2014.12.06 14:46:54 Core 1 2014.12.02 14:01:42   order performed sell 1.66 at 1.24233 [#2 sell stop 1.66 EURUSD at 1.24233]

2014.12.06 14:46:54 Core 1 2014.12.02 14:01:42   deal performed [#2 sell 1.66 EURUSD at 1.24233]

2014.12.06 14:46:54 Core 1 2014.12.02 14:01:42   deal #2 sell 1.66 EURUSD at 1.24233 done (based on order #2)

2014.12.06 14:46:54 Core 1 2014.12.02 14:01:42   order [#2 sell stop 1.66 EURUSD at 1.24233] triggered

2014.12.06 14:46:54 Core 1 2014.12.02 07:00:00   sell stop 1.66 EURUSD at 1.24233 sl: 1.24883 (1.24643 / 1.24652 / 1.24643)

 

any idea? 

ps: always use the Print(xxx) for checking some code 


Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties - Reference on algorithmic/automated trading language for MetaTrader 5
 

amando:...

2014.12.06 14:46:54 Core 1 2014.12.04 07:00:00   1.22871 Long

2014.12.06 14:46:54 Core 1 2014.12.04 07:00:00   failed modify sell 1.66 EURUSD sl: 1.24883, tp: 0.00000 -> sl: 1.22871, tp: 0.00000 [Invalid stops]

...

 

That doesn't match. Where is your position selected ?

You are using PositionGetXXX() function without selecting a position first, which give you wrong result.

      if(PositionsTotal()!=0)

should probably be :

      if(PositionSelect(_Symbol))
 
angevoyageur:

That doesn't match. Where is your position selected ?

You are using PositionGetXXX() function without selecting a position first, which give you wrong result.

should probably be :

this is very interresting,

i was thinking, when i check if the position number is bigger than 0, means minimum 1 position is on, than i select the long and short ones,

 

neverless, now its working,

 

thanks for your help