[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 37

 
nuan:
Question, how can I programmatically close all orders, e.g. every 30 minutes?

datetime prevtime;
int Magic=11111;
int slippage=5;

//=====================
 int start(){
 
    datetime TimeM30=iTime(NULL,30,0);
    if(TimeM30==prevtime) return(0); 
    prevtime = TimeM30;   
    CloseAllPos();
  return(0);
 }
//=====================
 void CloseAllPos(){
   double maxlot=0;
   for(int i=OrdersTotal()-1; i>=0; i--){
     if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;
     if(OrderSymbol()!=Symbol())continue;
     if(OrderMagicNumber()!=Magic)continue; 
      if(maxlot<OrderLots()){ 
         maxlot=OrderLots();
         if(OrderType()==OP_BUY)OrderClose(OrderTicket(),maxlot,NormalizeDouble(Bid, Digits),slippage,Yellow);
         if(OrderType()==OP_SELL)OrderClose(OrderTicket(),maxlot,NormalizeDouble(Ask, Digits),slippage,Yellow);
  } } }
 
Thank you
 
Replaced closing prices with opening prices - the result is identical to the previous one, except that now the equity line is strictly above the balance line. The number of deals and profit decreased a little, but the situation has stabilized even more. There are no losing trades on the studied period.
 
Vinin:


If I understand correctly, with a check on the condition of orders in the market? -

...
if (OrderType()<2) 
//здесь  корректировка размера позиций с учетом ввода/вывода


Interesting stuff! Can you post the full code? It's not quite clear how the orders are tied in to the funds being deposited/withdrawn. Can we determine how much money was deposited to the account at the beginning, the initial balance so to speak, without recalculating the history of closed positions? Not all brokers provide the whole trading history, some not older than 1 month, so the recalculation of the profitability of the Expert Advisor is wrong: The start date is correct, but the balance is the one that was one month ago. As a result, the monthly profit is stretched over the entire trading period.

 
nuan:
Question, how can I programmatically close all orders, e.g. every 30 minutes?

datetime prevtime;
int Magic=11111;
int slippage=5;

//=====================
 int start(){
 
    datetime TimeM30=iTime(NULL,30,0);
    if(TimeM30==prevtime) return(0); 
    prevtime = TimeM30;   
    CloseAllPos();
  return(0);
 }
//=====================
 void CloseAllPos(){
   double maxlot=0;
   for(int i=OrdersTotal()-1; i>=0; i--){
     if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;
     if(OrderSymbol()!=Symbol())continue;
     if(OrderMagicNumber()!=Magic)continue; 
      if(maxlot<OrderLots()){ 
         maxlot=OrderLots();
         if(OrderType()==OP_BUY)OrderClose(OrderTicket(),maxlot,NormalizeDouble(Bid, Digits),slippage,Yellow);
         if(OrderType()==OP_SELL)OrderClose(OrderTicket(),maxlot,NormalizeDouble(Ask, Digits),slippage,Yellow);
  } } }


чет он не работает , закрывает в секунду
 
forexnew:


If I understand correctly, with a check on the condition of orders in the market? -


Interesting stuff! Can you post the full code? It's not quite clear how the orders are tied in to the funds being deposited/withdrawn. Can we determine how much money was deposited to the account at the beginning, the initial balance so to speak, without recalculating the history of closed positions? Not all brokers provide the whole trading history, some not older than 1 month, so the recalculation of the profitability of the Expert Advisor is wrong: The start date is correct, but the balance is the one that was one month ago. As a result, the monthly profit is stretched over the entire trading period.


This is probably not the case after all.
In the terminal, open the "Account history" tab, right click, select "All history".
The history will be downloaded all the way back to when the account was opened.
 
forexnew:


If I understand correctly, with a check on the condition of orders in the market? -


Interesting stuff! Can you post the full code? It's not quite clear how the orders are tied in to the funds being deposited/withdrawn. Can we determine how much money was deposited to the account at the beginning, the initial balance so to speak, without recalculating the history of closed positions? Not all brokers provide the whole trading history, some not older than 1 month, so the recalculation of the profitability of the Expert Advisor is wrong: The start date is correct, but the balance is the one that was one month ago. As a result, the monthly profit is stretched over the entire trading period.

It's not about that here, but it is about keeping track programmatically of whether there have been deposits/withdrawals to/from the account by a certain time. There is no code yet, there is a basic formula for calculating the position volume adjustment here. (The number (in terms of total funds) of placements/withdrawals is tied into it)
 
nuan:


What do you mean "closes in a second"?
A long time? Or what?

 

The charter means that it closes the order in the same second, not in 30 minutes.


I have set it as in your example


datetime TimeM30=iTime(NULL,30,0);
    if(TimeM30==prevtime) return(0); 
    prevtime = TimeM30;   
    CloseAllPosTime();
The robot does not close for other reasons, i.e. it does not close on stop or on profit.


1 2011.07.29 00:00 buy 1 0.01 1.4328 1.3328 1.5328 0.00 1000.00
2 2011.07.29 00:01 close 1 0.01 1.4327 1.3328 1.5328 -0.10 999.90
3 2011.07.29 00:01 buy 2 0.01 1.4329 1.3329 1.5329 0.00 999.90
4 2011.07.29 00:01 close 2 0.01 1.4326 1.3329 1.5329 -0.30 999.60
5 2011.07.29 00:01 buy 3 0.01 1.4328 1.3328 1.5328 0.00 999.60
6 2011.07.29 00:03 close 3 0.01 1.4327 1.3328 1.5328 -0.10 999.50
7 2011.07.29 00:03 buy 4 0.01 1.4329 1.3329 1.5329 0.00 999.50
8 2011.07.29 00:03 close 4 0.01 1.4329 1.3329 1.5329 0.00 999.50


 
Roman.:
This is not the issue here, but whether there have been deposits/withdrawals to/from the account by a certain time. There is no code yet, there is a basic formula for calculating the position volume adjustment here. (The number (in terms of total funds) of the deposits/withdrawals is tied into it)

I get it.

And if you consider opening an account with $0 as a start, and the 1st deposit as a topping up. Is it possible to determine programmatically all toppings (including the first one) that have been made to the account?

Reason: