help with function to change lots quantities

 
Hello. Is there some function to change lots quantities without having to select one by one?


I mean, a function to say: open with 5 lots. If price falls to 1.2000, change number of lots to 2.


Thanks in advance

trader201

Escribe texto o la dirección de un sitio web, o bien, traduce un documento.

traducción del español al inglés

 

COME ON

double Lots = 5.0;

if (MarketInfo(Symbol(), MODE_BID) <= 1.2000)
   {
   Lots = 2.0;
   }
   
OrderSend(Symbol(),OP_BUY, Lots, MarketInfo(Symbol(), MODE_ASK), 3, 0, 0, NULL, 0, 0, Green);
 
qjol:

COME ON


Thanks a lot qjol.

I will work in that

Trader201

 
trader201:
Hello. Is there some function to change lots quantities without having to select one by one?


I mean, a function to say: open with 5 lots. If price falls to 1.2000, change number of lots to 2.


Escribe texto o la dirección de un sitio web, o bien, traduce un documento.

traducción del español al inglés

Are you talking about partially closing a position by 3 lots ?
 
qjol:
COME ON
He said
open with 5 lots. If ..., change number of lots to 2.

i.e. partial close. From here

    #define INF 0x6FFFFFFF  // Not quite infinite, Jul 2029, or 1,879,048,191
//+------------------------------------------------------------------+
//| Partial order close.                                             |
//+------------------------------------------------------------------+
bool    CloseOrder(int ticket=EMPTY, double size=INF){  // INF == entire.
    if      (ticket == EMPTY)   ticket = OrderTicket();
    else if (!OrderSelect(ticket, SELECT_BY_TICKET)){
        Alert("OrderSelect(",ticket,",ticket) failed: ", GetLastError());
                                                                return(false); }
    double  minLot      = MarketInfo(Symbol(), MODE_MINLOT),
            lotStep     = MarketInfo(Symbol(), MODE_LOTSTEP),
            sizeCurr    = OrderLots(),
            sizeClose   = MathRound(size/lotStep)*lotStep,
            sizeRem     = sizeCurr - sizeClose;

    if (sizeClose < minLot)                                     return(false);
    if (sizeRem   < minLot){    sizeClose = sizeCurr;   // Close all
        color   op.color    = IfI(Color.Buy, Color.Sell);   }
    else        op.color    = Aqua;

    if (GetTradeContext() < TC_LOCKED)                          return(false);
    if (OrderClose( ticket, sizeClose, now.close, Slippage.Pips*pips2points
                  , op.color )){    RelTradeContext();          return(true);  }
    Alert("OrderClose(ticket=", ticket, ", ...) [1] failed: ", GetLastError());
    RelTradeContext();      // After GetLastError
                                                                return(false);
}
 

Hello. thanks againg. What I am tryind to do is this (an example)


if (MA1>MA2)

{
int ticket=OrderSend(...OP_BUY, 0.6,...);
}

if (MA1<MA2)
{
here: change quantity of lots. If I change to 0.4, this mean sell 0.2. if I change to 0.9, this mean buy 0.3 more or add 0.3 lots)
}


what I am looking is change the quantities or the lot size with a simple function.


Thanks in advance againg

Trader201

 

int ticket;
double Lots = 0.6;
double ChangeLot = 0.4;

if (MA1>MA2)
   {
   ticket=OrderSend(...OP_BUY, Lots,...);
   }

if (MA1<MA2)
   {
   if (ChangeLot > Lots)
      {
      Lots = ChangeLot - Lots;
      OrderSend(...OP_BUY, Lots,...);
      }
   if (ChangeLot < Lots)
      {
      Lots -= ChangeLot;
      OrderSelect (ticket, SELECT_BY_TICKET, MODE_TRADES);
      OrderClose(ticket, Lots, OrderClosePrice(), 3, Red);
      }
   }