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

 

Good afternoon, need help with the code, I am a newbie.

The problem there is the following - trailing works only in buy direction, and in sell direction does not work and the code gives error"Error of ordermodification. Error code=4051".

Here is the part of the code responsible for trailing:

void Trailing(int tral)
{ 
  int Mag=OrderMagicNumber();  

  OrderSelect(Mag,MODE_TRADES);

//+------------------------------------------------------------------+

//|                      tral buy                                    |

//+------------------------------------------------------------------+

  if (OrderType()==OP_BUY)

  if(Bid-OrderOpenPrice()>Point*tral)
    {
    if(OrderStopLoss()<Bid-Point*tral) 
       { 
       bool ress= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*tral,Digits),0,0,Blue); 
       if(!ress) 
          Print("Ошибка модификации ордера. Код ошибки=",GetLastError()); 
       else 
          Print("Цена Stop Loss ордера успешно модифицирована.");
       }
     }
//+------------------------------------------------------------------+

//|                      tral sell                                   |

//+------------------------------------------------------------------+   
  if (OrderType()==OP_SELL)
  if(OrderOpenPrice()-Ask>Point*tral)
    {
    if(OrderStopLoss()>Ask+Point*tral) 
       { 
       bool res= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*tral,Digits),0,0,Red); 
       if(!res) 
          Print("Ошибка модификации ордера. Код ошибки=",GetLastError()); 
       else 
          Print("Цена Stop Loss ордера успешно модифицирована.");
       }
     }
}          

 
Ivan Rozhkov:

Good afternoon, need help with the code, I am a newbie, I think it would not be appropriate to insert the whole code here.

The problem is that trailing works only in buy direction and does not work in sell direction and the code gives error"Error in ordermodification. Error code=4051".

Who can help me figure this out, please send a message to

This thread is for discussion, not couloirs.
 
Artyom Trishkin:
The topic is for discussion, not couloirs.

Please forgive me ^_^

Pasted part of the code, please advise where the error is

 
Ivan Rozhkov:

Please forgive me ^_^

Inserted part of the code, please tell me where the error is

Look in this thread - I've posted a trawl template. Somewhere in the middle.
 
Ivan Rozhkov:

Good afternoon, need help with the code, I am a newbie.

The problem there is the following - trailing works only in buy direction, and in sell direction does not work and the code gives error"Error of ordermodification. Error code=4051".

Here is the part of the code responsible for trailing:

//+------------------------------------------------------------------+

//|                      tral sell                                   |

//+------------------------------------------------------------------+   
  if (OrderType()==OP_SELL)
  if(OrderOpenPrice()-Ask>Point*tral)
    {
    if((OrderStopLoss()==0.0) || (OrderStopLoss()>Ask+Point*tral)) 
       { 
       bool res= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*tral,Digits),0,0,Red); 
       if(!res) 
          Print("Ошибка модификации ордера. Код ошибки=",GetLastError()); 
       else 
          Print("Цена Stop Loss ордера успешно модифицирована.");
       }
     }
}          
and I don't like the whole design, here's a simple trailing magik, almost the same as yours:

bool trailingpos(int magic_,int trail_p)
  {
   bool res=true; double sl,slnew,tpips=trail_p*Point; int i,k=OrdersTotal();
   for(i=0;i<k;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_)
           {
            switch(OrderType())
              {
               case OP_BUY:
                  slnew=NormalizeDouble(Ask-tpips,Digits);
                  sl=OrderStopLoss();
                  if(OrderOpenPrice()<slnew)
                     if((sl<slnew) || (sl==0.0))
                       {
                        if(!OrderModify(OrderTicket(),OrderOpenPrice(),slnew,OrderTakeProfit(),OrderExpiration(),clrNONE))
                          {res=false; Print(__FUNCTION__,"OrderModify завершилась с ошибкой № ",GetLastError());}
                       }
                  break;
               case OP_SELL:
                  slnew=NormalizeDouble(Bid+tpips,Digits);
                  sl=OrderStopLoss();
                  if(OrderOpenPrice()>slnew)
                     if((sl>slnew) || sl==0.0)
                       {
                        if(!OrderModify(OrderTicket(),OrderOpenPrice(),slnew,OrderTakeProfit(),OrderExpiration(),clrNONE))
                          {res=false; Print(__FUNCTION__,"OrderModify завершилась с ошибкой № ",GetLastError());}
                       }
                  break;
              }
           }
        }
     }
   return(res);
  }
 
how to correctly write an iCustom for ZigZag, so that it would output the values of extrema?
 
02031986dima:
how to correctly write an iCustom for ZigZag, so that it would produce the values of extrema?

You don't need to write anything, you just need to come and take

Только "Полезные функции от KimIV".
Только "Полезные функции от KimIV".
  • 2011.02.18
  • www.mql5.com
Все функции взяты из этой ветки - http://forum.mql4...
 
Igor Makanu:

I don't like the whole construction, here's a simple trailing magik, almost the same as yours:

Thank you very much for your help, adding your code trailing does not work for some reason, i must be doing something wrong((

if((OrderStopLoss()==0.0)

I added it and it worked, but it keeps getting spammed with errors #1 and #4051

#1-No error, but the result is unknown.

#4051- Invalidvalue of function parameter

 

Hello, there is an array of data type datatime,

how do I get it into a readable file?

Code:

int h=FileOpen("test",FILE_WRITE|FILE_CSV|FILE_UNICODE);
      FileWriteArray(h,timeHistory,0,WHOLE_ARRAY);
      FileClose(h);

It only writes if there is the FILE_BIN flag, but it writes unreadable.

If the FILE_BIN flag is not present, the file remains empty.

 
Karlinvain:

Hello, there is an array of datatime type data,

how do I get it into a readable file?

Code:

It only writes if there is the FILE_BIN flag, but it writes unreadable.

If the FILE_BIN flag is not present, the file remains empty.

FileWriteArray

Note .

A string array can only be written to a file of type TXT. In this case the strings are automatically terminated with "\r\n". Depending on the file type ANSI or UNICODE, the strings are converted to ansi-encoding, or not.

Reason: