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

 

Hello Everyone.
I am having a problem with Error #130 (I have looked through the documentation and have not found anything that can help me so far). I have attached the code below - aside from the other issues in the code, I am just focusing on this for the moment.
For some reason, if I change the OP_BUY & OP_SELL to OP_BUYSTOP & OP_SELLLIMIT they work, as OP_BUY & OP_SELL they do not. I have tried rearranging the code, and still have the same problem. 

I demo trade with GFT, who are a Market Maker, and not an ECN, hence are 5 digits, I don't think this is the problem, as it works when I make them pending orders rather than immediate orders. Any ideas? (Also, I am a rookie, constructive feedback helps me learn best)

Thanks 

// 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;

// Start Function
int start()
        {            
                     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;
                  
                
                
                RefreshRates();                 
                // Calculate SL & TP For Sell Limit
                double SellLimitSL = Price + StopLoss;
                                    double SellLimitTP = Price - TakeProfit;
                                    
                                    RefreshRates();
                                    // Calculate SL & TP For Buy Stop                           
                                    double BuyStopSL = Price1 - StopLoss;
                                    double BuyStopTP = Price1 + TakeProfit;
                                    
                // Previous Day High // 
                if(Price > DayHigh && SellLimit == 0 && BuyStop == 0)
         {               
                 RefreshRates(); 
                                // Open Sell Limit
                                SellLimit = OrderSend(Symbol(),OP_SELLLIMIT,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_BUYSTOP,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 = Price1 - StopLoss;
                                    double BuyLimitTP = Price1 + TakeProfit;
                                    
                                    RefreshRates();
                     // Calculate SL & TP For Sell Stop                 
                                    double SellStopSL = Price + StopLoss;
                                    double SellStopTP = Price - TakeProfit;    
                                                  
        // Previous Day Low //
                if(Price < DayLow && SellStop == 0 && BuyLimit == 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 Yesterday = TimeToStr(iTime(Symbol(),PERIOD_M1,1),TIME_DATE);
                        string Today = TimeToStr(iTime(Symbol(),PERIOD_M1,0),TIME_DATE);
                                                    
                //Rest For New Trading Day//    
                if(Yesterday < Today)
                    {
                    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+"\nSellLimit: " + SL+"\nBuyStop: " + BS+"\nBuyLimit: " + BL+"\nSellStop: " + SS+"\nYesterdays Date: " + Yesterday+"\nTodays Date: " + Today);
                                                
                return(0);
        }
 

Your Code....

double Price = Bid;

// Open Sell Limit
SellLimit = OrderSend(Symbol(),OP_SELLLIMIT,LotSize,Price,5,SellLimitSL,SellLimitTP,"SellLimit Order",MagicNumber,0,Green);










/*  IS it FOR YOU that you can open pending at Bid or Ask ??   

Why not

// Calculate SL & TP For Sell Limit
  double SellLimitSL = DayHigh + StopLoss;
  double SellLimitTP = DayHigh - TakeProfit;


if(Price < DayHigh  " - STOPLEVEL "    && SellLimit == 0)  
// Open Sell Limit
SellLimit = OrderSend(Symbol(),OP_SELLLIMIT,LotSize,DayHigh,5,SellLimitSL,SellLimitTP,"SellLimit Order",MagicNumber,0,Green);

*/


 

 

Read the rules and limitations again  how to open a new trade then start this coding the way it has to be

 

deVries:

 

/*  IS it FOR YOU that you can open pending at Bid or Ask ??   

 Im not sure what you mean by this?

if(Price < DayHigh  " - STOPLEVEL "    && SellLimit == 0)  
// Open Sell Limit
SellLimit = OrderSend(Symbol(),OP_SELLLIMIT,LotSize,DayHigh,5,SellLimitSL,SellLimitTP,"SellLimit Order",MagicNumber,0,Green);

I understand most of this however the " -STOPLEVEL" confuses me, what is this here for?

Ill try to make some of the changes and see what happens.

 
See MarketInfo's MODE_STOPLEVEL, and MODE_FREEZELEVEL :https://docs.mql4.com/constants/marketinfo
 
NewCoder47:

 Im not sure what you mean by this?

I understand most of this however the " -STOPLEVEL" confuses me, what is this here for?

Ill try to make some of the changes and see what happens.

There are rules governing the price you can place Pending orders at and at what prices you can set your Stop and Take Profit . . .  you need to take some time to understand these: https://book.mql4.com/appendix/limits
 
LOL . .  SNAP.
 

Cool. Yea, I have read through those earlier today to make sure I understood them. To be sure I know what the MODE_STOPLEVEL value is, I am trying to call it and put it in a comment, however, I see only to be getting 0.00000 in the comments is this the correct way to call it?

double MI = MarketInfo(Symbol(),MODE_STOPLEVEL);
 
NewCoder47:

Cool. Yea, I have read through those earlier today to make sure I understood them. To be sure I know what the MODE_STOPLEVEL value is, I am trying to call it and put it in a comment, however, I see only to be getting 0.00000 in the comments is this the correct way to call it?

Some Brokers have StopLevel and FreezeLevel of 0.0
 

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???). So I can only assume, that my result of 0.0 from the MODE_FREEZELEVEL is correct.

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

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??

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!)

 
if they are ECN try to send order with TP = 0 and SL = 0, you can add it later.