Questions from a "dummy" - page 56

 
Interesting:

In contrast to the tick handler, the timer will be executed after a certain period of time, set by the period.

In heavy timer processing it is of course better to disable it for a time by slip or to first tick (there are a lot of variants), but if timer processing is not very heavy and period is long enough timer can be disabled.

Also in the timer processing you can provide a check on whether it is a working day or not.

If necessary, you can schedule heavy calculations for the weekend (for example, auto-optimizationof EA) and run this process from the timer. At the end of the calculations (or at the beginning of the calculations), the timer can be correctly disabled.

As for testing in the tester using OnTimer() function of the multi-currency EA. Suppose the timer is set at intervals of 10 seconds. Will it be ticking during all weekends of the testing period? I think that is what Vladimir meant. So, if we indicate to the timer that Saturday and Sunday are skipped, the testing will be much faster.
 
tol64:
As for testing in the tester through the OnTimer() function of the multi-currency Expert Advisor. Suppose the timer is set at an interval of 10 seconds. Will it be ticking all weekends during the testing period? I think that is what Vladimir meant. So, if we indicate to the timer that Saturday and Sunday are skipped, the testing will be much faster.

1. I tried to turn the timer off at weekends when the calculations were not very complicated, I didn't feel much of a difference (although there were differences of course), now I've decided not to turn the timer off for the time being.

2. Yes, if the timer is set, it makes no difference in the tester or in normal mode triggering will occur until the timer is turned off. If we are talking about a tester then at an interval of 10 seconds it will trip for the whole test period - every 10 seconds.

When stopping the timer for the weekend there are several solutions:

а. Shut down the timer with writing the status to a variable. At the first tick by the main tool (or by a "spy" signal) the timer can be started again. This method has disadvantages related to the probability of tick skipping or tick lagging in the illiquid market. Tick skipping can also be caused by a lack of connection to the trade server.

б. Slip brakes, for a certain period of time. The good thing is that the period is precisely specified, but the bad thing is that in this method, not only the timer, but the entire Expert Advisor will be inactive till the X hour.

Although, all positions and orders will be processed in the tester.

в. It is possible to realize a pause by increasing the period of timer. It is convenient to know beforehand time when timer has to "wake up" and expert's work is not stopped. Uncomfortable by the fact that you have to keep track of timer in working state or in standby mode.

в. Divide the timer's stuffing into two groups, the first is executed all the time (for example, determining the state of connection), and the second according to conditions (working days, connection present, trading is allowed, etc.).

 
Interesting:


If necessary, heavy calculations can be scheduled for the weekend (e.g. auto-optimisationof the EA) and run this process from the timer. At the end of the calculations (or at the beginning of the calculations) the timer can be correctly disabled.

Hello! I got a similar idea yesterday, but did not have time to write a post with question about it:

1.Is it possible to do this? How this may look in the code, particularly opening and closing trades.Or just their location and calculation-calculations.I.e. at the weekend on the timer goes to a defined function, which cyclically rewinds history, and determines the best parameters.For this online ticks are not needed, and the function will just rotate in the loop ...

2.Is there anywhere in any branch I can read about it?

3.If applied to the championship, will not be loaded on the car? This is probably a question for the organizers.

 
MetaDriver:
Then calculate everything in the Expert Advisor on a suitable timeframe, and print the result in OnTester(). You do not have to trade. Do you have any problems?

Thanks a lot

I have another question, how do Iclose a position by time, if the price hasn't reached either take or stop loss?

I read the libraries on how to work with orders... I hooked it up... The program is swearing that it doesn't have such a procedure...

So, my question is what kind of code should be in order to close order after certain time ( for example 1 day)

 

AccountInfoDouble(ACCOUNT_BALANCE) != AccountInfoDouble(ACCOUNT_EQUITY)

this is how I have to check if a trade is open...

OrdersTotal ()!=0 does not work )))) very interesting glitch )

 
papaklass:
There is PosirionTotal() for positions. OrdersTotal() only for Pending orders.

if ( PositionsTotal() == 1 )

same thing ... no reaction

// opens normally

if ( TimeActivation ( 1 )

{

if ( _1_operation == 1 && Buy ( 0.10 ) == 1 ) { Sleep (600000); }

if ( _1_operation == -1 && Sell ( 0.10 ) == 1 ) { Sleep (600000); }

}

// cannot close before take or stop

if ( TimeActivation ( 2 )

{

if ( PositionsTotal() == 1 ) /// NOT WORKING))

{

if ( _1_operation == 1 && Sell ( 0.10 ) == 1 ) { Sleep (600000); }

if ( _1_operation == -1 && Buy ( 0.10 ) == 1 ) { Sleep (600000); }

}

}

 
BaTTLeBLooM:

Thanks a lot

So question, what code should be approximately, to close the order after a certain time ( for example 1 day )

Please.

Approximately like this: You save the time of opening in a variable. Immediately add the desired period of time to it (e.g. 1 day = 60*60*24).

Then at each tick (or time), monitor if the current time is longer than the control time. If it is - you close it // if (TimeCurrent() > MyControlTime) CloseMyPosition();

Документация по MQL5: Дата и время / TimeCurrent
Документация по MQL5: Дата и время / TimeCurrent
  • www.mql5.com
Дата и время / TimeCurrent - Документация по MQL5
 
BaTTLeBLooM:

if ( PositionsTotal() == 1 )

same thing ... no reaction

// opens normally

if ( TimeActivation ( 1 )

{

if ( _1_operation == 1 && Buy ( 0.10 ) == 1 ) { Sleep (600000); }

if ( _1_operation == -1 && Sell ( 0.10 ) == 1 ) { Sleep (600000); }

}

// cannot close before take or stop

if ( TimeActivation ( 2 )

{

if ( PositionsTotal() == 1 ) /// NOT WORKING))

{

if ( _1_operation == 1 && Sell ( 0.10 ) == 1 ) { Sleep (600000); }

if ( _1_operation == -1 && Buy ( 0.10 ) == 1 ) { Sleep (600000); }

}

}

Actually, it's not clear what you've written here, but PositionTotal() clearly has nothing to do with it.

Put Print() before checking, =1 ?

Print("PositionsTotal=",PositionsTotal());
if ( PositionsTotal() == 1 ) /// НЕ ХРЕНА НЕ РАБОТАЕТ )))
 
tol64:

Konstantin Gruzdev suggested an interesting method with "spies" and "agents" in his article. )) But his "agent" exSpy Control panel MCM doesn't want to work for me.

I will now have a look at the variant presented in the article. So far made several experts on spies, works great.

MetaDriver:

I think this technology will not work in the tester.

It works.

 
MetaDriver:

Please.

Approximately this way: you need to store the time of opening in a variable. Immediately add to it the necessary time interval (for example 1 day = 60*60*24).

Then at each tick (or time), monitor if the current time is longer than the control time. If it is - you close it // if (TimeCurrent() > MyControlTime) CloseMyPosition();

Into a variable is an option, but if you need a more reliable closing, even after restarting the terminal/advisor, you can use a medjic to identify the order and check the time of its opening.

//закрывает ордера с заданным меджиком по прошествию определенного периода(в сек)
void closeOrderByTime(int magic,int period) {
        MqlTradeRequest request;
        MqlTradeResult tradeResult;
        MqlTradeCheckResult checkResult;
        ulong ticket = -1;
        int cnt = OrdersTotal();
        for (int i=cnt-1; i>=0; i--) {  
                ticket = OrderGetTicket(i);
                if (OrderGetInteger(ORDER_MAGIC) == magic && ticket>0 && TimeCurrent() > OrderGetInteger(ORDER_TIME_SETUP)+period) {
                        request.action = TRADE_ACTION_REMOVE;
                        request.order = ticket;
                        if(OrderCheck(request,checkResult) ) {
                                OrderSend(request, tradeResult);
                        } else {
                                MessageBox("Ошибка");
                        }
                }
        }
}
Reason: