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

 
MakarFX:

mql4 is also possible here

I don't think that's it. The Expert Advisor creates a graphical object in the form of a trend line:

   if(PriceDemUp2() != 0 && PriceDemUp1() != 0)
      CreateLine(trendUp, TimeDemUp2(), PriceDemUp2(), TimeDemUp1(), PriceDemUp1(), TrendUpColor);
   if(PriceDemDw2() != 0 && PriceDemDw1() != 0)
      CreateLine(trendDw, TimeDemDw2(), PriceDemDw2(), TimeDemDw1(), PriceDemDw1(), TrendDwColor);

But after restarting the terminal, only parameters of the first point are available. The parameters of the previous point will appear only after the new point is formed. I think I am beginning to understand - I need to find not only the last point calculated by the indicator but also the previous one. How can I skip the last (first) point and calculate the next one? I find the first point this way:

int BarPointDemUp()
{
   int i;
   
   for(i = 0; i < 70; i++)
   {   
      if(iCustom(NULL, 0, "DeMark Point", LevelDP, 0, i) != 0)
         return(i);
   }
   return(-1);   
}
//////////////////////////////////////
int BarPointDemDw()
{
   int i;
   
   for(i = 0; i < 70; i++)
   {   
      if(iCustom(NULL, 0, "DeMark Point", LevelDP, 1, i) != 0)
         return(i);
   }
   return(-1);
 
Youri Lazurenko:

That doesn't seem to me to be the case. The EA creates a graphical object in the form of a trend line:

But after restarting the terminal only the parameters of the first point are available. The parameters of the previous point will appear only after the formation of a new point. I think I am beginning to understand - I need to find not only the last point calculated by the indicator but also the previous one. How can I skip the last (first) point and calculate the next one? I find the first point this way:

Put a counter.

int BarPointDemUp()
{
   int i;
   int c=0;
   for(i = 0; i < 70; i++)
   {   
      if(iCustom(NULL, 0, "DeMark Point", LevelDP, 0, i) != 0)
       c++;
        if(c==2)  return(i);
   }
   return(-1);   
}

In general, make an array and fill it, then take the required point from the array

 
Vitaly Muzichenko:

Set a counter

And in general, make an array and fill it, then take the desired point from the array.

Thank you. It seems to me that the counter you've provided is just what we need and, most importantly, simple.

While my site was being updated, I tried the variant you suggest. It all works. Thank you very much. So simple, and I was beginning to get into the thick of things. Plus, the price and time functions above have been simplified.

 
MakarFX:

I highlighted what was wrong

the yellow highlighting is unnecessary and can be deleted.

The green highlighted function must be outside OnStart(),

where you want to define a new bar, use the brown highlight.

Thanks!)

 

Good day to allJ Please help me find a working code of trailing stop on parabolic. I want to ask how to add this function to my Expert Advisor, so that it would trail when the price goes up a certain amount of points? I will thank in advance, and ask experienced and knowledgeable people - I should somehow add the Grail to it ;-)

 
DanilaMactep:

Good day to allJ Please help me find a working code of trailing stop on parabolic. I want to ask how this function should be added to my Expert Advisor, so that it would trail when the price goes up a certain amount of points? Many thanks in advance, and please do not pass by experienced and knowledgeable people - I should somehow add the Grail ;-)

like this

//+------------------------------------------------------------------+
   int    Tral = 50;
   double Sar  = iCustom(_Symbol,Period(),"Parabolic",0.02,0.2,0);
//+------------------------------------------------------------------+
   for(int pos=0;pos<OrdersTotal();pos++)
      if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()==_Symbol)
        {
         if(OrderType()==OP_SELL)
           {
            if(OrderOpenPrice()>Ask+Tral*Point&&OrderStopLoss()!= Sar)
            if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Sar,Digits),OrderTakeProfit(),0,clrNONE))
            {Print("Order SELL Modify")}
           }
         if(OrderType()==OP_BUY)
           {
            if(OrderOpenPrice()<Bid-Tral*Point&&OrderStopLoss()!= Sar)
            if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Sar,Digits),OrderTakeProfit(),0,clrNONE))
            {Print("Order BUY Modify")}
           }
        }
 

Can you tell me how to update month day to reflect the new day of year.


   datetime time_current=TimeCurrent();
   MqlDateTime time_structure;
   TimeToStruct(time_current,time_structure);
   int curr_day_year=time_structure.day_of_year;
   int start_day=(curr_day_year-m_days_back)>0?curr_day_year-m_days_back:0;
   time_structure.day_of_year=start_day;
   time_structure.hour=0;
   time_structure.min=0;
   time_structure.sec=0;
   datetime start_time=StructToTime(time_structure);

So, I thought the start_time would be with the changed day of year. But there's the old date...

Hmm... probably easier to take seconds off...

 
leonerd:

I can't think now, I'll give you an example, maybe you'll get an idea

//получаем номер недели в году
int GetWeekNumber(datetime eTime)
   {
   MqlDateTime eDate;
   //получаем дату начала года
   TimeToStruct(eTime,eDate);
   eDate.mon=1;
   eDate.day=1;
   eDate.hour=0;
   eDate.min=0;
   eDate.sec=0;
   datetime StartTime=StructToTime(eDate);
   //возвращаем дату назад в структуру, чтобы определить день недели начала года
   TimeToStruct(StartTime,eDate);
   return(int((eTime-StartTime+86400*eDate.day_of_week)/604800));
   }

an idea https://www.mql5.com/ru/users/integer

Dmitry Fedoseev
Dmitry Fedoseev
  • www.mql5.com
Профиль трейдера
 
MakarFX:

like this

Makar, thank you very much for the code - I've rewritten the code by passing external variables to icastom instead of fixed values. Please clarify, is intTral = 50; is this the distance at which the trawl will be kept or is it the distance in pips after which the trawl will be activated ?

 
DanilaMactep:

Makar, thank you very much for the code - I've rewritten the code by passing external variables to icastom instead of fixed values. Please clarify, is intTral = 50; is this the distance at which trawl will be set, or is it distance of profit in pips after which trawl will be set ?

it is distance of profit in pips after which the trawl is turned on