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

 
Igor Zakharov:

Corrected... But there's one left for some reason.



And I can't reproduce it in the tester. I just don't have it on the same date


 

Why can't I connect library in mql4 from c++? Here is my code in Visual Studio 2012 C++. File main. with cpp extension (main.csr)

#define  MT4_EXPFUNC __declspec(dllexport) создал макрос чтобы не писать запись __declspec(dllexport)int __stdcall add(int a=0, int b=0)
//__declspec(dllexport)int __stdcall add(int a=0, int b=0)и так пробовал тоже
MT4_EXPFUNC int __cdecl add(int a=0, int b=0)//stdcall данная примитивная функция ничего не делает а просто возвращает значение 18
{return (18);пробовал так return 18;}

Then I created a file with main extension def (main.def) that has a list of exported functions, the code looks like this :

LIBRARY "dllmt42"
EXPORTS
add

Then I imported it into compiler

#import "dllmt42.dll"
int _add(int a=0, int b=0);
#import

No problems after compilation, but when you leave the EA on the chart, I get confused

Unresolved import function call, find '_add' in 'dllmt42.dll'. Total Comander sees the function as well as the compiler itself when dragging the file

Who can help?

 
Alexandr Sokolov:

Corrected... But there's one left for some reason.

And I can't reproduce it in the tester. I do not have this error on the same date

This error shows that you are trying to modify a position/order at the price at which you made the modification earlier...

 

Trying to retrieve indicator data in MT5 using a function:

//************************************************************************************************/
double Envelopes(string symb, ENUM_TIMEFRAMES TF_1, int period, int method, int shift, int price,double Deviation(ENUM_TIMEFRAMES TF_2, int kanal), int buff, int index)
{
  double buf[1];
  int handle=iEnvelopes(Symbol(), TF_1, period, method, shift, price, Deviation(TF_2, kanal), buff);
   if(handle<0)
   {
    Print("Failed to create handle ATR, Error: ",GetLastError());
    return(WRONG_VALUE);
   } else
   {
    if(CopyBuffer(handle,0,index,1,buf)<0)
    {
     Print("Failed to copy data from the indicator ATR, Error: ",GetLastError());
     return(WRONG_VALUE);
    }
   }
   return(buf[0]);
}
//************************************************************************************************/

I get an error :


Please advise how to fix code for MT5

 
Vladimir Pastushak:

This error indicates that you're trying to modify a position/order at the price at which you've already modified it...

No, I checked it many times already, the problem was in the randomness of selecting the input parameters of MQL when testing the products, which are not always compatible - I fixed that too. But now I got a message that there is no open order


Although I have them on the same pairs and timeframes

 
Alexandr Sokolov:

No, I've already checked it many times. The problem was in randomness of selecting the input parameters of MQL when testing the products, which are not always compatible - I've already fixed that too. But now I got a message that there is no open order


But I have them on the same pairs and timeframes

I don't know why my EA does not trade.

 
Vladimir Pastushak:

Find out why the EA does not trade.

It may not trade if the input parameters are randomly chosen so that signals simply do not occur. But you should not limit it either

 

What is meant by" tradingfreeze distance "? Received through

SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL)

MQL4

 

I have error #1 again when modifying. In this EA, SL or TP levels are only modified in four blocks


1 block

if(OrderMagicNumber() == id_number && OrderStopLoss() != NormalizeDouble(0,_Digits) && BMod(OrderTicket()) == true)
           {
            if(OrderType() == OP_BUY)
              {
               if(OrderComment() == "1" && Bid - OrderOpenPrice() >= a1 && OrderStopLoss() != NormalizeDouble(OrderOpenPrice() + l1,_Digits)) {bol = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+l1,_Digits),OrderTakeProfit(),0,clrNONE);};
               if(OrderComment() == "2" && Bid - OrderOpenPrice() >= a2 && OrderStopLoss() != NormalizeDouble(OrderOpenPrice() + l2,_Digits)) {bol = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+l2,_Digits),OrderTakeProfit(),0,clrNONE);};
              }
            else
              {
               if(OrderComment() == "1" && OrderOpenPrice() - Ask >= a1 && OrderStopLoss() != NormalizeDouble(OrderOpenPrice() - l1,_Digits)) {bol = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-l1,_Digits),OrderTakeProfit(),0,clrNONE);};
               if(OrderComment() == "2" && OrderOpenPrice() - Ask >= a2 && OrderStopLoss() != NormalizeDouble(OrderOpenPrice() - l2,_Digits)) {bol = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-l2,_Digits),OrderTakeProfit(),0,clrNONE);};
              };


2 block

if(BMod(OrderTicket()) == true && OrderMagicNumber() == id_number && (OrderStopLoss() == NormalizeDouble(0,_Digits) || OrderTakeProfit() == NormalizeDouble(0,_Digits)))
           {
            if(OrderComment() == "1")
              {
               bol = OrderModify(OrderTicket(),OrderOpenPrice(),(OrderType() == OP_BUY ? OrderOpenPrice() - sl : OrderOpenPrice() + sl),(OrderType() == OP_BUY ? OrderOpenPrice() + t1 : OrderOpenPrice() - t1),0,clrNONE);
              }
            else if(OrderComment() == "2")
              {
               bol = OrderModify(OrderTicket(),OrderOpenPrice(),(OrderType() == OP_BUY ? OrderOpenPrice() - sl : OrderOpenPrice() - sl),(OrderType() == OP_BUY ? OrderOpenPrice() + t2 : OrderOpenPrice() - t2),0,clrNONE);
              };


3 block

if(BMod(OrderTicket()) == true && OrderMagicNumber() == id_number && (OrderStopLoss() == NormalizeDouble(0,_Digits) || OrderTakeProfit() == NormalizeDouble(0,_Digits)))
           {
            if(OrderComment() == "1")
              {
               bol = OrderModify(OrderTicket(),OrderOpenPrice(),(OrderType() == OP_BUY ? OrderOpenPrice() - sl : OrderOpenPrice() + sl),(OrderType() == OP_BUY ? OrderOpenPrice() + t1 : OrderOpenPrice() - t1),0,clrNONE);
              }
            else if(OrderComment() == "2")
              {
               bol = OrderModify(OrderTicket(),OrderOpenPrice(),(OrderType() == OP_BUY ? OrderOpenPrice() - sl : OrderOpenPrice() + sl),(OrderType() == OP_BUY ? OrderOpenPrice() + t2 : OrderOpenPrice() - t2),0,clrNONE);
              };


4 block

if(BMod(OrderTicket()) == true && OrderMagicNumber() == id_number && OrderTakeProfit() == NormalizeDouble(0,_Digits))
              {
               if(MyOrders() == 1)
                 {
                  bol = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),(OrderType() == OP_BUY ? OrderOpenPrice() + t1 : OrderOpenPrice() - t1),0,clrNONE);
                 }
               else if(OrderTakeProfit() == 0)
                 {
                  bol = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),(OrderType() == OP_BUY ? OrderOpenPrice() + (OrderComment() == "1" ? t1 : t2) : OrderOpenPrice() - (OrderComment() == "1" ? t1 : t2)),0,clrNONE);
                 };


I have already checked everything many times but I can't find any errors

 
Alexandr Sokolov:

I have error #1 again when modifying. In this EA, SL or TP levels are only modified in four blocks



OrderStopLoss() != NormalizeDouble(0,_Digits)


This is not correct, also in other examples

If you put a stop at 1.2356 and on a new tick you put a stop at 1.2356 again, you will get error 1

Reason: