Error 130 - common I know, but problematic none the less. - page 2

 
phi.nuts:
if they are ECN try to send order with TP = 0 and SL = 0, you can add it later.
They are a Market Maker.
 

You can open Pending orders with price Ask+MarketInfo(Symb,MODE_STOPLEVEL)*Point, not just "Ask". Please read this information

https://book.mql4.com/trading/ordersend  -> Placing Pending Orders

 
NewCoder47:

Ok, so still having issues with this Error #130.
I have a demo account with GFT, and after many conversations with them, they believe that they do not set a MODE_STOPLEVEL & MODE_FREEZELEVEL, these are up to us to set?!? (I thought that they set those rates/levels???).

1.  So I can only assume, that my result of 0.0 from the MODE_FREEZELEVEL is correct.

2.  Anyway, these S/L & T/P are quite a way from the current price, ~30 pips or so.

3.  GFT say they are a market maker, so I should not have to normalize (from what I can understand). So where else could the problem be??

4.  I am getting the error on every order, be it buy or sell, however if I make them pending, then it places them.

So does anyone have ideas??? ( I am very new to this, so constructive feedback helps!)

1.  do not assume . . .  it will take you a couple of minutes to determine what the Freezelevel and Stoplevel are . . .  print them to the log or use Comment to print them to screen,  you can get them using MarketInfo()  and MODE_FREEZELEVEL & MODE_STOPLEVEL  . . . .  when you output the values using Comment did you also use DoubleToStr() to output 5 digits ?  4 digits is the default.

2.  "quite a way" ?  is that enough when you consider the requirements in this article ?  Requirements and Limitations in Making Trades   you did read it and understand it ?

3.  if you are using a price value such as Bid, Ask, Open, Close, etc . .  you DO NOT EVER need to Normalise . . . 

4.  this is typically of what happens when a Market Order is sent to an ECN Broker with SL & TP set. 

 
NewCoder47:
They are a Market Maker.
Please show the error information that you print to the log when you get an error 130,  including OrderType, Bid, Ask, your attempted Open price, the SL & TP, FreezeLevl and StopLevel . . .  and all to a resolution of Digits using DoubleToStr()
 
RaptorUK:
Please show the error information that you print to the log when you get an error 130,  including OrderType, Bid, Ask, your attempted Open price, the SL & TP, FreezeLevl and StopLevel . . .  and all to a resolution of Digits using DoubleToStr()
  1. For full resolution, I use:
    string  PriceToStr(double p){   return( DoubleToStr(p, Digits) );              }
    
  2. For pending orders, where ticksize is not equal to Point (metals mostly) the pending order open price must be a multiple of ticksize
    double NormalizePrice(double p, string pair=""){
        // https://forum.mql4.com/43064#515262 zzuegg reports for non-currency DE30:
        // MarketInfo(analyze.pair,MODE_TICKSIZE) returns 0.5
        // MarketInfo(analyze.pair,MODE_DIGITS) return 1
        // Point = 0.1
        // Prices to open must be a multiple of ticksize
        if (pair == "") pair = Symbol();
        double ts = MarketInfo(pair, MODE_TICKSIZE)
        return( MathRound(p/ts) * ts );
    }
    double NormalizeLots(double lots, string pair=""){
        if (pair == "") pair = Symbol();
        double  lotStep     = MarketInfo(pair, MODE_LOTSTEP),
                minLot      = MarketInfo(pair, MODE_MINLOT);
        lots    = MathRound(lots/ls) * ls;
        if (lots < minLot) lots = 0;    // or minLot
        return(lots);
    }
    

 
RaptorUK:

1.  do not assume . . .  it will take you a couple of minutes to determine what the Freezelevel and Stoplevel are . . .  print them to the log or use Comment to print them to screen,  you can get them using MarketInfo()  and MODE_FREEZELEVEL & MODE_STOPLEVEL  . . . .  when you output the values using Comment did you also use DoubleToStr() to output 5 digits ?  4 digits is the default.

2.  "quite a way" ?  is that enough when you consider the requirements in this article ?  Requirements and Limitations in Making Trades   you did read it and understand it ?

3.  if you are using a price value such as Bid, Ask, Open, Close, etc . .  you DO NOT EVER need to Normalise . . . 

4.  this is typically of what happens when a Market Order is sent to an ECN Broker with SL & TP set. 

Ok, so I rang GFT and they said that the basically have no idea. Helpful no? And the result that I am receiving on the comment is 0.00000. So I can only but assume/believe that the Stoplevel and freezelevel are zero, as I said, GFT had no clue.
Considering these are zero, I should not have an issue with the Requiremtns and Limitations in making Trades link that you posted.

And GFT have told me they are a Marker Maker, rather than an ECN, so I should be able to set a SL and TP

The most confusing part, is that it will sometimes place buy & sell trades, while at times placing only one, rather than both, or neither at all. There seems to be no pattern or anything.
Then, making them pending, they are placed. Setting the SL and TP to zero, does not seem to make much difference.

As I am new to coding, this is very very confusing. Any further ideas? I have placed the code below in its current form, for whoever would like to have a look. I just placed it on a chart then, and got error #130 for both the sell limit and buy stop.

// External Variables
extern double StopLoss = 0.00300;
extern double TakeProfit = 0.00400;
extern double LotSize = 1;
extern int MagicNumber = 123;

// Global Variables
int SellLimit;
int BuyStop;
int BuyLimit;
int SellStop;
extern bool CheckOncePerBar = true;
datetime CurrentTimeStamp;
// Start Function
int start()
        {           
                if(CheckOncePerBar == true)
                       {
                                  int BarShift = 1;
                                  if(CurrentTimeStamp != Time[0]) 
                                         {
                                                CurrentTimeStamp = Time[0];
                                                bool NewBar = true;
                                         }
                                  else NewBar = false;
                            }
                        else 
                            {
                                  NewBar = true;
                                  BarShift = 0;
                            } 
                            
                            
                     RefreshRates();
                double DayHigh = iHigh(NULL, PERIOD_D1, 1);  // Yesterday's High
                double DayLow = iLow(NULL, PERIOD_D1, 1);  // Yesterday's Low
                double Spread = Ask - Bid;
                double Price = Bid;
                double Price1 = Ask;        
                        
                // Calculate SL & TP For Sell Limit
                double SellLimitSL = DayHigh + StopLoss;
                                    double SellLimitTP = DayHigh - TakeProfit;
                                    
                                    RefreshRates();
                                    // Calculate SL & TP For Buy Stop                           
                                    double BuyStopSL = DayHigh - StopLoss;
                                    double BuyStopTP = DayHigh + TakeProfit;
                                    
                // Previous Day High // 
                if(Price > DayHigh && SellStop == 0 && BuyLimit == 0 && SellLimit == 0 && BuyStop == 0)
         {               
                 RefreshRates(); 
                                // Open Sell Limit
                                SellLimit = OrderSend(Symbol(),OP_SELL,LotSize,Price,5,SellLimitSL,SellLimitTP,"SellLimit Order",MagicNumber,0,Green);
    
                  if(SellLimit < 0 )  //  OrderSend has failed and has returned a value of  -1
                  {
                  Print("Order Send failed, error # ", GetLastError() );
                  }
       
                        // Open Buy Stop
                                BuyStop = OrderSend(Symbol(),OP_BUY,LotSize,Price1,5,BuyStopSL,BuyStopTP,"BuyStop Order",MagicNumber,0,Green);
         
                 if(BuyStop < 0 )  //  OrderSend has failed and has returned a value of  -1
                  {
                  Print("Order Send failed, error # ", GetLastError() );
                  }
         
         }                                  
                               
                               
                               RefreshRates();
                                    // Calculate SL & TP For Buy Limit                  
                                    double BuyLimitSL = DayLow - StopLoss;
                                    double BuyLimitTP = DayLow + TakeProfit;
                                    
                                    RefreshRates();
                     // Calculate SL & TP For Sell Stop                 
                                    double SellStopSL = DayLow + StopLoss;
                                    double SellStopTP = DayLow - TakeProfit;    
                                                  
        // Previous Day Low //
                if(Price < DayLow && SellStop == 0 && BuyLimit == 0 && SellLimit == 0 && BuyStop == 0)
         {
         RefreshRates(); 
                    // Open Buy Limit
                                BuyLimit = OrderSend(Symbol(),OP_BUY,LotSize,Price1,5,BuyLimitSL,BuyLimitTP,"BuyLimit Order",MagicNumber,0,Green);

                 if(BuyLimit < 0 )  //  OrderSend has failed and has returned a value of  -1
                  {
                  Print("Order Send failed, error # ", GetLastError() );
                  }
         
                                // Open Sell Stop
                                SellStop = OrderSend(Symbol(),OP_SELL,LotSize,Price,5,SellStopSL,SellStopTP,"SellStop Order",MagicNumber,0,Green);
                
                 if(SellStop < 0 )  //  OrderSend has failed and has returned a value of  -1
                  {
                  Print("Order Send failed, error # ", GetLastError() );
                  } 
         }    
                            
         
         string PreviousBarDate = TimeToStr(iTime(Symbol(),PERIOD_M1,1),TIME_DATE);
                        string CurrentBarDate = TimeToStr(iTime(Symbol(),PERIOD_M1,0),TIME_DATE);
                                                    
                //Rest For New Trading Day//    
                if(PreviousBarDate < CurrentBarDate && NewBar == True)
                    {
                    SellLimit = 0;
                    BuyStop = 0;
                    BuyLimit = 0;
                    SellStop = 0;
                    } 
                   
                   string DH1 = DoubleToStr(DayHigh,5);
                   string DL1 = DoubleToStr(DayLow,5);
           string BD1 = DoubleToStr(Bid,5);
                   string AK1 = DoubleToStr(Ask,5);
                        string SPRD = DoubleToStr(Spread,5);
                   string SL = DoubleToStr(SellLimit,2);
                   string BS = DoubleToStr(BuyStop,2);
                        string BL = DoubleToStr(BuyLimit,2);
                        string SS = DoubleToStr(SellStop,2);
                                    
                   Comment("Previous Day High: " + DH1+"\nPrevious Day Low: " + DL1+"\nCurrent Bid Price: " + BD1+"\nCurrent Ask Price: " + AK1+"\nCurrent Spread: " + SPRD+"\nSell Limit Order #: " + SL+"\nBuy Stop Order #: " + BS+"\nBuy Limit Order #: " + BL+"\nSell Stop Order #: " + SS+"\nPrevious Bar Date: " + PreviousBarDate+"\nCurrent Bar Date: " + CurrentBarDate);
                                                
                return(0);
        }
 

I have also told the EA to print the levels at which it is attempting to place the trade. At the moment I have set the Sell SL and TP to 0 and it is placing the order fine. I have set the Buy with a SL and TP as you can see below and it will not go through. What is going on here, Im almost at my witts end!!!!


 
NewCoder47:

I have also told the EA to print the levels at which it is attempting to place the trade. At the moment I have set the Sell SL and TP to 0 and it is placing the order fine. I have set the Buy with a SL and TP as you can see below and it will not go through. What is going on here, Im almost at my witts end!!!!

So you have the following information:

 

  • Trade works when you set TP & SL to 0.0
  • Stoplevel & Freezelevel are both 0.0 


This suggests that your Broker is an ECN type Broker,  so you need to place the Order with SL & TP set at 0.0 and then do an OrderModify() to set the TP & SL,  see the link I gave previously:   ECN



Also,  when you Print double variables please make sure you  . . . .  "and all to a resolution of Digits using DoubleToStr()"  otherwise yo are missing the last digit on 5 digit pairs. 

 
RaptorUK:

Also,  when you Print double variables please make sure you  . . . .  "and all to a resolution of Digits using DoubleToStr()"  otherwise yo are missing the last digit on 5 digit pairs. 

Yea, thanks for all your help. I tried doing this last night but had problems, and wasnt thinking straight by the end of it, might give it another go today.
Reason: