[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 371

 
BeerGod:
look in the functions there is a lot of interesting stuff https://www.mql5.com/ru/forum/131859/page5#434248

Thanks, I'll have a look now!
 

Good afternoon again!

I got some answers from the two good people, but unfortunately none of the options is working.

I will repeat, I am writing an EA and I got confused on this moment:

I always open orders with a certain order scheme and they may close on the opening day or stay in the market for another 3 days.

I cannot figure out how to register so that I could find an order that has been active for 3 days and close it without closing an order opened later.

The opening scheme is the same for all orders. I assign magics to all of them in the following way: Magic_s =Magic_s+1.

We need the system to automatically find and close this order because we need to test the system with historical data.

Please, if someone knows how to solve this problem - write the answer. I will be very thankful to you :)

 
Boneshapper:

Got it. Thank you very much. It's a good option, but I can't test the system with historical data. So I wanted to automatically prescribe it somehow. If you have any other suggestions, please let me know.
For testing on the history we should determine the closing condition. Profit/loss or position lifetime, for example no more than 3 days. This can be done by modifying the datetime expiration of an order/position using OrderModify.
 
paladin80:
To test it on the history we have to decide on the closing condition of the position. Profit/Loss or position lifetime, for example no longer than 3 days. This can be done by modifying the datetime expiration of the order/position using OrderModify.

Yes, it turns out we will have a close condition - it is the lifetime of the position, all right, not more than 3 days. I have read about OrderModify but I still do not understand it. I will try to do it in the evening. Thank you very much again for your reply, very prompt:)
 

Sorry, it's not in the language, but I really need to know if anyone knows.

In Windows 7 some files refuse to open. I press "Open with...", select a program and it does NOT appear in the program selection list. Does anyone know how to remove this restriction? Didn't have it on XP. Fucking sevens is killing me :(

I suspect the registry needs to be cleaned. Specifically, I can't double-click FB2 format. CoolReader run and everything is fine. it opens. double-click to run the file format fb2 does not want.

Runs a registry search Utillitoy JV-16 (always used it) - well, it found so many registry entries that mention fb2, just horror - even afraid to kill. What to do? A google search didn't yield anything :(

 

Greetings!

Help me re-do the code. The code is not new, but something is not working for me.

Here is the code:

  *///-----------------Закрытие по истории в безубыток--------------------
   //---------------------расчет по истории ордеров номера очередной итерации----------------------------------------------- 
  Iteration = 0; // зануляем инерации перед их учетом в цикле по истории
  Sum_Loss = 0;  // суммарный убыток по этим итерациям

datetime 
Time_at_History_Current = 0,
Time_at_History_Previos = 0;     
 
 if(OrdersHistoryTotal() != 0)
   {
    for(int counter = OrdersHistoryTotal()-1; counter >= 0; counter--)
      {
       OrderSelect(counter, SELECT_BY_POS, MODE_HISTORY);
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {
          if(OrderType() == OP_BUY || OrderType() == OP_SELL)
            {
             if(OrderProfit() < 0) // если убыток по выбранному ордеру, то считаем суммарный и записываем время закрытия ордера
                                   // для последующего его анализа при подсчете количества итераций
                {
                 double lastLoss = OrderProfit();
                 Sum_Loss=Sum_Loss+lastLoss;  // считаем общий убыток по закрытым подряд убыточным ордерам
                 Time_at_History_Current = OrderCloseTime();
                } 
             
             //Print(" Time_at_History_Current_в цикле = ", TimeToStr(Time_at_History_Current, TIME_DATE|TIME_SECONDS));
             //Print(" Time_at_History_Previos_в цикле = ", TimeToStr(Time_at_History_Previos, TIME_DATE|TIME_SECONDS));
             
             if(Time_at_History_Current != Time_at_History_Previos) // если они не равны, то считаем итерации и делаем их равными
               {
                Time_at_History_Previos = Time_at_History_Current ;
                Iteration++;
                //Print("Iteration at History в условии сравнения  = ",  Iteration);
               }   
             else // они равны, то проверяем, дополнительно, наличие профита по выбранному следующему ордеру и выходим из цикла
               {
                if(OrderProfit() >= 0)
                  break;
               }
            }
         }
      }
   }

if (Sum_Loss < 0.0) { // Имеем убыток по закрытым позам
  if (((AccountEquity() + Sum_Loss + (Sum_Loss * 0.25)) >= AccountBalance()) && (((totalSell > 0) && (totalBuy < 1)) || ((totalSell < 1) && (totalBuy > 0)))) { // Достигли безубытка
    // Здесь какой-то код, который необходимо выполнить при достижении безубытка
        CloseAllBuy();
           CloseAllSell();
           Sum_Loss = 0.0;
           
  
  }
}
//-----------------------------------------------------------------

I tried my best to open a loop when a minus trade is done and after a positive trade, if I had a minus trade, I would decrease my minus balance by the profit of the last closed order, which is higher than zero. That is, if the order has closed in a minus, we begin to work, if the following transaction on profit is more than a loss, we close, if on the following transaction have closed in plus, but this plus is not more than a minus, on the previous orders, this plus from a negative balance, and the following order we compare with new indicators which already is less, as we before have closed in a minus. That is why we have positive balance.

 
drknn:

Sorry, it's not in the language, but I really need it, if anyone knows.

In Windows 7 some files refuse to open. I press "Open with...", select a program and it does NOT appear in the program selection list. Does anyone know how to remove this restriction? Didn't have it on XP. Fucking sevens is killing me :(

I suspect the registry needs to be cleaned. Specifically, I can't double-click FB2 format. CoolReader run and everything is fine. it opens. double-click to run the file format fb2 does not want.

Runs a registry search Utillitoy JV-16 (always used it) - well, it found so many registry entries that mention fb2, just horror - even afraid to kill. What to do? A google search didn't yield anything :(


Start - All programmes - Default programmes - Set mappings
 
drknn:

Sorry, it's not in the language, but I really need to know if anyone knows.

In Windows 7 some files refuse to open. I press "Open with...", select a program and it does NOT appear in the program selection list. Does anyone know how to remove this restriction? Didn't have it on XP. Fucking sevens is killing me :(

I suspect the registry needs to be cleaned. Specifically, I can't double-click FB2 format. CoolReader run and everything is fine. it opens. double-click to run the file format fb2 does not want.

Runs a registry search Utillitoy JV-16 (always used it) - well, it found so many registry entries that mention fb2, just horror - even afraid to kill. What to do? A google search didn't yield anything :(

http://rhpc.ru/topic/200/
 

Guys...help who knows!!!!


The essence of the strategy: Entry by stochastic (5,14,3) exit also by stochastic but with another period (5,3,3). I don't understand how to make an exit by stochastic and not by reverse signal.
I have a problem and I have no idea how it can be solved, I will try to explain.
So in the code, which I posted, there are 2 functions
//+------------------------------------------------------------------+
//| prepare array of tickets to close |
//+------------------------------------------------------------------+
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 the order type is not a market order, then skip
if (type>OP_SELL) continue;

if (Reverses) // flip the market order type
{
if (type==OP_BUY) type=OP_SELL; else type=OP_BUY;
}

// here we decide for each open order its fate
// leave it in the market or add it to the array on closing
if (type==OP_BUY)
{
//
// code allowing to leave the buy

// as an example
if (signal==OP_BUY) continue;
}

if (type==OP_SELL)
{
//
//code allowing to keep selling

//as an example
if (signal==OP_SELL) continue;
}


closeSize=ArrayRange(ticketsClose,0);
ArrayResize(ticketsClose,closeSize+1);
ArrayResize(ticketsClose,closeSize+1);
ticketsClose[closeSize][0] = arrayTickets[i][0]; // ticket #
ticketsClose[closeSize][1] = arrayTickets[i][1] // order type

// here we specify how many lots to close
lots[closeSize] = arrayTickets[i][2]; // volume to be closed
// it is possible to close partially, then the line above must be rewritten
}
//----
return;
}

//+------------------------------------------------------------------+
//| Closes orders with specified tickets |
//+------------------------------------------------------------------+
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(); // just in case the market environment is updated

// purchase close block
if (type==OP_BUY)
{
res = OrderClose(ticket,lots,Bid,Slippage,Orange);
if (!res)
{
Print("Failed to close order to buy #",ticket,"! Error #",GetLastError());
// further error handling, write yourself
}
}

// sales closing block
if (type==OP_SELL)
{
res = OrderClose(ticket,lots,Ask,Slippage,Orange);
if (!res)
{
Print("Failed to close sell order #",ticket,"! Error #",GetLastError());
// further error handling, write yourself
}
}

}
//----
return;
}

The void PrepareTicketsToClose(int signal, bool Revers, int & ticketsClose[][2], double & lots[],double arrayTickets[][9]) function needs to pass a condition to decide if the order should be closed or not...
I tried to put conditions but nothing works....
Can someone look and see if there is an error in these functions or i messed up....
Files:
osc_test.mq4  37 kb
 
Can bid equal 0 in a tick stream?(sometimes) during a trading session
Reason: