How to start with MQL5 - page 35

 
Vladimir Karputov #:

What principle do you use to place a pending order? Which bar do you check?

on rectangle values. SellLimit from Upper Rectangle & BuyLimit from Lower Rectangle values
 
daengrani #:
on rectangle values. SellLimit from Upper Rectangle & BuyLimit from Lower Rectangle values
 
Vladimir Karputov #:

Don't use 'OnChartEvent' - do your checks in OnTick.

I put it at OnTick()

void OnTick()
{
   HandleRect();
   CalculateOrders();
//--- we work only at the time of the birth of new bar
   static datetime PrevBars=0;
   datetime time_0=iTime(m_symbol.Name(), Period(), 0);
   if(time_0==PrevBars)
      return;
   PrevBars=time_0;
//---
   ManageTrades();

   /*
   if(ObjectFind(0, sUpRectangle)!=-1) {
      Comment ("Rectangle Low : ", DoubleToString(UpperRectLow, _Digits), "\n",
               "Rectangle High : ", DoubleToString(UpperRectHigh, _Digits), "\n",
               "SellLimit Price : ", DoubleToString(ObjectGetDouble(0, sUpRectLabelPrice, OBJPROP_PRICE, 0), _Digits), "\n",
               "SellLimit SL : ", DoubleToString(ObjectGetDouble(0, sUpRectLabelSL, OBJPROP_PRICE, 0), _Digits)
              );
   }
   else if(ObjectFind(0, sDnRectangle)!=-1) {
      Comment ("Rectangle High : ", DoubleToString(LowerRectHigh, _Digits), "\n",
               "Rectangle Low : ", DoubleToString(LowerRectLow, _Digits), "\n",
               "BuyLimit Price : ", DoubleToString(ObjectGetDouble(0, sDnRectLabelPrice, OBJPROP_PRICE, 0), _Digits), "\n",
               "BuyLimit SL : ", DoubleToString(ObjectGetDouble(0, sDnRectLabelSL, OBJPROP_PRICE, 0), _Digits)
              );
   }
   */
//---
}
It creates rectangle at OnInit.. I add price label & trendline on that rectangle just for visualisation. Values from rectangle that uses for level price & SL for limit orders
 
daengrani # :

I put it at OnTick()

I'll take a look at it tomorrow. It's very late today - it's time to sleep :)

 
Vladimir Karputov #:

I'll take a look at it tomorrow. It's very late today - it's time to sleep :)

Okay sir, thank you

It's fine when using indicators value, thanks to you for open this thread i learned a lot...


 
daengrani # :

Okay sir, thank you

It's fine when using indicators value, thanks to you for open this thread i learned a lot...


I launched it and immediately saw that the stop loss for 'Buy Limit' was set somewhere in the wrong place:

 
Vladimir Karputov #:

I launched it and immediately saw that the stop loss for 'Buy Limit' was set somewhere in the wrong place:

My mistake

   InitialLot        = NormalizeLot(Symbol(), InpLotPercent>0 ? InpLotPercent*balans/100/1000 : InpLots);
   LongEntryPrice    = NormalizeDouble(LowerRectHigh + ExtAddPips + dRecentSpread, _Digits);
   LongSL            = NormalizeDouble(LowerRectLow - ExtTakeProfit, _Digits); // it has to be : ExtAddPips
   LongTP            = NormalizeDouble(LongEntryPrice + ExtTakeProfit, _Digits);
   ShortEntryPrice   = NormalizeDouble(UpperRectLow - ExtAddPips, _Digits);
   ShortSL           = NormalizeDouble(UpperRectHigh + ExtAddPips + dRecentSpread, _Digits);
   ShortTP           = NormalizeDouble(ShortEntryPrice - ExtTakeProfit, _Digits);

but modify orders still don't work..

those rectangle will be dragged manually (near last SnD) & limit order has to be modified accordingly

I saw that OnChartEvent very responsive to detect values of rectangle changes. Whenever i dragged that rectangle, their values change realtime
 
daengrani # :

My mistake

but modify orders still don't work..

those rectangle will be dragged manually (near last SnD) & limit order has to be modified accordingly

I saw that OnChartEvent very responsive to detect values of rectangle changes. Whenever i dragged that rectangle, their values change realtime

Broken call logic

//--- handle buylimit
   if(count_buylimit>0)
     {
      if(buylimit_op!=LongEntryPrice || buylimit_sl!=LongSL || buylimit_tp!=LongTP)
        {
         ModifyPending(ORDER_TYPE_BUY_LIMIT, LongEntryPrice, LongSL, LongTP);
        }
     }
//--- handle selllimit
   if(count_selllimit>0)
     {
      if(selllimit_op!=ShortEntryPrice || selllimit_sl!=ShortSL || selllimit_tp!=ShortTP)
        {
         ModifyPending(ORDER_TYPE_SELL_LIMIT, ShortEntryPrice, ShortSL, ShortTP);
        }
     }

and the logic inside the function 'ModifyPending':

 
Vladimir Karputov #:

Broken call logic

and the logic inside the function 'ModifyPending':

Okay, i'll check it

I found it, very stupid mistake i made. I didn't see it before. Thank you very much Sir

 
daengrani #:

Okay, i'll check it

I found it, very stupid mistake i made. I didn't see it before. Thank you very much Sir

Dear Vladimir,

I put modify pending code at OnChartEvent...


They're very responsive.