Damn Error 130 to Hell - page 3

 
delcor wrote >>

Vangrosh

thanks for the input

can you help me to under stand

is this correct

i do an EA with auto trail

if(OrderType()==OP_SELL && OrderSymbol()==Symbol())

{
if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); // place a TP and SL
}
if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) // place TP
{
if(OrderStopLoss()>(Ask+Point*TrailingStop)+Point) // check true
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red)) // if true modify order
Print("Error_Modify - ",GetLastError());
else str=StringConcatenate("\n My ticket number is ", OrderTicket(), " and my stop loss setting is ", DoubleToStr(Ask+Point*TrailingStop,Digits)); // new code
}
}
}

Here is what I wrote in another post, explaining the different approach.

>>Here is an easy fix simply by checking that the new stoploss price is at least 1 point or greater then the old stoploss. Just do the reverse for a Sell order.

      if (OrderType() == OP_BUY)
      {      
         if(Bid-OrderOpenPrice() > (Point*TrailingStop))
         {       
            double oldStopLoss = OrderStopLoss();
            double newStopLoss = Bid-Point*TrailingStop;
            double nextStopLoss = oldStopLoss + Point; // Adding 1 point to oldStopLoss, i.e. 76.78 to 76.79            
                       
            if(newStopLoss >= nextStopLoss) // checking that the new stoploss price is at least 1 point or greater then the old stoploss
            {                              
               OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,0,0,Green);
               return;
            }
         }
      }


Here is the complete function I use. Now that I think about it I could have used a better var name then nextStopLoss, and I should also add error checking to the OrderModify().

Also my Trailing Stop function is in an EA that can have multiple orders opened at the same time, that is why it has those params so I can update the Trailing Stop on multiple orders at the same time.

void CheckTrailingStop(int order_Ticket, int trailingStopValue)
{
   double oldStopLoss;
   double newStopLoss;
   double nextStopLoss;
   int _trailingStop = trailingStopValue;
   
   if (order_Ticket < 0) return;
                                    
   if(OrderSelect(order_Ticket,SELECT_BY_TICKET,MODE_TRADES) == false)
   {
      Print("CheckTrailingStop() - OrderSelect returned the error of ", GetLastError());
      return;   
   }
         
   if (OrderType() == OP_BUY)
   {      
      if(Bid-OrderOpenPrice() > Point*_trailingStop)
      {       
         oldStopLoss = OrderStopLoss();
         newStopLoss = Bid-Point*_trailingStop;
         nextStopLoss = oldStopLoss + Point; // Adding 1 point to oldStopLoss, i.e. 76.78 to 76.79            
                    
         if(newStopLoss >= nextStopLoss)
         {                              
            OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,0,0,Green);
            return;
         }
      }
   }
                                             
   if (OrderType() == OP_SELL)
   {               
      if(OrderOpenPrice()-Ask > Point*_trailingStop)
      {
         oldStopLoss = OrderStopLoss();
         newStopLoss = Ask+Point*_trailingStop;
         nextStopLoss = oldStopLoss - Point; // Subtracting 1 point from oldStopLoss, i.e. 76.78 to 76.77
                    
         if(newStopLoss <= nextStopLoss || (OrderStopLoss() == 0))
         {                              
            OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,0,0,Green);
            return;
         }
      }
   }
}

Then in my start() function I have:

void start()
{                      
   if (validTimePeriod == false) return;
   if (validTrailingStop == false) return;
        
   //---- Start Main program ----
   Main();
   
   if (EnableHedging == true)
   {
      HedgeStopLossCheck();
      CheckHedges();
   }
   
   if (TrailingStop > 0) CheckTrailingStop(currentOrderTicket, TrailingStop);               
           
   CheckWaiting();
   
   GetOpenTradeLots();   
      
   CheckIfCurrentOrder_Closed();
}

I left the other function calls in there just so you can see that I like to partition my code into specific functions as much as possible. It makes things a lot easier.

Good luck with your EA.

 
vangrosh:

Here is what I wrote in another post, explaining the different approach.

>>Here is an easy fix simply by checking that the new stoploss price is at least 1 point or greater then the old stoploss. Just do the reverse for a Sell order.


Here is the complete function I use. Now that I think about it I could have used a better var name then nextStopLoss, and I should also add error checking to the OrderModify().

Also my Trailing Stop function is in an EA that can have multiple orders opened at the same time, that is why it has those params so I can update the Trailing Stop on multiple orders at the same time.

Then in my start() function I have:

I left the other function calls in there just so you can see that I like to partition my code into specific functions as much as possible. It makes things a lot easier.

Good luck with your EA.

thank you - it look good

so do you place your start() function at the bottom of the ea

 
I have a problem too with dreadful error. Thing is, I don't have stop loss or take profit, it just fails to place the pending order, lots of pips away from the market where there should be no problem...
 
TheEconomist wrote >>
I have a problem too with dreadful error. Thing is, I don't have stop loss or take profit, it just fails to place the pending order, lots of pips away from the market where there should be no problem...

Problem with good'ole 130 is that it indicates (one of) a class or group of errors and does not lead one to any instant fix..
You can even fix a problem and its still there

Only thing that occurs here is a typo?

Maybe you are entering a Buy Limit above Ask, when you intended a Buy Stop order?

FWIW

-BB-

 
BarrowBoy:

Problem with good'ole 130 is that it indicates (one of) a class or group of errors and does not lead one to any instant fix..
You can even fix a problem and its still there

Only thing that occurs here is a typo?

Maybe you are entering a Buy Limit above Ask, when you intended a Buy Stop order?

FWIW

-BB-

I have a function that selects operation type:

int SellOperation(double ToCompare)
  {
   int op;
   if (Bid>ToCompare)
     op=OP_SELLSTOP;
   if (Bid==ToCompare)
     op=OP_SELL;
   if (Bid<ToCompare)
     op=OP_SELLLIMIT;        
   return(op);   
  }
  
  
int BuyOperation(double ToCompare)
  { 
   int op;
   if (Ask>ToCompare)
     op=OP_BUYLIMIT;
   if (Ask==ToCompare)
     op=OP_BUY;
   if (Ask<ToCompare)
     op=OP_BUYSTOP;
   return(op);
  }

int WhatOperation(int operation, double ToCompare)
  { 
   if (operation==OP_BUY)
     return(BuyOperation(ToCompare));
   if (operation==OP_SELL)
     return(SellOperation(ToCompare));     
  }       

like this:

09:28:46 2008.06.09 00:00 ForexCraft2 EURGBP,Daily: Opening Sell on level 2 for pylon 0 @ 0.8024 while bid = 0.8016
09:28:46 2008.06.09 00:00 ForexCraft2 EURGBP,Daily: OrderSend error 130
09:28:46 2008.06.09 00:00 ForexCraft2 EURGBP,Daily: ReliableOrderSend error : 130 : Invalid stops.


 

Hello TheEconomist

just some quickies...

1. Do not see any normalizes on ToCompare, unless WhatOperation() is guarranteed to have norm'd actual given it.

2. Double comps have issues - eg, 'Conditional Statement failure... [At wits end] if ( 1.4225 > 1.4225) is NOT TRUE!!!!!!'

3. Do you follow guidance in https://book.mql4.com/appendix/limits

Regards

 

I've been studying this post in hops of solving my error in 'Quick Question' with 130. The order send function is there as well as the journal entries with Print function, do any of you guys know whats going on?

Thanks,

Bauer Boy

 

.

as seen on .../24681

if(isBuying ) 
{ 
  if(stopLoss > 0)
  ACCTSL = Ask - (stopLoss*Point*MyDig);

  if(takeProfit > 0)
  ACCTTP = Ask + (takeProfit*Point*MyDig);
  // Buy
  ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, slippage,ACCTSL,ACCTTP, 
  nameEA, 16384,0,Red); 
  Print ("Stop Loss Value", ACCTSL);
  Print ("Take Profit Value", ACCTTP);

1. StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL);

SL,TP must be at least StopLevel points away from Bid

See below (**)


2. ACCTxx = NormalizeDouble(Ask ..(..), Digits);


3. Print("Bid=",DoubleToString(Ask,Digits),", Ask=",DoubleToString(Bid,Digits));


4. Print ("Stop Loss Value",DoubleToString( ACCTSL,Digits),", stopLoss=",stopLoss);
Print ("Take Profit Value", DoubleToString(ACCTTP,Digits),", takeProfit=",takeProfit);

Why DoubleToString()? Print() only displays FOUR DIGITS



Btw, I'd also somewere at least once Print("MyDig=",MyDig); Why? no way can you then have to worry about it. May seem petty but you'd be amazed by the funnies surrounding such simple stuff!


5. ALL your issues can be easily solved by getting all available information at your fingertips and displaying it.

Then, with good old fashioned paper + pencil you can see where missunderstandings are.



(**)

Ref: https://book.mql4.com/appendix/limits

StopLevel Minimum Distance Limitation.

A trade operation will not be performed if any of the following conditions is disrupted.

Order Type Open Price StopLoss (SL) TakeProfit (TP)
Buy
Modification is prohibited Bid-SL StopLevel TP-Bid StopLevel
Sell
Modification is prohibited SL-Ask StopLevel Ask-TP StopLevel
BuyLimit
Ask-OpenPriceStopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellLimit
OpenPrice-Bid StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel
BuyStop
OpenPrice-Ask StopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellStop
Bid-OpenPrice StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel

 
fbj wrote >>

.

as seen on .../24681

1. StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL);

SL,TP must be at least StopLevel points away from Bid

See below (**)


2. ACCTxx = NormalizeDouble(Ask ..(..), Digits);


3. Print("Bid=",DoubleToString(Ask,Digits),", Ask=",DoubleToString(Bid,Digits));


4. Print ("Stop Loss Value",DoubleToString( ACCTSL,Digits),", stopLoss=",stopLoss);
Print ("Take Profit Value", DoubleToString(ACCTTP,Digits),", takeProfit=",takeProfit);

Why DoubleToString()? Print() only displays FOUR DIGITS



Btw, I'd also somewere at least once Print("MyDig=",MyDig); Why? no way can you then have to worry about it. May seem petty but you'd be amazed by the funnies surrounding such simple stuff!


5. ALL your issues can be easily solved by getting all available information at your fingertips and displaying it.

Then, with good old fashioned paper + pencil you can see where missunderstandings are.



(**)

Ref: https://book.mql4.com/appendix/limits

StopLevel Minimum Distance Limitation.

A trade operation will not be performed if any of the following conditions is disrupted.

Order Type Open Price StopLoss (SL) TakeProfit (TP)
Buy
Modification is prohibited Bid-SL StopLevel TP-Bid StopLevel
Sell
Modification is prohibited SL-Ask StopLevel Ask-TP StopLevel
BuyLimit
Ask-OpenPriceStopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellLimit
OpenPrice-Bid StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel
BuyStop
OpenPrice-Ask StopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellStop
Bid-OpenPrice StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel

Really can't tell what is going on and why this is happening

2009.08.05 14:32:26 Trender Beta Test EURUSD,H1: OrderSend (Trender Beta Test ) failed with error #130

2009.08.05 14:32:26 Trender Beta Test EURUSD,H1: MyDig=10

2009.08.05 14:32:26 Trender Beta Test EURUSD,H1: Take Profit Value1.43155, takeProfit=110

2009.08.05 14:32:26 Trender Beta Test EURUSD,H1: Stop Loss Value1.42255, stopLoss=200

2009.08.05 14:32:26 Trender Beta Test EURUSD,H1: Bid=1.44255, Ask=1.44229







 
Bauer_Boy wrote >>

Really can't tell what is going on and why this is happening

Really it's time to show the whole code. If you hesitate, you can use PM.

I see you have TP lower then Bid

Reason: