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

 
why are time and price points 2 to 30 available inObjectCreate? tried adding to the chart, only the first point is shown
ObjectCreate(0,"name",OBJ_ARROW_LEFT_PRICE,0,TimeCurrent()-600,1.29400,TimeCurrent()-1200,1.29500);   
 
Valerius:

You don't need to write this code in OnInit, but in OnTick().

I tried it, it doesn't work at all.
1 warning
 
Igor Makanu:

No,you can'T.

I can't explain how.... templates work it's like this - until you call such a function, the compiler knows nothing about its existence (often, there are even no compiler errors if there is no call)

then you call such a template function and the compiler fills the needed types and only then checks that everything will work properly

and then you make another call to the template with different types of parameters - and the compiler creates a new function, i.e. one more, i.e. as if you write 2 functions, which do the same thing, but with different types of parameters


whew, that's how it works ))))



UPD:

you can, but if the types in the template match, here's an example, it works correctly:

Thanks, even clearer than in the docs) It turns out in the template predefinition of variables does not allow not to specify them. I need it for printing to a file. The log does not give me the option of splitting the records. I wish there were 5 logs). As a result, templates give an option not to bring the type of variable to the desired one, it can be done inside a template function, but the number of variables must be specified in full. A simple function with predefined variables of the required type gives an opportunity to specify fewer variables at a call, but the types of variables must be brought to the right one. Of course, this can be done at the call, but the record will be too long.

 
Valerius:

Good afternoon everyone!

I made a function to modify stoploss. But when it works it gives out EURUSD,H1: OrderModify error 130.

And the price is far from the place where stoploss should be set.

Here is the function:


....
    err=OrderModify(OrderTicket(), OrderOpenPrice(),New_Stop( NormalizeDouble(OrderOpenPrice()+spred*point, 
digits)), OrderProfit(), 0, clrNONE);// Цена открытия плюс спред может быть в зоне заморозки.
.....
.....
double New_Stop(double Parametr) // Проверка стоп-прик.
  {
   double Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// Миним. дистанция
   if(Parametr<Min_Dist) // Если меньше допуст.
     {
      Parametr=Min_Dist;                        // Установим допуст.
      Alert("Increased the distance of a stop order or the opening price of pending orders.");
     }
   return(Parametr);                            // Возврат значения
  }
 
Valerius:

Try it this way:


Thank you, it worked!

But two more nuances:

1 what condition to add not to close orders that were opened on Friday of the current week, and on Fridays of previous weeks, respectively, were closed ?

2. how to correct the code - OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(nameSym,MODE_ASK),MarketInfo(nameSym,MODE_DIGITS)),3,CLR_NONE);

to remove"possible loss of data due to type conversion" warning? Appears to be about "...MarketInfo(nameSym,MODE_DIGITS)...".

 
Good evening. What should the code that selects the most recently closed order look like? Is it really like this:"OrderSelect(OrdersHistoryTotal, SELECT_BY_POS, MODE_HISTORY"?
 
GetAmountLotFromOpenPos function returns -1717986918 how can I fix it?
 

Please advise.

In the tester, the return value of the GetAmountLotFromOpenPos lot summing function gives a value of -1717986918.

 
Valeriy Yastremskiy:

I found the reason. I should have put OrderTakeProfit() in OrderModify instead of OrderProft(). I've looked through it a bit.

Thanks for the help anyway.

 
Yerkin Sagandykov:

Thank you, it worked!

But two more nuances:

1 what condition to add not to close orders that were opened on Friday of the current week, and on Fridays of previous weeks, respectively, were closed?

2. how to correct the code - OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(nameSym,MODE_ASK),MarketInfo(nameSym,MODE_DIGITS)),3,CLR_NONE);

to remove"possible loss of data due to type conversion" warning? It must be about "...MarketInfo(nameSym,MODE_DIGITS)...".

For the first question, you need to make this function:


for(int is=OrdersTotal()-1; is>=0; is--)
{
if(OrderSelect(is,SELECT_BY_POS,MODE_TRADES))
{//Close orders which have been opened on Friday of the week which is not the current week. In this case, we are not closing orders on Friday of the current week.
if(OrderMagicNumber()==Magic && TimeDayOfWeek(TimeCurrent())==5 && TimeDayOfWeek(OrderOpenTime())==5 && TimeDayOfYear(OrderOpenTime())<TimeDayOfYear(TimeCurrent())
{
if (OrderType()==OP_BUY) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(nameSym,MODE_BID),MarketInfo(nameSym,MODE_DIGITS)),3,CLR_NONE);
if (OrderType()==OP_SELL) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(nameSym,MODE_ASK),MarketInfo(nameSym,MODE_DIGITS)),3,CLR_NONE);
if(!result) {error=GetLastError(); Print("LastError = ",error, ",Symbol()); }
else {error=0;}
else
{Print("NoMagic ",OrderMagicNumber();} // for Debug
else

{Print("Error when order select ", GetLastError();}


For the second question, there should be the following entry:

OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(MarketInfo(nameSym,MODE_ASK)), 3, clrNONE);

Good luck.

Reason: