OrderSend Error 130 - tester

 
//+------------------------------------------------------------------+
//| Order Entry function - Buy or Sell (pending orders)              |
//+------------------------------------------------------------------+

void OrderEntry(int direction)
{
   // Padding for Stop & Entry    ---------
   ATR_Pad = iATR(NULL,low,ATR_Period,1)/2;
   Buy_Pad = NormalizeDouble(ATR_Pad,Digits); 
   Sell_Pad = NormalizeDouble(ATR_Pad,Digits);
   //Stop calculations  -------------------
   ATR = iATR(NULL,low,ATR_Period,1);
   MA = iMA(NULL,low,MA_Period,0,1,0,1);
   //Market Information -------------------  
   Lot_Step = MarketInfo(Symbol(), MODE_LOTSTEP); 
   ts = MarketInfo(Symbol(), MODE_TICKSIZE); 
   tv = MarketInfo(Symbol(), MODE_TICKVALUE);
   minlot = MarketInfo(Symbol(), MODE_MINLOT);
   freezelevel = MarketInfo(Symbol(), MODE_FREEZELEVEL);   

     
   risk_amount = AccountBalance( )*RiskPercent/100;
   risk_amount2 = AccountBalance( )*RiskPercent2/100;
   risk_amount3 = AccountBalance( )*RiskPercent3/100;
   risk_amount4 = AccountBalance( )*RiskPercent4/100;

   D1_ATR = NormalizeDouble(iATR(NULL,1440,D1_ATR_Period,1),Digits);
   Todays_Range = NormalizeDouble(Todays_D1_high - Todays_D1_low, Digits);
   
   double Buy_StopLevel = ((MarketInfo(Symbol(), MODE_STOPLEVEL) + 
                            MarketInfo(Symbol(), MODE_SPREAD))*pips)+Bid;

//+-------------------------------------------------------------------------------------+
//| Order Buy Function                                                                  |
//+-------------------------------------------------------------------------------------+   

if(direction==0)
{//--Buy--// 

  double BuyStopPriceMath = MA - ATR, 
         BuyStopPrice = NormalizeDouble(BuyStopPriceMath,Digits); 
         
 //Get Take Profit price for FIRST TARGET
 if( Stored_BuyPrice > BuyStopPrice + Point || BuyStopPrice > Stored_BuyPrice + Point ) 
    {
    pips_to_bsl = Stored_BuyPrice - BuyStopPrice;
    }
      
      
  double buy_tp_price1 =(pips_to_bsl)+Stored_BuyPrice, 
         buy_takeprofit_price1 = NormalizeDouble(buy_tp_price1,Digits), 
        btp1 = buy_takeprofit_price1;
      
  //Get Take Profit price for SECOND TARGET
  double buy_tp_price2 =(pips_to_bsl*Second_Target_Ratio)+Stored_BuyPrice, 
         buy_takeprofit_price2 = NormalizeDouble(buy_tp_price2,Digits), 
         btp2 = buy_takeprofit_price2;
      
  //Get Take Profit price for THIRD TARGET
  double buy_tp_price3 =(pips_to_bsl*Third_Target_Ratio)+Stored_BuyPrice, 
         buy_takeprofit_price3 = NormalizeDouble(buy_tp_price3, Digits), 
         btp3 = buy_takeprofit_price3;   
      
  //Get Take Profit price for FOURTH TARGET
  double buy_tp_price4 =(pips_to_bsl*Fourth_Target_Ratio)+Stored_BuyPrice, 
         buy_takeprofit_price4 = NormalizeDouble(buy_tp_price4, Digits), 
         btp4 = buy_takeprofit_price4;
             
      
  //Get Lot Size calculations for all FOUR Trades
  double loss_for_1_lot = pips_to_bsl / ts * tv ;         
  double LotSize_Buy = MathFloor( risk_amount / loss_for_1_lot/ Lot_Step) * Lot_Step, 
         LotSize_Buy2 = MathFloor( risk_amount2 / loss_for_1_lot/ Lot_Step) * Lot_Step,
         LotSize_Buy3 = MathFloor( risk_amount3 / loss_for_1_lot/ Lot_Step) * Lot_Step, 
         LotSize_Buy4 = MathFloor( risk_amount4 / loss_for_1_lot/ Lot_Step) * Lot_Step;

   double Buy_StopLevel = ((MarketInfo(Symbol(), MODE_STOPLEVEL) + 
                        MarketInfo(Symbol(), MODE_SPREAD))*pips) + Ask;
                        Print("Buy_StopLevel == ", Buy_StopLevel);
   
  
//+------------------------------------------------------------------+
//---Buy---//

        

if( OpenOrdersThisPair(Symbol()) == 0 && Stored_BuyPrice > Buy_StopLevel + Point && 
    Stored_BuyPrice > BuyStopPrice + Point && btp1 > Stored_BuyPrice + Point )
  { 
  BuyTicketOrder1 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy,Stored_BuyPrice,3,
                                    BuyStopPrice,btp1,NULL,MagicNumber1,0,Green);
  BuyTicketOrder2 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy2,Stored_BuyPrice,3,
				    BuyStopPrice,btp2,NULL,MagicNumber1,0,Green);
  BuyTicketOrder3 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy3,Stored_BuyPrice,3,
			            BuyStopPrice,btp3,NULL,MagicNumber1,0,Green);
  BuyTicketOrder4 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy4,Stored_BuyPrice,3,
                                    BuyStopPrice,btp4,NULL,MagicNumber1,0,Green);
  }          
                       
} // end of  if(direction==0)

...
Getting error 130 on OrderSend now and again... I am back-testing within FXCM. I don't understand why as I am trying to use FREEZE_LEVEL as I thought that sometimes my stops and targets can be too close to the current price to send the BUY and SELLSTOPS? 

Really appreciate any help or thoughts....
 

How you use Point is wayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy wrong.

Fix it and the error will go away instantly.

 
* Point?

I've re-read your post on my other thread, but I'm obviously still not understanding the impact of Point in relation to + Point, - Point, * Point... 

double Point

The current symbol point value in the quote currency.

It doesn't tell me much...

Besides, error code 130 is invalid stops? So surely it has something more to do with that despite my being wrong in the use of Point?
 

If you do more homework, none of this problems would occurred. It is not new problem you know.

There are many examples. Just google it.



 
      if( OpenOrdersThisPair(Symbol()) == 0 && Stored_BuyPrice > BuyStopPrice + Point )
         { 
         BuyTicketOrder1 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy,Stored_BuyPrice,3,BuyStopPrice,btp1,NULL,MagicNumber1,0,Green);
         BuyTicketOrder2 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy2,Stored_BuyPrice,3,BuyStopPrice,btp2,NULL,MagicNumber1,0,Green);
         BuyTicketOrder3 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy3,Stored_BuyPrice,3,BuyStopPrice,btp3,NULL,MagicNumber1,0,Green);
         BuyTicketOrder4 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy4,Stored_BuyPrice,3,BuyStopPrice,btp4,NULL,MagicNumber1,0,Green);

...
I always Google everything first. I even try to use the search function at the top and then filter for forums. It does not seem to be that great even when searching very broad topics surrounding my issues.

Even if I changed it to just this ^ it still pushes out OrderSend error 130. Even if I drop out: && Stored_BuyPrice > BuyStopPrice + Point entirely it still pops up with that error.

Thanks for your post regarding Point... But in this case regarding the error alone, I don't think it will instantly fix my error code 130.
 
You don't know well or at least the basics of how things work and yet, you are developing an ea.
 
DomGilberto, I believe that you have been asked a number of times to limit the width of your code, yet you continue to make posts that requires scrolling back and forth to read them
 
I'm confused? That is why I am writing on here for tips? You're most probably right in regards to Point and my understanding. But I definitely understand the basics... I've programmed a fair amount and do alright. I am still learning and always will be thanks to some of the help i receive on here.

I understand error 130 and I am convinced it is to do with one of 3 things:

  1. Stop loss is too close to the market price
  2. TP is too close to the market price
  3. Placing pending order too close to the market price
So if I tested to see if my entry, stops and take profits violate the specific brokers minimum paramters relative to the 3 points above before placing the trade, it should get rid of this error.

I guess there is some kind of 'code' of conduct on programming forums. It seems if I don't word my questions wisely, I get shot down and disregarded. Quite odd when I am completely self-taught with no programming background at all. 

Sorry if what I am asking is too much. 

Thanks for your help anyway.
 
GumRai:
DomGilberto, I believe that you have been asked a number of times to limit the width of your code, yet you continue to make posts that requires scrolling back and forth to read them
I will fix that now! Sorry!
 
Fixed that now! Sorry, I forget to do that. I think it's partly due to the fact that I do not need to scroll right to left as it all fits on my screen. Despite this, I realize that it's a stupid way of coding anyway! 

Is that easier like that ^^?

Am working on it! 
 

I think it has something to do with price being too close to the pending order (or within the FREEZE_LEVEL) entry price. 

I use buystops and sellstops. They update and change every hour for new stop levels, tps and lot sizing. I figured, if price moves right up on the hour just shy of my entry and requires a new calculation, then if its too close it will fail and send Error 130!?