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

 
ANDREY:
Pr is a variable so that only 1 order is opened after 30 pips. Without this variable they open on every tick
if(OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0))
{LoU=Bid;}

So you don't need this variable...and there's already less load)

 
MakarFX:
Even worse... still need to know the number of bars


I tweaked ...try

I did. It's the same.
Your code.

double LoU,Pr;
int OnInit()
  {
   LoU=Low[0];
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   if(Low[1]<LoU) {LoU=Low[1];}
   if ((Bid-30*Point)>=LoU)
     {
      if(OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0)) LoU=Low[0];
     }
  }


 
MakarFX:

So you don't need this variable...and already the load is less)

Maybe I don't need it. But it's not the one I'm struggling with.....

 
ANDREY:

Probably not necessary. But it's not the one I'm struggling with.....

1) If you're struggling with speed, any code optimization is a plus.

2) The difference in results because you don't have LoU initialization at startup is nothing... EMPTY

 
MakarFX:
Even worse...still need to know the number of bars


I tweaked ...try

If Bid - Low[ ] >= 30 pips, open an order. But how do we know the number of thisLow[ ] after Bid goes above this Low[ ] by 30 pips?
 
ANDREY:
Alternatively, if Bid - Low[? ] >= 30 p. we should open an order. But how do we know the number of Low[ ] after Bid goes higher than Low[ ] by 30 points?

And if Bid goes down, that means a new low...and from which low should the calculation be made?

 
MakarFX:

1) If you're struggling with speed, any code optimization is a plus.

2) The difference in results because you don't have LoU initialisation- at startup doesn't equal anything... EMPTY

So if I assign a value to LoU when I declare it, the code will run much faster ?

I have assigned it the opening price of the first bar from 04.01.2010.

double LoU = 1.6121,Pr;
void OnTick()//531
{
if (Bid<LoU)
LoU=Bid;
//**************************************************************||TimeCurrent()==1262568096
if (Bid-LoU>=0.0030&&Pr!=LoU)
{
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0);
Pr=LoU;
LoU=Bid;

}
}
 
MakarFX:

And if Bid goes down, it means a new low...and what is the low to calculate from?

Let it go down, the main thing is that the order opens in 30 pips. And after it is opened, let the price go down to find the new minimum. Imagine that we have the current Bid and it is 30 points away from Low[ 50] and we can open an order. If ( Bid - Low[ 50] > 30 points ) - open an order, how will we know that it is the 50th candle low? So, in this case we should check not what was before the local minimum but what was after it.
And in this case it will not matter how much the price will fall after the order is opened.

 
ANDREY:

I don't think the fractal indicator is right for me. It will miss many orders.

The order opened by my code with price checking on each tick is highlighted in blue. It seems to me that a fractal does not say anything necessary to me in this case.

I gave a fractal as an example. And how you determine the minimum (in your case) is a military secret... or you do not understand what I am asking.

 
ANDREY:

Let it drop, the main thing is that the order will open in 30 pips. And after it is opened, let the price go down to find a new low. Imagine that we have the current Bid and it is 30 points away from Low[ 50] and we can open an order. if ( Bid - Low[ 50] > 30 points ) - open an order. But how to check if it is the 50th candle low? So, in this case we should check not what was before the local minimum but what was after it.

you don't need to count the bars

After the order is opened, assign to the variable the value Low[0] (the current bar minimum) and after the bar is closed, if the value of Low[1] is less than the variable, assign a new value,

if not, the old value is retained, i.e. the minimum.

Reason: