[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 118

 
Shixan:

Afternoon.

I wrote code to open two pending orders (BuyStop and SellStop) on conditions a=true and b=true and after some time the EA closes both orders, until a new signal appears, but sometimes the EA opens 2 pending orders in the same direction. Why this happens and how to avoid this "bug"?



if (a=true && b=true)
{
int OrderCount = OrdersTotal();
if (OrderCount>1) return(0);
ticket1=OrderSend(Symbol(), OP_BUYSTOP, getLot(), PriceOpen_Buy, slippage, PriceOpen_Sell,0,0,Green);
Sleep(1000);

ticket2=OrderSend(Symbol(), OP_SELLSTOP, getLot(), PriceOpen_Sell, slippage, PriceOpen_Buy,0,0,Green);

Sleep(1000*59*TimeFrame);

for (int i=OrdersTotal()-1; i>=0; i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderType()==OP_BUYSTOP ) OrderDelete(OrderTicket());
if (OrderType()==OP_SELLSTOP ) OrderDelete(OrderTicket());
if (OrderType()==OP_SELL ) OrderClose(OrderTicket(),OrderLots(),Ask, slippage);
if (OrderType()==OP_BUY ) OrderClose(OrderTicket(),OrderLots(),Bid,slippage);
}

return(0);

}


Can you give me a hint?

Thank you in advance

I haven't looked at your code, but... in order NOT to place two or more orders on ONE signal, make a check BEFORE placing an order: is there an order already placed on this signal? If not - put it up, if there is - smoke puffs.
 
mario065:

Hello,

Is it possible to enter a schedule with a fixed weight 1:1 in the settings?

If it is possible, please tell me how.

Thanks in advance.

This library can.

Section "3.3 Function for setting chart properties" function ServiceSetScaleFix1To1().

The library works only with the Russian and English localizations. It may work in yours, too.

 
Hi, could you tell me why in the new build 451 in MetaEditor when you compile, the second ex 4 file does not appear in the experts folder next to the mq 4 file
 

Here is the order opening function:

//+-------------------------------------------------------------------------------------+
//| Открытие короткой позиции                                                           |
//+-------------------------------------------------------------------------------------+
bool OpenSell(double price)
{
   int ticket = -1;
   double SL = OrderOpenPrice() + i_sl * pt;
   double TP = OrderOpenPrice() - i_tp * pt;
   
   if (price < Bid)
       ticket = OrderSend(Symbol(), OP_SELLSTOP, 0.1, ND(price), 3, 0, 0, NULL, i_magic, 0);
       
   if (ticket > 0 && OrderSelect(ticket, SELECT_BY_TICKET == true))
   {
      if (i_sl > 0 && OrderStopLoss() == 0)
      {
         if (!OrderModify(ticket, OrderOpenPrice(), ND(SL), ND(TP), 0, Red))
         {
            Print ("Ошибка установки первичного стопа для шортов ", OrderType(), " - ", GetLastError());
            Print("pt = ", pt);
            Print("Ask = ", Ask);
            Print("Bid = ", Bid);
            Print("SL_s = ", OrderOpenPrice() + i_sl * pt);
            Print("TP_s = ", OrderOpenPrice() - i_tp * pt);
         }
      }
   }
       return (true);
}

Here is the parameter printout:

2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: TP_s = 1.4499
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: SL_s = 1.4519
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: Bid = 1.4513
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: Ask = 1.4515
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: pt = 0.0001
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: Ошибка установки первичного стопа для шортов 5 - 4051
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: OrderModify error 4051
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: invalid takeprofit for OrderModify function
2013.01.26 11:02:56     2010.01.12 00:00  Phillip_Nel's_TS_for_M5 EURUSD,M5: open #1 sell stop 0.10 EURUSD at 1.45091 ok

Here you can clearly see that the TP and SL price are below and above the Ask and Bid respectively, i.e. everything is correct. But for some reason I get a modification error because the stop is wrong. How so?

 
hoz:

Here is the order opening function:

Here is the parameter printout:

Here you can clearly see that the TP and SL price are below and above the Ask and Bid respectively, i.e. everything is correct. But for some reason I get a modification error because the stop is wrong. How so?

Do you read at all what is being scolded?

ERR_INVALID_FUNCTION_PARAMVALUE 4051 Invalid function parameter value

If you don't understand anything, we'll sort it out with the rest of the world...

ZZY. When you place a pending order, the string

if (price < Bid)

When you place a pending order, the string should not be quite relevant. It should be checked for the correspondence with minimal allowed distance set in MarketInfo(Symbol(), MODE_STOPLEVEL). The first thing that immediately caught my eye.

The second is to print the price at which the order is set. The Stop and Take should not be set relative to the Ask and Bid, but relative to the order setting price

 
Zhunko:

This library can.

Section "3.3 Graph Property Setting Functions" function ServiceSetScaleFix1To1().

The library works only with Russian and English localizations. It may work in yours, too.

Thanks Zhunko.
 
artmedia70:

Do you even read what is being scolded?

ERR_INVALID_FUNCTION_PARAMVALUE 4051 Invalid value of function parameter

Look at parameters passed to the called function. When nothing at all becomes clear, we'll sort it out in peace...


Of course I'm reading it, that's why I'm curious. I unlinked all input parameters.

This is what I got:

bool OpenSell(double price)
{
   int ticket = -1;
   double SL = OrderOpenPrice() + i_sl * pt;
   double TP = OrderOpenPrice() - i_tp * pt;
   
   if (price < Bid)
       ticket = OrderSend(Symbol(), OP_SELLSTOP, 0.1, ND(price), 3, 0, 0, NULL, i_magic, 0);
       
   if (ticket > 0 && OrderSelect(ticket, SELECT_BY_TICKET == true))
   {
      if (i_sl > 0 && OrderStopLoss() == 0)
      {
         Print("ND(price) = ", DoubleToStr(ND(price),Digits));
         Print("ND(SL) = ", DoubleToStr(ND(SL),Digits));
         Print("ND(TP) = ", DoubleToStr(ND(TP),Digits));
         Print("ND(OOP) = ", DoubleToStr(ND(OrderOpenPrice()),Digits));
         if (!OrderModify(ticket, ND(OrderOpenPrice()), ND(SL), ND(TP), 0, Red))
         {
            Print ("Ошибка установки первичного стопа для шортов ", OrderType(), " - ", GetLastError());
            Print("pt = ", pt);
            Print("Ask = ", Ask);
            Print("Bid = ", Bid);
            Print("SL_s = ", OrderOpenPrice() + i_sl * pt);
            Print("TP_s = ", OrderOpenPrice() - i_tp * pt);
         }
      }
   }
       return (true);
}

Here's what's in the log:

2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: TP_s = 1.4485
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: SL_s = 1.4505
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: Bid = 1.4496
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: Ask = 1.4497
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: pt = 0.0001
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: Ошибка установки первичного стопа для шортов 5 - 4051
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: OrderModify error 4051
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: invalid takeprofit for OrderModify function
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: ND(OOP) = 1.44946
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: ND(TP) = -0.00100
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: ND(SL) = 0.00100
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: ND(price) = 1.44946
2013.01.26 12:16:22	2010.01.12 01:45  Phillip_Nel's_TS_for_M5 EURUSD,M5: open #4 sell stop 0.10 EURUSD at 1.44946 ok

Some of the orders are modified and some are not. Values of ND(TP), ND(SL) in the beginning were returned to random values. Why?

The normalisation function, by the way, is mine:

//+-------------------------------------------------------------------------------------+
//| Функция нормализации                                                                |
//+-------------------------------------------------------------------------------------+
double ND(double A)
{
  return (NormalizeDouble(A, Digits));
}
 
artmedia70:

Do you even read what is being scolded?

ERR_INVALID_FUNCTION_PARAMVALUE 4051 Invalid value of function parameter

See the parameters passed to the function to be called.When nothing is clear at all, we'll sort it out with the world...

ZS. When you place a pending order the line

if (price < Bid)

This is not quite appropriate. You should check if the minimum allowed distance corresponds to that specified in MarketInfo(Symbol(), MODE_STOPLEVEL). The first thing that caught my eye right away.



I usually encounter such checks for order modification but not for opening. I've already seen it. If I set pending price to bystop, it will be a mistake. And if I set a 10 pips stop it will be surely higher than the StopLoss value. I do not trade on ticks :)
 
artmedia70:


Secondly, print the price at which the order is set. Stop and Take should not be placed relative to the Ask and Bid, but relative to the price at which the order is set



I take it that this is for modification? After all, it is Bid and Ask that is important to us when we open the order. I have straightened out everything with the post above.
 

Good afternoon,

I want to make an EA work on several windows at the same time. But only one order can be open for each instrument. Therefore, now there is a condition:

int total = OrdersTotal();

if (total<1) { analysis and open position block} else { analysis and close position block }

Now, if it is opened on two symbols at the same time, opening on one will be blocked on the other. That's why I made up something similar:

int total = OrdersTotal();

int cnt;

if(total>0)
{
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol())
{
Symbol_FLAG = true;
}
}
}

if(total<1 || total>0 && Symbol_FLAG == false) { analysis and opening ptposition block}

but it doesn't work on the tester...

Maybe you can tell me, maybe I'm up to something unrealizable?

Reason: