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

 
Good day to all.
I wrote a simple code in mql4 that opens an order on a minute chart every time the price rises 30 pips from the nearest local minimum. After opening the order, the local low becomes the opening price of the order.
void OnTick()
{
if (Bid<LoU)
LoU=Bid;
//********************
if (Bid-LoU>=0.0030&&Pr!=LoU)
{
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0);
Pr=LoU;
LoU=Bid;
}
}

What I don't like about my code..... That it has to be executed on almost every tick. I can improve this code and it will not be executed on every tick, but on almost every minute candle. It means that the program has to do a huge amount of work to find the point where the order is opened.

Q:

Could you please suggest a language structure which would help me find the open point of the order mentioned in my code without trying ticks or candlesticks, or with a minimum possible try, i.e. for the program to spend as little time as possible on finding the open point.

Thank you for your help.

 
ANDREY:
Good day to all.
I wrote a simple code in mql4 that opens an order on a minute chart every time the price rises 30 pips from the nearest local minimum. After opening the order, the local low becomes the opening price of the order.

What I don't like about my code..... It has to be executed on almost every tick. I can improve this code and it will not be executed on every tick, but on almost every minute candle. It means that the program has to do a huge amount of work to find the point where the order is opened.

Q:

Could you please suggest a language structure which would help me find the open point of the order mentioned in my code without trying ticks or candlesticks, or with a minimum possible try, i.e. for the program to spend as little time as possible on finding the open point.

Thanks for the help.

//+------------------------------------------------------------------+
int OnInit()
  {
   LoU=Bid;
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   if ((Bid+30*Point)<=LoU)
     {
      if(OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0)) LoU=Bid;
     }
  }
 
MakarFX:

Thank you for your help.

But the result of my code is not the same as mine. Here is the result of my code on GBPUSD on a minute chart over a day from 04.01.2010 to 05.01.2010.
This is the result of my code

And this is a result of your code

 
ANDREY:

Thank you for your help.

But the result of my code is not the same as mine. Here is the result of my code on GBPUSD on a minute chart over a day from 04.01.2010 to 05.01.2010.
This is the result of my code

This is a result of your code

Show code OnInit()

 
MakarFX:

Show me the OnInit() code.

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

I just copied your code into MetaEditor and got the result, which is above.

Your code opens an order and counts 30 pips downwards (yellow), and mine counts downwards (blue)

Thank you for your help

 
ANDREY:

I just copied your code into the MetaEditor and got the result above.

Thanks for your help.

I need your code to understand the point.

In your code LoU changes on every tick if price goes down, but in mine LoU changes only after opening a trade.

 
MakarFX:

I need your code to understand what the point is.

In your code, the LoU changes on every tick if the price goes down, whereas my LoU changes only after a trade is opened.

You have 30 pips on the wrong side. I added a picture to the previous post
And my code is in the first post. As soon as the price has passed 30 pips from the local minimum *bottom-up* - open an order. And my code opens the order exactly as I need it. But I want it to spend minimal time for that.

Agreed in my code LoU changes on every tick after opening each order. Without it the programme will not find the nearest local minimum, from which we should count 30 pips. I am thinking how to exclude the LoU change at every tick or at every minute candlestick, but the orders will be opened in the same places where my code opens them.
 
ANDREY:

I just copied your code into MetaEditor and got the result above.

Your code opens order and counts 30 pips downwards (yellow), and mine counts downwards (blue)

Thank you for your help

My mistake...replace

double LoU;
int OnInit()
  {
   LoU=Bid;
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   if ((Bid-30*Point)>=LoU)
     {
     
      if(OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0)) LoU=Bid;
     }
  }
 
MakarFX:

My mistake...replace

Thanks for your help.
I did. It opens a huge number of orders (27657 orders), among which are the ones I need

Here is a screenshot of initial orders

 
MakarFX:

My mistake...replace

Here's your code with the changed line.

double LoU;
int OnInit()
  {
   LoU=Bid;
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   if ((Bid+30*Point)>=LoU)
     {
     
      if(OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,0,0,"300",0)) LoU=Bid;
     }
  }
How can I make the code open only the required orders?
Reason: