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

 
MakarFX:

use the readings to build the logic for your indicator

No, it doesn't work like that.

here . 1 indicator always shows a number - 2147483647. as soon as a signal is received, it shows a different number on one of the buffers. This I have figured out.

But the second indicator always shows either 0 or 2147483647 on 2 buffers simultaneously

Files:
 
I think I've figured it out. It's supposed to be like this
  
     if (in1b<2147483647 && in2b>0 && in2b<2147483647)
           Sell[i]=low[i];
     if (in1s<2147483647 && in2s>0 && in2s<2147483647)
            Buy[i]=high[i];
 
jarikn:
I think I've figured it out. It should be like this

no specifics are needed in this case, i.e. just if >0

 
MakarFX:

in this case the specifics are not needed, i.e. just if >0

but what's in the buffers when there's no signal. i don't think >0 will work here. but i'll try it now

Files:
 
jarikn:

But here's what's in the buffers when there's no signal. I don't think >0 will work here. but I'll try it now

the first indicator has the value EMPTY_VALUE when there is no signal

do the following

   if(iCustom(NULL,0,"in1",1,i)>0&&iCustom(NULL,0,"in1",1,i)<Bid*2&&iCustom(NULL,0,"in2",0,i)>0) // индикатор стрелка вниз

   if(iCustom(NULL,0,"in1",0,i)>0&&iCustom(NULL,0,"in1",0,i)<Bid*2&&iCustom(NULL,0,"in2",1,i)>0) // индикатор стрелка вверх
 

Please help me to solve this problem with the tester. I am testing position opening for CME on EUR/USD futures

On the rise of the market in the tester I open a long position on the breakdown with my stop and the trade gets a ticket #2. The market goes up and the next position is opened with a stop and the trade gets ticket #3 in the tester.

When the market goes against the position #3 and reaches its stop, ideally #3 should close at the stop, and #2 should stay there, waiting for the price to reach the stop #2. But for some reason, when stop #3 triggered, the tester closes position #2 as well.

The code for mql5 is

MqlTradeRequest request={};
MqlTradeResult  result={};
                                 
request.action = TRADE_ACTION_DEAL; //Вход рынку
request.symbol = Symbol();
request.volume = 1.0; //Кол-во фьючей
request.type   = ORDER_TYPE_BUY; //Купить
request.price  = SymbolInfoDouble(Symbol(),SYMBOL_ASK);   
request.sl     = NormalizeDouble(sl,5); // Стоп

bool check     = OrderSend(request,result);


 
NastyaMaley:

Please help me to solve this problem with the tester. I am testing position opening for CME on EUR/USD futures

On the rise of the market in the tester I open a long position on the breakout with my stop and the trade gets number 2. The market went up and the next position is opened with a stop, the trade gets number 3 in the tester.

When the market goes against position #3 and reaches its stop, the idea is that #3 should close at the stop and #2 should stay there, waiting for the price to reach stop #2. But for some reason, when stop #3 triggered, the tester closes position #2 as well.

The code for mql5 is


I do not know mql5, but I do not see where there is a choice of order to close
 
MakarFX:

the first indicator has a value of EMPTY_VALUE when there is no signal

should be done like this

Yes, that's right. That's it. Thank you very much.

 

I think the reason for the tester's behaviour has become clear. The type of demo account the robot is testing on is Netting. Therefore, if the stop specified when opening position #3 is triggered, it will close the entire volume of the position. Therefore, at the stop from #3, it closes #2 as well, even though it had its own separate stop set for it when it was opened.

With Hedging account type, everything would work like in good old mql4.

 
NastyaMaley:

Please help me to solve this problem with the tester. I am testing position opening for CME on EUR/USD futures

On the rise of the market in the tester I open a long position on the breakdown with my stop and the trade gets a ticket #2. The market goes up and the next position is opened with a stop and the trade gets ticket #3 in the tester.

When the market goes against the position #3 and reaches its stop, ideally #3 should close at the stop, and #2 should stay there, waiting for the price to reach the stop #2. But for some reason, when stop #3 triggered, the tester closes position #2 as well.

The code for mql5 is as follows

You should not use stops. Instead of using stops, we should place pending orders of the opposite direction.

Reason: