Help ... error 130 order modify

 

Hi,

Please help me to find the solution of "error 130" at my code :

I calculate the Averaging price of some OP_SELL orders of a pair & the new Target (Profit) level and then trying to modify the order. This is a martingale EA without stoploss ...

if (!OrderModify(OrderTicket(), AverageSellPrice, 0, TargetSellPrice, 0, Green)) {

  print(   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx );

}

This is the debug output of print() value :

Error modify , Avgprc:0.12176000  <=> Stoploss:0.00000000 <=> Target:1.22670000 <=> Ask:1.22540000  <=> Bid:1.22520000 <=> StopLevel:0.00100000  <=> spread: 0.0002000 <=> freeze:0.0003000

From the output : SELL take profit target = 1.2267 is bigger than (Ask + StopLevel) = 1.2254 + 0.001 = 1.2264

Note: StopLevel, spead & freeze value is already multiplied by POINT (0.0001). What is wrong ??

Thank you very much
Giovanni

 
You can find info on error 130 Here. Don't forget to search Here.
 
giovanni:

Hi,

Please help me to find the solution of "error 130" at my code :

I calculate the Averaging price of some OP_SELL orders of a pair & the new Target (Profit) level and then trying to modify the order. This is a martingale EA without stoploss ...


This is the debug output of print() value :

From the output : SELL take profit target = 1.2267 is bigger than (Ask + StopLevel) = 1.2254 + 0.001 = 1.2264

Note: StopLevel, spead & freeze value is already multiplied by POINT (0.0001). What is wrong ??

Thank you very much
Giovanni

You don't say what type this Order is that you are trying to Modify . . . if it's a OP_BUY you can't change the price it was opened at, if it's a pending BUY then Ask is not relevant . . . what is Avgprc: 0.12176000 ?
 
ubzen:
You can find info on error 130 Here. Don't forget to search Here.
Thank you ubzen ....
 
RaptorUK:
You don't say what type this Order is that you are trying to Modify . . . if it's a OP_BUY you can't change the price it was opened at, if it's a pending BUY then Ask is not relevant . . . what is Avgprc: 0.12176000 ?


Hi RaptorUK,

Thank you .... the Avgprc is the "averaging of some opened orders", this will replace the OrderOpenPrice() .... but you say that : the OrderOpenPrice() of an OP_BUY can not be changed ? How about Openprice of OP_SELL ? Some times I got the same error also for OP_BUY process.

The snippet of the code of Modifying OP_SELL orders :

                     //--- error found at FxOpen, 4 digits mini account
                     double Stoploss = 0;
                     extern double TakeProfit = 30; 
                     
                     //----- conv 4-5 Digits
                     theDigits   = MarketInfo(Symbol(), MODE_DIGITS);
                     if ((theDigits == 2)||(theDigits == 4)) int pointMulFactor = 1;
                     else if ((theDigits == 3)||(theDigits == 5)) pointMulFactor = 10;
                     newPoint = Point * pointMulFactor;
                     StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) * newPoint;  // calculate stop level
                     calcSpread = MarketInfo(Symbol(), MODE_SPREAD) * newPoint;
                     calcFreeze = MarketInfo(Symbol(), MODE_FREEZELEVEL) * newPoint;
                     
                     //--- averaging of some sell orders 
                     total_Sell = CountTrades_Sell();  // get total amount of Sell orders
                     AveragePrice_Sell = 0;
                     double Count_Sell = 0;
                     for (int cntSell = OrdersTotal() - 1; cntSell >= 0; cntSell--) {
                        OrderSelect(cntSell, SELECT_BY_POS, MODE_TRADES);
                        if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
                        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
                           if ((OrderType() == OP_SELL)&&(OrderCloseTime() == 0)) {
                                 AveragePrice_Sell += OrderOpenPrice() * OrderLots();
                                 Count_Sell += OrderLots();
                           }
                        }
                     } // ende for
                     //----------------------------
                     if (total_Sell > 1) AveragePrice_Sell = NormalizeDouble(AveragePrice_Sell / Count_Sell, Digits);
                     for (cntSell = OrdersTotal() - 1; cntSell >= 0; cntSell--) {
                        OrderSelect(cntSell, SELECT_BY_POS, MODE_TRADES);
                        if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
                        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
                           if ((OrderType() == OP_SELL)&&(OrderCloseTime() == 0)) {
                              RefreshRates();
                              double minDistance=MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(), MODE_SPREAD);
                              if (TakeProfit <  minDistance) { TakeProfit = minDistance; }
                              if ((Stoploss != 0)&&(Stoploss <  minDistance)) { Stoploss = minDistance; }
                              TargetPrice_Sell = AveragePrice_Sell - TakeProfit * newPoint;
                              SellTarget = TargetPrice_Sell;
                              Stopper_Sell = AveragePrice_Sell + Stoploss * newPoint;
                           }
                        }
                     }
                     //---------
                     for (cntSell = OrdersTotal() - 1; cntSell >= 0; cntSell--) {
                        OrderSelect(cntSell, SELECT_BY_POS, MODE_TRADES);
                        if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
                        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
                           if (OrderCloseTime() == 0) {
                              while(IsTradeContextBusy()) Sleep(10);
                              RefreshRates();
                              if (TargetPrice_Sell < (Ask + StopLevel)) { TargetPrice_Sell = (Ask + StopLevel + 0.0003); }  
                                    if (!OrderModify(OrderTicket(), AveragePrice_Sell, 0, TargetPrice_Sell, 0, Blue)) {
                                       // {Sleep(1000);RefreshRates();}
                                       Print("Error modify, Avgprc:"+  AveragePrice_Sell +" Stoploss:" + OrderStopLoss() + " Target:" +  TargetPrice_Sell + " Ask:" + Ask + " Bid:" + Bid+" StopLevel:"+StopLevel+" spread: "+calcSpread+" freeze:"+calcFreeze );       
                                    }
                                 NewOrdersPlaced_Sell = FALSE;
                           }
                        }
                     } // ende for      

Thank you very much for your help ...

BR,
Gio

 

Hi RaptorUK,

To avoid some other possible errors, may be I must use "OrderOpenPrice()" instead of "AveragePrice_Sell" ?? => let the Order Open Price as it is ...

Thanks
Gio

                                    if (!OrderModify(OrderTicket(), OrderOpenPrice(), 0, TargetPrice_Sell, 0, Blue)) {
                                       // {Sleep(1000);RefreshRates();}
                                       Print("Error modify, Avgprc:"+  OrderOpenPrice() +" Stoploss:" + OrderStopLoss() + " Target:" +  TargetPrice_Sell + " Ask:" + Ask + " Bid:" + Bid+" StopLevel:"+StopLevel+" spread: "+calcSpread+" freeze:"+calcFreeze );       
                                    }
 
Did you solve the Error_130 or are you still having issue with it?
 
ubzen:
Did you solve the Error_130 or are you still having issue with it?

Tashi Deleg,

I still have the same problem ... even after I have changed the "AveragePrice_Sell" to "OrderOpenPrice()" ... the error is still persist ... :(

Thanks
Gio

 

Try this one. I've not tested... and there's a good chance I missed something. However it communicates allot of the things I believe you could fix within your code or at least look for.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void Modify_Order_TargetPrice(int Magic, string Symb, int Type, double Target){
/*
    Function Designed To Add Target/TakeProfit To Non-Pending Orders Only.
    Provide Magic_Number, Symbol Example Symbol(), Type Example OP_BUY And 
    Price Target In Double Value.
*/
    for(int cntSell=OrdersTotal()-1; cntSell>=0; cntSell--){                    //Always Count Down //Always Check if(OrderSelect()) || if(!OrderSelect()) Before Moving On.
        if(OrderSelect(cntSell, SELECT_BY_POS)                                  //Defaults To Mode Trade When Selecting By Position, Only Check if OrderCloseTime() == 0 When Selecting By Ticket.
        && OrderMagicNumber()==Magic                                            //Good Idea To Filter By Magic Number....So its Compatable With Other Experts And Manual Trading
        && OrderSymbol()==Symb                                                  //Good Idea To Filter By Symbols....So its Compatable With Other Pairs
        && OrderType()==Type){                                                  //Good Idea To Filter By OrderType.....So That It's Only Looking For Market Orders- Instead of Pending Orders
            double  Bkr_Points=     MarketInfo(Symb,MODE_POINT);                //Broker Point Value Represented In Double.
            int     Bkr_Digits=     MarketInfo(Symb,MODE_DIGITS);               //Broker Integer Representation of Digits
            int     StopLevel=      MarketInfo(Symb,MODE_STOPLEVEL);            //Stop Level In Integer Representation of Points.
            int     Freeze_Lv=      MarketInfo(Symb,MODE_FREEZELEVEL);          //Freeze Level In Integer Representation of Points.
            double  Integ2Pips=     Bkr_Points; int Int2IntPts=1;               //Integ2Pips: [Integer] Points Converted to [Double] Pips. 
            if(Bkr_Digits==3){Integ2Pips=0.01;      Int2IntPts=10;}             //Int2IntPts=Example Slippage In OrderSend() Needs To Be Submitted As Integer
            if(Bkr_Digits==5){Integ2Pips=0.0001;    Int2IntPts=10;}             //When Broker Is Not The Usual 4-Digit Broker, Integer Points As In Slippage Needs To Be Multiplied By 10.
            if(Type==OP_BUY){int Sign=1;} if(Type==OP_SELL){Sign=-1;}           //Sign Is Used To Make The Function Work With Both Buy And Sell Orders, Without Having To Duplicate The Code.
            double OOP=OrderOpenPrice(); double OCP=OrderClosePrice();          //Some Variables For Short Hand.
            if(Sign*(OCP-OOP)<(Freeze_Lv+1)*Integ2Pips){continue;}              //Use OrderClosePrice Instead Of Worring About Bid/Ask. Line Means OrderClosePrice Have SurPass The Freeze Level.
            if(Sign*(Target-OCP)<(StopLevel+1)*Integ2Pips){continue;}           //Distance Between Target And OrderClosePrice Is Greater-Than The StopLevel By At Least A Whole Pip.
            while(IsTradeContextBusy()){Sleep(10);} RefreshRates();             //If You Prefer To Work In Points Then Substitute Bkr_Points Instead Of Integ2Pips. Within The Above Lines ^.
            if(!OrderModify(OrderTicket(),OOP,0,Target,0,Blue)){                //You Cannot Modify The OrderOpenPrice For Non-Pending Orders. The Target Not-Being Near The Current Close Price Matters. 
                Print("GetLastError="+GetLastError());                          //Simple GetLastError Statement.
}   }   }   }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Thanks a lot ubzen. I will try it ...

Regards,
Giio

 

Umm.. I already caught one-error. This line.

if(Sign*(OCP-OOP)<(Freeze_Lv+1)*Integ2Pips){continue;} 

What I wanted to code is if( Target>OOP+(Freeze_Lv+1)*Integ2Pips) .... When dealing with Op_Buy Orders. And Of course.

if( Target<OOP-(Freeze_Lv+1)*Integ2Pips)... When dealing with Op_Sell Orders.

See if you can figure-out a way to code it ... Because you certainly CAN modify orders while its within the Freeze-Level. You just cannot Close-it, nor place a Take-Profit within the Freeze-Level.

Reason: