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

 
yaaarik777:

Good evening!

Please help me write the code, I don't feel I can do it myself, here's the gist:


The bottom line is this: here in this thread to help the suffering and the seeking.
If you need to do it for you - this is a freelance. And to help you tell what you want to get, show what you have done and describe what failed.
 
Maxim Kuznetsov:
The point is this: here in this thread to help the suffering and the seeking.
If you need to do it for you - that's in the freelance. And to get help, you need to tell what you want to get, show what you're doing and describe what failed.


The point is, I don't understand how to make the EA analyse only the orders of one particular pair, rather than the orders of all pairs in the terminal.

If you can, please give me an idea or code example, as the textbooks describe separately what works and how it works, but there aren't many concrete examples.

I would be grateful for your help.

Thank you.

 
Hello.
It's been a long time since I picked up draughts, and when I did, it turned out

I don't know how to play.
I'm asking for help.
There's a good old-fashioned EA that uses Rosh's ZigZag indicator
And it works fine as swiss clock.
It has attached the code not to download the expert advisor given at the bottom of the text.

The idea of the EA was that orders are opened and closed at the moment of

coincidence of different ZigZags.
Now I need to replace the Rosh indicator with another

indicator, also one of the first versions of ZigZag from the time of MT3.
But this indicator has different algorithm of ZigZag drawing.

Its name is High_Low v2 (ZigZag), (in the attachment for some reason the name glitched)

By gut feeling method, which sometimes worked, I simply changed the conditions
double zz1 = iCustom( NULL, 60, "ZigZag_Rosh",12, 5, 3, 0, 0);
double zz2 = iCustom( NULL, 60, "ZigZag_Rosh",48, 20, 12, 0, 0);
on
double zz1 = iCustom( NULL, 0, "High_Low v2 (ZigZag)",300, 6, 0, 0);

double zz2 = iCustom( NULL, 0, "High_Low v2 (ZigZag)",300, 6, 0, 0);

I.e., I have replaced the name of one custom indicator and its

In the case of fractals, for example, it worked for me.

.
Parameters are the same, because two Zigzags do not need to be the same.

I have not needed coincidence of Zigzags, I need only the fact of its variation.
I have replaced number 60 with 0 to work in all TFs.

After the replacement, the EA compiled without errors, but it strongly refuses to work when attached to

Moreover, it refuses to work in the Strategy Tester.

does not want to work.

The question is: What's wrong?
And another question, what's the right way to do it?
Thanks, sorry for the big text.


//+------------------------------------------------------------------+
//| ZZ.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp.
#property link "http://www.metaquotes.net"

#include <stdlib.mqh>

#define MAGIC 20110220

extern double TakeProfit = 50;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialisation function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int pos=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL) pos++;
}
}
//---- return orders volume
if(pos>0) return(pos)
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
int res;

//---- get ZZ
double zz1 = iCustom( NULL, 60, "ZigZag_Rosh",12, 5, 3, 0, 0);
double zz2 = iCustom( NULL, 60, "ZigZag_Rosh",48, 20, 12, 0, 0);
//---- buy conditions
if(CompareDoubles(zz1,Low[0]) && CompareDoubles(zz2,Low[0])
{

res=OrderSend(Symbol(),OP_BUY,1,Ask,3,0,Ask+TakeProfit*Point,"",MAGIC,0,Bl

ue);
return;
}
//---- sell conditions
if(CompareDoubles(zz1,High[0]) && CompareDoubles(zz2,High[0])
{

res=OrderSend(Symbol(),OP_SELL,1,Bid,3,0,Bid-TakeProfit*Point,"",MAGIC,0,Re

d);
return;
}

//----
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//---- get ZZ
double zz1 = iCustom( NULL, 60, "ZigZag_Rosh",12, 5, 3, 0, 0);
double zz2 = iCustom( NULL, 60, "ZigZag_Rosh",48, 20, 12, 0, 0);
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(CompareDoubles(zz1,High[0]) && CompareDoubles(zz2,High[0])

OrderClose(OrderTicket(),OrderLots(),Bid,3);
break;
}
if(OrderType()==OP_SELL)
{
if(CompareDoubles(zz1,Low[0]) && CompareDoubles(zz2,Low[0])

OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
break;
}
}
//----
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
//+------------------------------------------------------------------+













MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
Торговая платформа MetaTrader 5 - это бесплатный инструмент трейдера, позволяющий торговать на форексе и фондовых биржах.
Files:
 
yaaarik777:


The point is that I don't understand how to make the EA only count orders of one particular pair, and not the total of all pairs in the terminal.

I don't understand how to make an EA calculate only orders of one particular pair, and not the sum of all pairs in the terminal.

I will be very grateful for help.

I would appreciate it.

feel free to look into the CodeBase - every EA has an order loop :-)

For example https://www.mql5.com/ru/code/16588 (the first one I came across)

  for(int index = orders-1; index >= 0; index--)
      {
      if(OrderSelect(index,SELECT_BY_POS,MODE_HISTORY)==false)
         {
         Print("Error in history!");
         break;
         }
      if(OrderSymbol()==symbol && OrderMagicNumber()==MAGICMA)
         {
         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
            {
            if(OrderProfit()>0) break;
            if(OrderProfit()<0) losses++;
            }
         }
      }

the"if(OrderSymbol()==symbol && OrderMagicNumber()==MAGICMA)" condition is exactly what selects orders by a specific symbol and with a specific MAGIC

PS/ in the above copy-paste code break in case of an OrderSelect error is not quite correct, rather use continue (no matter what the reason is the order is not picked, maybe there is a problem with some internal MetaTrader mechanism, but the next order won't be skipped)

Middle Moving Average
Middle Moving Average
  • votes: 6
  • 2016.10.18
  • Dmitriy Kudryashov
  • www.mql5.com
Вариант советника, основанного на среднем значении цены для расчета Moving Average.
 
Maxim Kuznetsov:

feel free to look into the CodeBase - every EA has an order loop:-)

For example https://www.mql5.com/ru/code/16588 (the first one I came across)

Not only is it in CodeBase, it's in one of the two threads on the forum, the important thing is to start looking and there will be over a hundred of them in different interpretations.
 
Thank you, I will be visiting
 

Hello guys!!! Help me write a function that would return a buy or sell signal. I don't know how to work with bars in MQL yet (although I don't know a lot of things!).

The condition is as follows: the parent bar is a bar inside which, namely, inside the high and low is a bar with the close price (it's important!!! exactly the close price.) Once some bar pierces the parent one and closes above the high or below the low, it now becomes the parent bar!

If the close price of the parent bar is higher than the open price, we return the signal to buy.

If the close price of the mother bar is lower than the open price, we return the signal to sell.

It is very important to set the timeframe in the external variable.

But here is the problem, at least for me, how can the Expert Advisor find the last matte bar on the chart? Yes, visually I can see it right away! ....

It would be convenient for me to specify the index of the last MAT bar in an external variable and then the function will start dancing from it; or another variant to take a bar with the index, for example, 50 and go through the loop to zero.

Very please help orphan!!!

 

Good afternoon!

Can you give me an idea? We need an EA to be unable to open an order if an order has already been opened at this price. How to implement the check?

 
Kot:

Good afternoon!

Can you give me an idea? We need an EA to be unable to open an order if an order has already been opened at this price. How to implement the check?

This is a difficult task. Out of desperation, I used to assign a magic order to the desired_price/_Point given the slippage.

It is much easier in mql5: there is a position with a price that does not correspond to the requested price and an order with the requested price.

 
Kot:

Good afternoon!

Can you give me an idea? We need an EA to be unable to open an order if an order has already been opened at this price. How to implement the check?


You write a loop of orders, in which you compare the opening price of each order with the given price value, and if there is a match, then the flag of a new order is not raised.