Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 800

 
Good afternoon! Help to understand the functions, and how it works, thank you in advance.
//+----------------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//|  Версия   : 28.11.2006                                                     |
//|  Описание : Модификация одного предварительно выбранного ордера.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    pp - цена установки ордера                                              |
//|    sl - ценовой уровень стопа                                              |
//|    tp - ценовой уровень тейка                                              |
//|    ex - дата истечения                                                     |
//+----------------------------------------------------------------------------+
void ModifyOrder(double pp=-1,double sl=0,double tp=0,datetime ex=0) 
  {
   bool   fm;
   color  cl=IIFc(OrderType()==OP_BUY
                  || OrderType()==OP_BUYLIMIT
                  || OrderType()==OP_BUYSTOP, clModifyBuy, clModifySell);
   double op,pa,pb,os,ot;
   int    dg=MarketInfo(OrderSymbol(),MODE_DIGITS),er,it;

   if(pp<=0) pp=OrderOpenPrice();
   if(sl<0 ) sl=OrderStopLoss();
   if(tp<0 ) tp=OrderTakeProfit();

   pp=NormalizeDouble(pp, dg);
   sl=NormalizeDouble(sl, dg);
   tp=NormalizeDouble(tp, dg);
   op=NormalizeDouble(OrderOpenPrice() , dg);
   os=NormalizeDouble(OrderStopLoss()  , dg);
   ot=NormalizeDouble(OrderTakeProfit(), dg);

   if(pp!=op || sl!=os || tp!=ot) 
     {
      for(it=1; it<=NumberOfTry; it++) 
        {
         if(!IsTesting() && (!IsExpertEnabled() || IsStopped())) break;
         while(!IsTradeAllowed()) Sleep(5000);
         RefreshRates();
         fm=OrderModify(OrderTicket(),pp,sl,tp,ex,cl);
         if(fm) 
           {
            if(UseSound) PlaySound(SoundSuccess); break;
              } else {
            er=GetLastError();
            if(UseSound) PlaySound(SoundError);
            pa=MarketInfo(OrderSymbol(), MODE_ASK);
            pb=MarketInfo(OrderSymbol(), MODE_BID);
            Print("Error(",er,") modifying order: ",ErrorDescription(er),", try ",it);
            Print("Ask=",pa,"  Bid=",pb,"  sy=",OrderSymbol(),
                  "  op="+GetNameOP(OrderType()),"  pp=",pp,"  sl=",sl,"  tp=",tp);
            Sleep(1000*10);
           }
        }
     }
  }
//+----------------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//|  Версия   : 11.09.2008                                                     |
//|  Описание : Сопровождение позиций простым тралом                           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ( ""  - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   ( -1  - любая позиция)                  |
//|    mn - MagicNumber                ( -1  - любой магик)                    |
//+----------------------------------------------------------------------------+
void SimpleTrailing(string sy="",int op=-1,int mn=-1) 
  {
   double po,pp;
   int    i,k=OrdersTotal();

   if(sy==NULL) sy=Symbol();
   for(i=0; i<k; i++) 
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) 
        {
         if((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) 
           {
            po=MarketInfo(OrderSymbol(),MODE_POINT);
            if(mn<0 || OrderMagicNumber()==mn) 
              {
               if(OrderType()==OP_BUY) 
                 {
                  pp=MarketInfo(OrderSymbol(),MODE_BID);
                  if(pp-OrderOpenPrice()>=TrailingStart*po) 
                    {
                     if(OrderStopLoss()<pp-(TStop_Buy+TrailingStep-1)*po) 
                       {
                        ModifyOrder(-1,pp-TStop_Buy*po,-1);
                       }
                    }
                 }
               if(OrderType()==OP_SELL) 
                 {
                  pp=MarketInfo(OrderSymbol(),MODE_ASK);
                  if(OrderOpenPrice()-pp>=TrailingStart*po) 
                    {
                     if(OrderStopLoss()>pp+(TStop_Sell+TrailingStep-1)*po || OrderStopLoss()==0) 
                       {
                        ModifyOrder(-1,pp+TStop_Sell*po,-1);
                       }
                    }
                 }
              }
           }
        }
     }
  }
//+----------------------------------------------------------------------------+
 
lihn:

Why did they erase the author of Igor Kim's functions?! Because of disrespect to the author, but it is obligatory to publish with the indication of authorship!

And it is better to address your question to the author in his branch! You can find it in a search or google!

 

Can you tell me if it is possible to draw multicoloured indicators in MQL4? Where can I get an example?


The MQL4 documentation contains INDICATOR_COLOR_INDEX, but the subject is not covered at all. I found an example in MQL5 - https://www.mql5.com/ru/articles/135 .

It compiles successfully, but does not work as intended. The PlotIndexSetInteger function used in the example compiled successfully, although it is not mentioned in MQL4 documentation.


There is one more inconsistency: the MQL4 doc contains a similar example in the description of the ArrayCopy function which also uses the PlotIndexSetInteger function.


Are the developers lost in their own wood, or what am I missing?

 
Dubovik:

Do you know if it is possible to draw different-colored indicators in MQL4? Where can I find an example?


The MQL4 documentation contains INDICATOR_COLOR_INDEX, but the subject is not covered at all. I found an example in MQL5 - https://www.mql5.com/ru/articles/135 .

It compiles successfully, but does not work as intended. The PlotIndexSetInteger function used in the example compiled successfully, although it is not mentioned in MQL4 documentation.


There is one more discrepancy: the MQL4 doc contains a similar example in the description of the ArrayCopy function and the PlotIndexSetInteger function is used there as well.


Are the developers lost in their own forest, or I don't understand something?

There are as many colours as there are buffers, look for them in Documentation, Code Base, Articles and in the Forum! And Google to the rescue!
 
borilunad:
As many colours, as many buffers, look in the Documentation, Codebase, Articles and the Forum! And Google to the rescue!

That's not what I mean, I mean indicators that have a buffer added like this:

 SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);
 
Dubovik:

That's not what I mean, I mean indicators that have a buffer added like this:

This parameter doesn't work in quadruple. As many buffers, as many colours
 
Is that in mcl4?!
 
Yeah, in MQL4. There's something in the documentation that's sketchy and doesn't actually work.
 
Dubovik:
Yeah, in MQL4. There's something in the documentation that's described in bits and pieces, but it doesn't actually work.
Strange, usually it's too late to put it in the doc, but now it's the other way around! So it will be! Only when?!
 

I don't understand what the problem is?

int start() 

{

bool i;

int ticket;

double Pricem;

datetime Timen; 

string Symb=Symbol();

ticket=OrderSend(Symb,OP_SELL,0.1,Bid,3,Ask+4*Point,Ask-12*Point);

i=OrderSelect(0,SELECT_BY_POS);

while(true)

{

RefreshRates();

Timen=OrderCloseTime();

  if(Timen>0)

   {

     Pricem=OrderClosePrice();

     Alert(Pricem);

     Alert("ордер закрылся");

     Sleep(30000);

 }

 Sleep(10);

 }

return;                              

}


A close message should appear. The order opens, gets to the stop, closes and that's it! Where is the error?