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

 
MakarFX:

Still, it checks on every tick

and the minimum calculation gets off... rolls back two bars.

My minimum calculation was getting hit like in your picture. But then I added the LoY1 variable and it stopped this error. As a result, all orders are opened the same way (by time, amount and price) as in my initial code, i.e. the way I need them. My code failed in another place .... But I fixed it in the same place.


double LoU,LoY1,Pr;
int x;
void OnTick()
{
if (Low[1]>Low[2]&&Time[2]>x&&Low[2]<LoY1)
{
LoU=Low[2];
LoY1=Low[2];
}
//**************************************************************
if (Bid-LoU>=0.0030&&Pr!=LoU)
{
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0);
Pr=LoU;
LoU=Bid;
LoY1=Bid;
x=TimeCurrent();
}
}

And you can also place pending order in 30 points from LoU instead of opening at market. And then you don't need to check Bid on every tick. But in the case of a pending order, every time LoU changes , we should delete the old pending order and set a new one, or change the parameters of a current pending order without deleting it. And all this should be done much less frequently than checking on every Bid tick .

Which variant in my case is the least time-consuming in terms of code implementation?

1. Check at each tick if the Bid is 30 points away from LoU

2. With each change of LoU, delete the old pending and set a new one.

3. With each change of LoU, change parameters of active LoU

Thank you for your help
.

 
ANDREY:

My calculation of the minimum was going off like in your picture. But then I added the LoY1 variable and it stopped it.

There are standard functions iLowest andiHighest.

 
ANDREY:

My calculation of the minimum was going off like in your picture. But then I added a variable LoY1 and it stopped this straying. As a result, all orders open the same way (by time, amount and price) as in my original code (i.e. the way I want). My code failed in another place .... But I fixed it in the same place.


And you can also place pending order in 30 points from LoU instead of opening at market. And then you don't need to check Bid on every tick. But in the case of a pending order, every time LoU changes , we should delete the old pending order and set a new one, or change the parameters of a current pending order without deleting it. And all this should be done much less frequently than checking on every Bid tick .

Which variant in my case is the least time-consuming in terms of code implementation?

1. Check at each tick if the Bid is 30 points away from LoU

2. With each change of LoU, delete the old pending and set a new one.

3. With each change of LoU, change parameters of the active position

1) x is not int, it's datetime (will come in handy in the future)

2) your initial code has no pending orders

3) Now your code makes more operations on each tick

Check your message

 
Taras Slobodyanik:

there are standard iLowest andiHighest functions.

Not suitable... the number of timeseries items is not constant
 
MakarFX:
It doesn't... the number of timeseries elements is not constant

er... does it prevent you from finding the high/low?

 
Taras Slobodyanik:

er... does that prevent you from finding high/low?

TheiLowest andiHighest functionsmean to search among a certain number of bars (number of timeseries elements)

in this case, the number is unknown and it changes every time

 
MakarFX:

1) x is not int, it is datetime (it will come in handy in the future)

2) your initial code has no pending orders

3) now your code makes more operations on each tick

Check your message.

This is my old code

This is my new code for the same time period as the old one

The number of operations per tick is much less important to me than the time spent on this number. And the new code takes 25% less time.... if I'm not mistaken.

Thanks for the help.

 
Aleksei Stepanenko:
There is a subtlety here. First we set the size and then by resetting to zero we release the fixation, this does not change the size. There is no other way around it.
Thank you very much!
 
MakarFX:

Still, it checks on every tick

and the calculation of the low gets off... rolls back two bars.

Below is my original code without your additions

Below with your latest improvements



Maybe if(TimeSeconds(TimeCurrent())==0) should be applied only to those sections where no orders are opened, and where the next minimum is looked for?

If I'm not mistaken thanks to your function my code started executing only at the beginning of each minute candle, that's why it opens orders not correctly.


Thanks for the help.

 
ANDREY:

Below is my original code without your additions

Below is the code with your latest improvements



Maybe, if(TimeSeconds(TimeCurrent())==0) should be applied only to those sections where no orders are opened, and where the next low is searched for?

If I am not mistaken, your function has started to execute my code only at the beginning of each minute candle.


Thanks for the help.

Yes