Download MetaTrader 5
To add comments, please log in or register
Sell your applications via the Market. It is secure!
dori.claudino
36
dori.claudino 2014.03.20 03:46 

Hi!

The first buy position does not open and throws the error 130.

This happens after a few orders.

The second order never gives problem (OP_SELLSTOP).

I put the code/log for better understanding.


My code:

        RefreshRates();
        Print("Account Balance: "+AccountBalance());
        InitialPrice = Ask - INCREMENT * Point;
        SellGoal = InitialPrice - 2 * INCREMENT * Point;
        BuyGoal = InitialPrice + 2 * INCREMENT * Point;
         
         ticket = OrderSend(Symbol(), OP_BUYSTOP, LOTS, InitialPrice +  INCREMENT * Point, 2, SellGoal, BuyGoal, DoubleToStr(InitialPrice, MarketInfo(Symbol(), MODE_DIGITS)), MAGIC, 0);
         if (ticket > 0) {
             BuyGoalProfit = CheckProfits(OP_BUY, InitialPrice);
             Print("cpt(" + cpt + ")  BuyGoalProfit(" + BuyGoalProfit + ")");
         }else{
            Print("Cannot trade, error: ",ErrorDescription(GetLastError()));  
            PrintFormat("OP:"+(InitialPrice +  INCREMENT * Point)+" SL:"+SellGoal+" TP:"+BuyGoal);
            Print("Bid-SL:"+(Bid-SellGoal)+" > Freeze Level:"+MarketInfo(Symbol(),MODE_FREEZELEVEL));
            Print("Bid-SL:"+(Bid-SellGoal)+" >= Stop Level:"+MarketInfo(Symbol(),MODE_STOPLEVEL));
         }
         
         ticket = OrderSend(Symbol(), OP_SELLSTOP, LOTS, InitialPrice - INCREMENT * Point, 2, BuyGoal, SellGoal, DoubleToStr(InitialPrice, MarketInfo(Symbol(), MODE_DIGITS)), MAGIC, 0);
         if (ticket > 0) {
             SellGoalProfit = CheckProfits(OP_SELL, InitialPrice);
             Print("cpt(" + cpt + ")  SellGoalProfit(" + SellGoalProfit + ")");
         }else{
            Print("Cannot trade, error: ",ErrorDescription(GetLastError())); 
            PrintFormat("OP:"+(InitialPrice -  INCREMENT * Point)+" SL:"+BuyGoal+" TP:"+SellGoal);        
         }

My log:

00:31:59 2011.02.03 16:30  mGRID EA branch_dori USDJPY,M15: Account Balance: 250878.26624
00:31:59 2011.02.03 16:30  mGRID EA branch_dori USDJPY,M15: OrderSend error 130
00:31:59 2011.02.03 16:30  mGRID EA branch_dori USDJPY,M15: Cannot trade, error: invalid stops
00:31:59 2011.02.03 16:30  mGRID EA branch_dori USDJPY,M15: OP:81.841 SL:80.341 TP:82.341
00:31:59 2011.02.03 16:30  mGRID EA branch_dori USDJPY,M15: Bid-SL:1.481 > Freeze Level:0
00:31:59 2011.02.03 16:30  mGRID EA branch_dori USDJPY,M15: Bid-SL:1.481 >= Stop Level:0
00:31:59 2011.02.03 16:30  mGRID EA branch_dori USDJPY,M15: open #30 sell stop 0.10 USDJPY at 80.841 sl: 82.341 tp: 80.341 ok

Watching to see the response and analysis!

Thanks!

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.20 08:52  
dori.claudino:

Hi!

The first buy position does not open and throws the error 130.

This happens after a few orders.

The second order never gives problem (OP_SELLSTOP).

I put the code/log for better understanding.


Please add prints for Bid and Ask into your error reporting . . .


It seems to me that your trade does not comply with the requirements . . .

        InitialPrice = Ask - INCREMENT * Point;           //  <-------  note
        SellGoal = InitialPrice - 2 * INCREMENT * Point;
        BuyGoal = InitialPrice + 2 * INCREMENT * Point;
         
         ticket = OrderSend(Symbol(), OP_BUYSTOP, LOTS, InitialPrice +  INCREMENT * Point, 2,       // <---- note

so the opening price is InitialPrice + INCREMENT * Point or ( Ask - INCREMENT * Point ) + INCREMENT * Point resulting in a value of Ask

From here: Requirements and Limitations in Making Trades

Order Type
Open Price
Close Price
Open Price of a Pending Order
Transforming a Pending Order into aMarket Order




BuyStop


Above the current Ask price
Ask price reaches open price
dori.claudino
36
dori.claudino 2014.03.21 05:17  
RaptorUK:

Please add prints for Bid and Ask into your error reporting . . .


It seems to me that your trade does not comply with the requirements . . .

so the opening price is InitialPrice + INCREMENT * Point or ( Ask - INCREMENT * Point ) + INCREMENT * Point resulting in a value of Ask

From here: Requirements and Limitations in Making Trades

You're right!
The problem was the initial price to open a buy position.

New code:

 ticket = OrderSend(Symbol(), OP_BUYSTOP, LOTS, Ask, 2, SellGoal, BuyGoal, DoubleToStr(InitialPrice, MarketInfo(Symbol(), MODE_DIGITS)), MAGIC, 0);  <<--- The problem line
         if (ticket > 0) {
             BuyGoalProfit = CheckProfits(OP_BUY, InitialPrice);
             Print("cpt(" + cpt + ")  BuyGoalProfit(" + BuyGoalProfit + ")");
         }else{
            Print("Cannot trade, error: ",ErrorDescription(GetLastError()));  
            PrintFormat("OP:"+(InitialPrice +  INCREMENT * Point)+" SL:"+SellGoal+" TP:"+BuyGoal);
            Print("Bid-SL:"+(Bid-SellGoal)+" > Freeze Level:"+MarketInfo(Symbol(),MODE_FREEZELEVEL));
            Print("Bid-SL:"+(Bid-SellGoal)+" >= Stop Level:"+MarketInfo(Symbol(),MODE_STOPLEVEL));
         }



Thanks!

/
To add comments, please log in or register