Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 215

 
AlGuru Please advise. How to specify in the Expert Advisor to close on the next candle?
datetime Time[] - Array Timecontaining opening time of each bar of the current chart.Time[0] - The open time of the last bar. If the OrderOpenTime() is less thanTime[0] - this means that the order was opened on the last bar, and according to your strategy, it is time to close this order.
 
STARIJ:
datetime Time[] -Time arraycontaining opening time of each bar of the current chart.Time[0] - The open time of the last bar. If the OrderOpenTime () is open at less than Time[0]- this means that the order was opened on the last bar, and according to your strategy, it is time to close this order.
Or, it has been forgotten about and was opened one year ago, for example ;)
 
STARIJ:
datetime Time[] - Array Time series, that contains opening time of each bar of the current chart.Time[0] - time of the last bar open . If the OrderOpenTime() is less thanTime[0] - this means that the order was opened on the last bar, and according to your strategy, it is time to close this order.


Thank you! Just solved the problem with iTime function. I'm not good with arrays yet )).

 
AlGuru:


Thank you! I have just solved the problem using the iTime function. I am not good with arrays yet )).

Show me how you solved it.

There's just something you might not have considered:

Forum on trading, automated trading systems and trading strategy testing

Any questions from newbies on MQL4, help and discussion on algorithms and codes

Artyom Trishkin, 2017.05.25 19:43

STARIJ:
datetime Time[] -Time array, which contains opening time of each bar of current chart.Time[0] - The open time of the last bar. If the OrderOpenTime () isless than Time[0]- it means that the order is opened on the last bar, and according to your strategy, it is time to close this order.

Either it has been forgotten about and was discovered a year ago, for example ;)

 
Artyom Trishkin:

Show me how you solved it.

There are just some things you might not have considered:



OrderOpenTime() < iTime(Symbol(), 0, 0)
 
AlGuru:

OrderOpenTime() < iTime(Symbol(), 0, 0)

And if the opening time of the order was a week ago? Then it is definitely not on the last candle (if the chart is not weekly). Should we close it too?

Of course, it all depends on the requirements of your TS, but I would go the other way...

 
Artyom Trishkin:

And if the opening time of the order was a week ago? Then it is definitely not on the last candle (if the chart is not weekly). Should we close it too?

Of course it all depends on the requirements of your TS, but I would go the other way...


This is an additional condition. A position should be closed when the price reaches the MA line. Sometimes the price opens right on the line and opens and closes positions on every tick. I have solved this problem by closing a position not earlier than the next candle.
 

Good day to all!

Please advise how to code the following action in the strategy tester

General idea

1.open order N -X (volume = 0.1)

2.If this order is closed on SL, then. to compensate for the loss, immediately at the closing price on SL of an order N X, open the order N - X1 (volume = 0.3)

WE HAVE TO DO.

3 If the order (volume = 0.3) is closed on SL, only the value of the hour of opening of the order N - X will be remembered to compensate for losses at which it was opened.

I know how to open both orders, but I cannot find my way to the end, how to memorize the hour value for an order with 0.1 lot volume that was closed on the SL.

NOTE: This is related to order closures on the same tick.

Sometimes more than one order with the volume of 0.1 and 0.3 are closed on one tick.

If 3 orders of 0.1, for example, are closed on a single tick on a SL, instead of opening 3 orders of 0.3. - only 1 order of 0.3 lots is opened

In this case if I close only 1 order of 0.3 lots on the SL, I will not get values of the hour when two orders of 0.1 lot are opened which compensate their losses.

I.e., I need 3 orders of 0.3 lots to be opened in this case, not one.


Sometimes 3 orders of 0.3 lots will be closed by a SL on one tick, despite the fact that their corresponding 0.1 lot orders were opened on different ticks (but just at one price).

In this case the program saves the right value only for one last order of 0.1 lot.

I need the program to save the hour value of each order (0.1 lot) closed by SSL.


Here is my code, which we need to modify.

Thank you for your help.

int  A2;
int A1;
int A;
int start()                                             
{                                               
int ot = OrdersTotal();                                         
int Ht = OrdersHistoryTotal();
                                                
                                                
if(Bid == iOpen(NULL,PERIOD_H1,0))
if ( A!= Hour() )
{
OrderSend(Symbol(),OP_SELL,0.1,Bid ,3,Ask+400*Point,Ask-200*Point,"jfh",123 );
A = Hour();
}                                               
//**************************************************************************************
int Счет=0, Номер=OrdersHistoryTotal()-1;
//int A1=0;
  for( ; Номер>=0; Номер--)
  {
    if(!OrderSelect(Номер, SELECT_BY_POS, MODE_HISTORY)) continue;
    A1=OrderOpenTime();
    if(OrderProfit()>=0) break;
    Счет++;
    if(Счет ==1&&A2!=OrderOpenTime())
    {
    A2=OrderOpenTime();
     OrderSend(Symbol(),OP_SELL,0.3,Bid ,3,Ask+400*Point,Ask-200*Point,"jfh",123 );
    }
  }
//************************************************************************************** 
return;
}

Here is an example of a situation where several orders are closed on one tick

        08:51:38.906    2017.03.27 13:09:44  Tester: stop loss #200  at 1.08858 (1.08856 / 1.08858)
2       08:51:38.906    2017.03.27 13:09:44  1 = 1 = 1 = 1 EURUSD,M1: open #214  sell 0.30 EURUSD at 1.08856 sl: 1.09258 tp: 1.08658 ok
0       08:51:38.906    2017.03.27 13:10:28  Tester: stop loss #192  at 1.08879 (1.08877 / 1.08879)
0       08:51:38.906    2017.03.27 13:10:28  Tester: stop loss #193  at 1.08879 (1.08877 / 1.08879)
2       08:51:38.906    2017.03.27 13:10:28  1 = 1 = 1 = 1 EURUSD,M1: open #215  sell 0.30 EURUSD at 1.08877 sl: 1.09279 tp: 1.08679 ok
0       08:51:38.906    2017.03.27 13:10:29  Tester: stop loss #194  at 1.08880 (1.08878 / 1.08880)
 
AlGuru:

This is an additional condition. A position is closed when the price crosses the МА line. Sometimes the price opens right on the line and opens and closes a position on every tick. I have solved the problem by closing the position before the next candle.

Such a problem should be solved by checking whether there is, or has been, an open and closed position on this very bar.

Otherwise you will pile everything up. The signal function should send signals, while the trading function should already check the validity of the signal.

 

Hello. Why do the euro vs usdcurrency pairs show 149.16325 instead of 1.0616?


Reason: