Questions from Beginners MQL5 MT5 MetaTrader 5 - page 722

 
Alexey Viktorov:
Yeah, well... Where can I find a broker like that... Can you give me a link?
That's right. Buy closes at Bid
 
I apologise for my inattention. I read "opens"...
 

Good afternoon,

Question:

Can you please tell me why I can't put a buy pending:

request.price =SymbolInfoDouble(Symbol(),SYMBOL_ASK)+(offset)*point;

If offset=1 , then errorwill pop up:

failed buy stop 0.10 AUDNZD.m at 1.03748 [Invalid price],i.e.small level price (in my case)

When the same "order to execute" is placed right after it

request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK)

everything works fine (i.e., the order is placed):

order buy 0.10 at 1.03747 [#2 buy 0.10 AUDNZD.m at 1.03747]

Why is the request for a pending order(1.03748) not accepted, i.e.at 1.03747 it is placed, but at 1.03748 it is not? (becauseSYMBOL_ASK takes into account the spread and offset - offset from the current price for placing the order, in points, is increased by 1)

But at offset=100: pending BUY_STOP price = 1.03847 - it already works


Thank you.
 
Konstantin_78:

Good afternoon,

Question:

Can you please tell me why I can't put a buy pending:

request.price =SymbolInfoDouble(Symbol(),SYMBOL_ASK)+(offset)*point;

If offset=1 , then errorwill pop up:

failed buy stop 0.10 AUDNZD.m at 1.03748 [Invalid price], i.e.small price level (in my case)

When I set an "order to execute" immediately after

request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK)

everything works fine (i.e., the order is placed):

order buy 0.10 at 1.03747 [#2 buy 0.10 AUDNZD.m at 1.03747]

Why is the request for a pending order(1.03748) not accepted, i.e.,at 1.03747 the order is placed, but at 1.03748 the order is small?

But if offset=100: pending BUY_STOP price = 1.03847, it already works.


Thank you.

You have already answered your own question.

There is a parameter "stoplevel" -- minimal necessary distance from the current price to the price of placing a pending order -- for each symbol has its own value and is set in the trading conditions

 
Andrey F. Zelinsky:

Вы же сами и ответили на свой вопрос.

Есть такой параметр stoplevel -- минимально необходимое расстояние от текущей цены до цены установки отложенного ордера -- для каждого инструмента своё значение и задаётся в торговых условиях 

Then it would probably be fair to write

price =SymbolInfoDouble(Symbol(),SYMBOL_ASK)+SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL)*point

Although, if you wrote "...from the current price", what does that have to do with the spread? Which is included in SYMBOL_ASK (because SYMBOL_ASK = open price + spread).

 
Vladimir Karputov:

I have attached an example to help you...

I see, the example helped. Thank you.


Now, here's a question.

When I increase the lot, at some point there is not enough free funds, and I need to open with increased lot.

That is, to enter the maximum lot, as much as FreeMargin allows.

How to write this condition: if there are not enough funds to open position with calculated lot, the function should return the maximum possible lot to open the position.

double LotA()
{
   double Lot=FirstLot;

   if(DoublingCount<=0) return Lot;
   double MaxLot=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   double MainLot=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
if(Lot<MainLot)Lot=MainLot;
     if(Lot>MaxLot)Lot=MaxLot;
   double lt1=Lot;
   HistorySelect(0,TimeCurrent());
   if(HistoryOrdersTotal()==0)return(Lot);
   double cl=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-1),ORDER_PRICE_OPEN);
   double op=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_PRICE_OPEN);

   long typeor=HistoryOrderGetInteger(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_TYPE);
   if(typeor==ORDER_TYPE_BUY)
     {
      if(op>cl)
        {
         if(ud<DoublingCount)
           {
            lt1=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_VOLUME_INITIAL)*_C_;
            ud++;
           }
         else ud=0;
        }
      else ud=0;
     }
   if(typeor==ORDER_TYPE_SELL)
     {
      if(cl>op)
        {
         if(ud<DoublingCount)
           {
            lt1=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_VOLUME_INITIAL)*_C_;
            ud++;
           }
         else ud=0;
        }
      else ud=0;
     }
   if(lt1>MaxLot)lt1=MaxLot;
   lt1=LotCheck(lt1);
   return(lt1);
  }
//+------------------------------------------------------------------+}
 
Marina Korotkih:

I see, the example helped. Thank you.


Now this question.

When I increase the lot, at some point there is not enough free funds, and I need to open with bigger lot.

That is, to enter the maximum lot, as much as FreeMargin allows.

How to write this condition: if there are not enough funds to open position with calculated lot, the function should return the maximum possible lot to open the position.

               

double Mgn,Lot=0,BID,ASK;

    BID=SymbolInfoDouble(_Symbol,SYMBOL_BID);
    ASK=SymbolInfoDouble(_Symbol,SYMBOL_ASK);

   if(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1,ASK,Mgn)==true)Lot=AccountInfoDouble(ACCOUNT_MARGIN_FREE)/Mgn;

   if(OrderCalcMargin(ORDER_TYPE_SELL,_Symbol,1,BID,Mgn)==true)Lot=AccountInfoDouble(ACCOUNT_MARGIN_FREE)/Mgn;
                        

Marina, how about this?

You apply two calculation options - one to open SELL, and one to open BUY

 
Renat Akhtyamov:

                  if(OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1,ASK,Mgn)==true)Lot=AccountInfoDouble(ACCOUNT_MARGIN_FREE)/Mgn;

                  if(OrderCalcMargin(ORDER_TYPE_SELL,_Symbol,1,BID,Mgn)==true)Lot=AccountInfoDouble(ACCOUNT_MARGIN_FREE)/Mgn;
                        

Marina, could it be like this?

No, it's not.

You need not just calculate the maximum possible lot, but also check the whole thing for the minimum allowable, because it may happen that the minimum lot is 0.01, and the margin allows you to open only 0.009, then torment the server with requests that will never be accepted, but they can take action on you)

 
Vitaly Muzichenko:

No, it's not.

You need not just calculate the maximum possible lot, but also check the whole thing for the minimum allowable, because it may happen that the minimum lot 0.01, and the margin allows you to open only 0.009, then torture the server requests, which will never accept, but the action on you and can take)

Write full code, as it should be, and I'll see at the same time....?

I will always learn from you and keep an eye on you to make sure the answers are complete.

I used to work as a technical supervisor, don't worry, everything will be OK!

Together we are a team!

 
Marina Korotkih:

I see, the example helped. Thank you.


Now this question.

When I increase the lot, at some point there is not enough free funds, and I need to open with bigger lot.

That is, to enter the maximum lot, as much as FreeMargin allows.

How to write this condition: if there are not enough funds to open position with calculated lot, the function should return the maximum possible lot to open the position.


A slippery slope you're on.)
Reason: