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

 

Good afternoon. Why is there a MODE_MARGINREQUIRED parameter among MarketInfo's request identifiers to determine the amount of free funds needed to open 1 lot for buying, but there is no parameter for determining the amount of free funds needed to open 1 lot for selling? And how to determine how much free funds are needed to open 1 lot to sell in one or another brokerage company?

P.S. In order not to clutter up the forum, thank you in advance for the answer.

 
7777877:

Good afternoon. Why is there a MODE_MARGINREQUIRED parameter among MarketInfo's request identifiers to determine the amount of free funds needed to open 1 lot for buying, but there is no parameter for determining the amount of free funds needed to open 1 lot for selling? And how to determine how much free funds are needed to open 1 lot to sell in one or another brokerage company?

P.S. In order not to clutter up the forum, thank you in advance for the answer.

You need a little less money to sell, so in practice you can use this one parameter.
 

Can you tell me if it's possible to put EAs into folders instead of storing them all in one folder...\experts?

And that they also work from these folders.

I have 20 versions of one EA and 20 of another, and it's impossible to cope with a full set of files.

 

Good afternoon.

The search didn't help.

Maybe someone has seen a similar script.

The point: the script specifies: symbol, buy/sell, volume

there should be 5-7 such fields.

for simultaneous opening on several symbols, the volume of which is not equal to 0.

thank you.

Sincerely.

 
Good afternoon. I have a question for you.... Entry by stochastic (5,14,3) exit also by stochastic but with another period (5,3,3). I dont know how i can use stochastic for the exit, but not the return signal.
I have a problem and I have no idea how it can be solved, I will try to explain.
So, in the code I posted, there are 2 functions
//+------------------------------------------------------------------+
//| подготовить массив тикетов для закрытия |
//+------------------------------------------------------------------+
void PrepareTicketsToClose(int signal, bool Revers, int & ticketsClose[][2], double & lots[],double arrayTickets[][9])
{
int size=ArrayRange(arrayTickets,0);
//----
if (size==0) return;

int i,type,ticket,closeSize;
for (i=0;i<size;i++)
{
type=arrayTickets[i][1];
// если тип ордера не рыночный, то пропускаем
if (type>OP_SELL) continue;

if (Revers) // перевернем тип рыночного ордера
{
if (type==OP_BUY) type=OP_SELL; else type=OP_BUY;
}

// тут решаем для каждого открытого ордера его судьбу
// оставить в рынке или добавить в массив на закрытие
if (type==OP_BUY)
{
//
// код разрешающий оставить покупку

// как пример
if (signal==OP_BUY) continue;
}

if (type==OP_SELL)
{
//
// код разрешающий оставить продажу

// как пример
if (signal==OP_SELL) continue;
}

closeSize=ArrayRange(ticketsClose,0);
ArrayResize(ticketsClose,closeSize+1);
ArrayResize(lots,closeSize+1);
ticketsClose[closeSize][0] = arrayTickets[i][0]; // # тикета
ticketsClose[closeSize][1] = arrayTickets[i][1]; // тип ордера

// здесь укажем сколько лотов нужно закрыть
lots[closeSize] = arrayTickets[i][2]; // закрываемый объем
// можно закрывать частично, тогда нужно переписать строку сверху
}
//----
return;
}

//+------------------------------------------------------------------+
//| Закрывает ордера с указанными тикетами |
//+------------------------------------------------------------------+
void CloseMarketOrders(int ticketsArray[][2], double lotsArray[])
{
//----
int i,size=ArrayRange(ticketsArray,0);
if (size==0) return;

int ticket,type;
double lots;
bool res;

int total=OrdersTotal();

for (i=0;i<size;i++)
{
ticket = ticketsArray[i][0];
type = ticketsArray[i][1];
lots = lotsArray[i];
RefreshRates(); // на всякий случай обновим сведения о рыночном окружении

// блок закрытия покупок
if (type==OP_BUY)
{
res = OrderClose(ticket,lots,Bid,Slippage,Orange);
if (!res)
{
Print("Не удалось закрыть ордер в покупку #",ticket,"! Ошибка №",GetLastError());
// дальнейшая обработка ошибки, написать самостоятельно
}
}

// блок закрытия продаж
if (type==OP_SELL)
{
res = OrderClose(ticket,lots,Ask,Slippage,Orange);
if (!res)
{
Print("Не удалось закрыть ордер в продажу #",ticket,"! Ошибка №",GetLastError());
// дальнейшая обработка ошибки, написать самостоятельно
}
}

}
//----
return;
}
In void PrepareTicketsToClose(int signal, bool Revers, int & ticketsClose[][2], double & lots[],double arrayTickets[][9]) we have to put a condition that will decide if we should leave or close the order...
I tried to put conditions but nothing works....
Can someone look and show if there is an error in these functions or i messed up....
Files:
 
Snegovik:

Good afternoon.

The search didn't help.

Maybe someone has seen a similar script.

The point: the script specifies: symbol, buy/sell, volume

there should be 5-7 such fields.

for simultaneous opening on several symbols, the volume of which is not equal to 0.

thank you.

Sincerely.


That's a hell of a wording. What the questioner is asking...
 
belous:
Good afternoon. I have a question for you.... Entry by stochastic (5,14,3) exit also by stochastic but with another period (5,3,3). I dont understand how i can use stochastic for the exit, but not the return signal.
I have a problem and I have no idea how it can be solved, I will try to explain.
In the code, that I have laid out, there are 2 functions
In void PrepareTicketsToClose(int signal, bool Revers, int & ticketsClose[][2], double & lots[],double arrayTickets[][9]) we have to put a condition that will decide if we should leave or close the order...
I tried to put conditions but nothing works....
May someone look and show if there is mistake in these functions or i screwed up....


Maybe it will be helpful. I did not look at your code.
Kim's functions.

  //========================================================================================================================
  // Закрытие открытых позиций на продажу 
  //-------------------------------------------------------------------------------------------------------------------------
  if(ExistPositions(NULL, OP_SELL, Magic, 0) == true) //если открыта позиция sell
  {
    if() // условие на закритие 
    {
      ClosePosFirstProfit(NULL, OP_SELL, Magic); //закрываем позицию
    }
  } 


//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 06.03.2008                                                     |
//|  Описание : Возвращает флаг существования позиций                          |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//|    ot - время открытия             ( 0   - любое время открытия)           |
//+----------------------------------------------------------------------------+
bool ExistPositions(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (ot<=OrderOpenTime()) return(True);
            }
          }
        }
      }
    }
  }
  return(False);
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия  : 19.02.2008                                                      |
//|  Описание: Закрытие одной предварительно выбранной позиции                 |
//+----------------------------------------------------------------------------+
void ClosePosBySelect() {
  bool   fc;
  color  clClose;
  double ll, pa, pb, pp;
  int    dg=MarketInfo(OrderSymbol(), MODE_DIGITS), err, it;

  if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
    for (it=1; it<=NumberOfTry; it++) {
      if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) //break;
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      pa=MarketInfo(OrderSymbol(), MODE_ASK);
      pb=MarketInfo(OrderSymbol(), MODE_BID);
      if (OrderType()==OP_BUY) {
        pp=pb; clClose=clCloseBuy;
      } else {
        pp=pa; clClose=clCloseSell;
      }
      ll=OrderLots();
      pp=NormalizeDouble(pp, dg);
      fc=OrderClose(OrderTicket(), ll, pp, Slippage, clClose);
      if (fc) {
        if (UseSound) PlaySound(SoundSuccess); //break;
      } else {
        err=GetLastError();
        if (UseSound) PlaySound(SoundError);
        if (err==146) while (IsTradeContextBusy()) Sleep(1000*11);
        Print("Error(",err,") Close ",GetNameOP(OrderType())," ",
              ErrorDescription(err),", try ",it);
        Print(OrderTicket(),"  Ask=",pa,"  Bid=",pb,"  pp=",pp);
        Print("sy=",OrderSymbol(),"  ll=",ll,"  sl=",OrderStopLoss(),
              "  tp=",OrderTakeProfit(),"  mn=",OrderMagicNumber());
        Sleep(1000*5);
      }
    }
  } else Print("Некорректная торговая операция. Close ",GetNameOP(OrderType()));
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Закрытие позиций по рыночной цене сначала прибыльных           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
void ClosePosFirstProfit(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal();
  if (sy=="0") sy=Symbol();

  // Сначала закрываем прибыльные позиции
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (OrderProfit()+OrderCommission()+OrderSwap()>0) ClosePosBySelect();
          }
        }
      }
    }
  }
  // Потом все остальные
  k=OrdersTotal();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) ClosePosBySelect();
        }
      }
    }
  }
}
 
 
belous:
Good afternoon. I have a question for you.... I'm entering by stochastic (5,14,3) and exiting by stochastic only with another period (5,3,3). I dont understand how i can use stochastic for the exit, but not the return signal?

Imho, I would not create an array of tickets to close, but in the market order enumeration loop check each order by feeding its ticket to the closing function input with a check of possible conditions.

 
Can bid be 0 at any point?
 
YOUNGA:
Can bid be 0 at any point?
Is it hard to check, or lazy? It is easier to ask the question. Can the bid price be zero? It can if nothing is being sold8-(
Reason: