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

 
Alexey Viktorov:

Just like that.

Thank you, just what I need!

 

Good afternoon!

Could you please advise on this issue?

I place a pending order:

bool send1=OrderSend(Symbol(),OP_BUYSTOP,Lots,Price,3,SL,TP,NULL,MagicNumber,0,clrGreen);

And then I try to make a trailing stop on it after it is opened:

 {
 for(int i=0; i<OrdersTotal(); i++) 
  {
  if(OrderSelect(i,SELECT_BY_POS))
  if(OrderSymbol()==Symbol()||OrderMagicNumber()==MagicNumber)
  if(OrderType()==OP_BUY)
   {
  if(TrailingStop>0)  
    {                 
  if(Bid-OrderOpenPrice()>TrailingStop)
     {
  if(OrderStopLoss()<Bid-TrailingStop)
      {
     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop,OrderTakeProfit(),0,clrRed);
      }
     }
    }
   }
  }
 }

After its opening the order becomes OP_BUY? What is the trick, why trailing does not work in this case?

 
YanSay:

Good afternoon!

Could you please advise on this issue?

I place a pending order:

And then I try to make a trailing stop on it after it is opened:

After its opening the order becomes OP_BUY? What is the trick, why trailing does not work in this case?

100500 reasons. The 1st obvious one is that Bid-TrailngStop is not normalised. It could be even closer to the stopplevel and then also opaque.
 
YanSay:

Good afternoon!

Could you please advise on this issue?

I place a pending order:

And then I try to make a trailing stop on it after it is opened:

After its opening the order becomes OP_BUY? What is the trick, why trailing does not work in this case?

TrailingStop in pips? Multiply by Point then.
 

I asked the wrong question, sorry. Taken out of context.

Especially to test trailing code, trades open, but trailing does not work, no matter how I turned it, deadlocked(

//Вводные
#define  MagicNumber 150
double SL=0;                        //Stop Loss
input int Trailing=100;             //Трэйлинг

//Код

void OnTick()
{
 if (OrdersTotal()==0)
 {
   if(TimeCurrent()>StrToTime("17:59")&&TimeCurrent()<StrToTime("18:01"))
  {
SL = Low[1]-Point; //Стоп лосс
bool send1=OrderSend (Symbol(), OP_BUY,1,Bid,30,SL,0,NULL,MagicNumber,0,clrNONE);
  }
 }
 if (OrdersTotal()>0)
   {
      for (int i=0; i<OrdersTotal (); i++)
    {
   bool select1=OrderSelect (i, SELECT_BY_POS);
   if (OrderMagicNumber() == MagicNumber && OrderSymbol () == Symbol())
     {
   if (OrderType()==OP_BUY)
      {
     if (NormalizeDouble(Ask-OrderStopLoss(),Digits)>NormalizeDouble(Trailing,Digits))
     bool modify1=OrderModify (OrderTicket(),0,Ask-Trailing,OrderTakeProfit(),0,CLR_NONE);
      }
     }
    }
   }
}
 
YanSay:

I asked the wrong question, sorry. Taken out of context.

Especially to test trailing code, trades open, but trailing does not work, no matter how I turned it, deadlocked(

Answered your question above.
 
Vladislav Andruschenko:
Answered your question above.
Thank you very much, it helped!
 
YanSay:
Thank you very much, it helped!

You still have problems there.

The loop is forward, it should be reverse - forward will skip positions after one of them closes on the trawl

There is no check for minimum stop distance (StopLevel) - there will be modification errors if the stop is closer to the price than the minimum allowed distance (don't forget about floating spread)

Maybe something else - looked diagonally - in passing, since you have already been told.

ZS. Looked again:

if (NormalizeDouble(Ask-OrderStopLoss(),Digits)>NormalizeDouble(Trailing,Digits))

this is the kind of check that lacks the very point of checking with normalisation, as you have normalised both values and when you check, the result is not normalised again.

You need to check the normalized difference of the two double values. You are comparing two normalized values.

 
Artyom Trishkin:

You still have problems there.

The loop is forward; it must be reverse - with a forward loop positions will be skipped after one of them closes on the trawl

There is no check for minimum stop distance (StopLevel) - there will be modification errors if the stop is closer to the price than the minimum allowed distance (don't forget about floating spread)

Maybe something else - looked diagonally - in passing, since you have already been told.

ZS. Looked again:

this is the kind of check that lacks the very point of checking with normalisation, as you have normalised both values and when you check, the result is not normalised again.

You should check the normalized difference of two double-values. You are comparing two normalized values.

Like this?

for (int i = OrdersTotal() - 1; i >= 0; --i)
if (NormalizeDouble((Ask-OrderStopLoss()>Trailing*Point),Digits))
 
the size of local variables is too large (more than 512 kb)
What does the error mean?


I have a function with two objects:

bool              CheckCandleOneRules(CCandlePropertiesBase *candle,
                                      CCandleRule *rule,
                                      int dir);

One of the classes has a structure with more than 4000 fields (mostly enums).

What to do with this error?

Reason: