Error 130 on OrderModify

 

Hi, I'm Thomas a passionate beginner coder..

I have searched on a lot of topics but I did not find how to solve my problem .. maybe someone can enlighten me ..

Here is my code : 

extern int TakeProfit = 800;
extern int StopLoss = 45;
extern double LotSize = 0.01;
extern int MagicNumber = 1234;
double Pips ;
extern int TraillingStopStart = 80 ;
extern int TraillingStep = 10 ;
int HighestCandle;
int LowestCandle;


else if (OrderType ()==OP_BUY){

int HighestCandle = iHighest(_Symbol,_Period,MODE_HIGH,200,0);

}
 if(prev_ma10>prev_ma5 && ma10<ma5){          if(OrdersTotal() !=0) closeexisting();                   OrderSend(Symbol (),OP_BUY,LotSize,Ask,3,Ask - (StopLoss * Pips), Ask + (TakeProfit * Pips),NULL,MagicNumber,0,Green);                                  for (int b= OrdersTotal ()-1;b>=0;b--){                if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))        if (OrderSymbol()==Symbol ())         if (OrderType ()==OP_BUY)                  if ( HighestCandle <= Ask + (TraillingStopStart * Pips)){         OrderModify(                                  OrderTicket(),                     //For current order                              OrderOpenPrice(),                  // opened for the OpenPrice                                Ask + (TraillingStep * Pips),     // set stop loss                              OrderTakeProfit(),                // unchanged takeprofit                              0,                             // no expiration                              CLR_NONE                       // no color                      );  

Everything works perfectly except the modification of the stop loss (the bold part)

The stop loss is supposed to move from the moment it reaches the purchase price + the Takeprofit (traillingstopstart)


thank you in advance for your help,

 
  1. OrderSend(Symbol (),OP_BUY,LotSize,Ask,3,Ask - (StopLoss * Pips), Ask + (TakeProfit * Pips),

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  2. OrderModify(    
                                 OrderTicket(),                     //For current order
                                 OrderOpenPrice(),                  // opened for the OpenPrice  
                                 Ask + (TraillingStep * Pips),     // set stop loss
                                 OrderTakeProfit(),                // unchanged takeprofit
                                 0,                             // no expiration
                                 CLR_NONE                       // no color
                         );
    How can the stop loss be above the market for a buy order?
 
William Roeder:
  1. Vous achetez à la demande et vous vendez à l' offre . Les ordres d'achat stop en attente deviennent des ordres de marché lorsqu'ils sont frappés et ouverts à la demande .

    1. Le TP / SL de votre ordre d'achat (ou l'entrée de Sell Stop / Sell Limit) est déclenché lorsque le Bid / OrderClosePrice l' atteint. En utilisant Ask ± n , votre SL est plus court et votre TP plus long, par l'écart. Vous ne voulez pas que le montant spécifié soit utilisé dans les deux sens?

    2. Le TP / SL de votre ordre de vente (ou l'entrée de Buy Stop / Buy Limit) sera déclenché lorsque le Ask / OrderClosePrice l' atteindra. Pour déclencher près d'un prix Bid spécifique , ajoutez le spread moyen.
                 MODE_SPREAD (Paul) - Forum de programmation MQL4 - Page 3 # 25

    3. Les graphiques montrent uniquement les prix des offres . Activez la ligne Ask pour voir la taille du spread ( Outils → Options (contrôle + O) → graphiques → Afficher la ligne de demande .)
      La plupart des courtiers avec des spreads variables s'élargissent considérablement en fin de journée (17 h HE) ± 30 minutes. Mon GBPJPY (OANDA) montre un spread moyen = 26 points, mais un spread maximum moyen = 134 (votre courtier sera similaire).

  2. Comment le stop loss peut -il être supérieur au marché pour un ordre d'achat?

Hi William Roeder :)

Woah, actually I had totally neglected the spread!

I will add it .. thank you very much for that (genius) ..


So indeed it may be an abuse of language but the

Ask + (TraillingStep * Pips), // définir la perte d'arrêt

Is not a StopLoss .. but a "condition" If the high of the candle is equal to my "TraillingStopStart" (ask + 80 pips) then I would like to trigger my trailing StopLoss directly at (ask + 70) so 10 pips below on current price then thereafter my TraillingStep is the movement of my StopLoss by 10 pips by 10 pips each time the market increases by 10 pips.

I had first created the code in a very simple EA with very simple order launch conditions, just to check the correct operation of my Trailling StopLoss .. Everything worked perfectly so I integrated my real strategy (therefore more complex) and bim .. Error 130 OrderModify

 
It's not a stop loss?
Your code
 Documentation
OrderModify(    
   OrderTicket(),                //For current order
   OrderOpenPrice(),             // opened for the OpenPrice  
   Ask + (TraillingStep * Pips), // set stop loss
   OrderTakeProfit(),            // unchanged takeprofit
   0,                            // no expiration
   CLR_NONE                      // no color
);
bool  OrderModify(
   int        ticket,      // ticket
   double     price,       // price
   double     stoploss,    // stop loss
   double     takeprofit,  // take profit
   datetime   expiration,  // expiration
   color      arrow_color  // color
   );
 
ThomasBrd51:

Hi, I'm Thomas a passionate beginner coder..

I have searched on a lot of topics but I did not find how to solve my problem .. maybe someone can enlighten me ..

Here is my code : 

Everything works perfectly except the modification of the stop loss (the bold part)

The stop loss is supposed to move from the moment it reaches the purchase price + the Takeprofit (traillingstopstart)


thank you in advance for your help,

 if ( HighestCandle <= Ask + (TraillingStopStart * Pips) && OrderStopLoss()!=Ask + (TraillingStep * Pips)){
        OrderModify(    
                             OrderTicket(),                     //For current order
                             OrderOpenPrice(),                  // opened for the OpenPrice  
                             Ask + (TraillingStep * Pips),     // set stop loss
                             OrderTakeProfit(),                // unchanged takeprofit
                             0,                             // no expiration
                             CLR_NONE                       // no color
                     );
Reason: