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

 
Порт-моне тв:

Can someone help me?

In order not to bother with figure names, you can find the figure with the most recent point dates. And then, when this figure is found, the question is for you: what event should be tracked? Intersection of horizontal, vertical, top-down, bottom-up.

The event to watch is OnChartEvent.

 

Good afternoon!

I used to be able to put a limit in the code for displaying the indicator values on the monitor. But with this indicator, nothing works. Maybe you can help me to put a limit into the code? Please!

Thank you!

Files:
Tipu_MACD.mq4  18 kb
 

Hello. Could you please tell me how to calculate the Bid price.

How do I calculate a Bid price which several BUY positions will have a total zero profit for currency pairs, where the base (first) currency is the dollar, and the pip value is not constant and depends on prices?

For pairs where the dollar is the quoted (second) currency and the pip value is constant I have derived the following function,

double Null_BUY(){ 
   double null=0; double summ_count=0; double lots_count=0; double position_count=0;
   for (int i=OrdersTotal()-1; i>=0; i--){
     if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
        if (OrderSymbol() == Symbol() ){
            if(OrderType()==OP_BUY ){
               position_count=Bid-((OrderProfit()+OrderSwap()+OrderCommission()) / OrderLots()*MarketInfo(Symbol(), MODE_TICKVALUE))*Point; 
               summ_count+=position_count*OrderLots();
               lots_count+=OrderLots();
            }
         }
      }
   }
   if(lots_count!=0) null=NormalizeDouble(summ_count/lots_count, Digits);
   return(null);
}
 
Forallf:

Can you give me a hint? I have drawn a line segment on a graph. I need to know the start and end prices of the segment. Can it be done?

I found an example. I made it like this.

//+------------------------------------------------------------------+
//|                                                        линия.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   //Проверим что есть трендовая линия и она в единственном экземпляре:
   if(ObjectsTotal(OBJ_TREND)!=1)
   {Comment("Нарисуйте 1 трендовую линию!");}

   //Получим ИМЯ трендовой линии:
   for(int i=0;i<ObjectsTotal();i++)
     {
      string name=ObjectName(i);
      if(ObjectType(name)==OBJ_TREND)
        {
         datetime t1=ObjectGet(name,OBJPROP_TIME1);
         datetime t2=ObjectGet(name,OBJPROP_TIME2);
         double p1=NormalizeDouble(ObjectGet(name,OBJPROP_PRICE1),Digits);
         double p2=NormalizeDouble(ObjectGet(name,OBJPROP_PRICE2),Digits);
         Comment(p1,"   ",p2);
        }
     }
  }
//+------------------------------------------------------------------+

Please help me make one more segment that would be horizontal to the middle of the first one. I will change the length of the first segment, so the location of the second segment should change too. Drawing from PRICE2 10 candles ahead.

Files:
EURUSDM12.png  25 kb
 
Forallf:

Found an example. Made it like this.

Please help me make another segment that would be horizontal to the middle of the first segment. I will change the length of the first segment, so the location of the second one should change, too. Drawing from PRICE2 10 candles ahead.

like this.


369
369
  • 2021.01.07
  • www.youtube.com
лин
 
Iurii Tokman:

there you go -


So.
 
Forallf:
Right.

this bicycle is a standard feature of the terminal
called Fibonacci lines

 
Iurii Tokman:

this bicycle is a standard feature of the terminal
called Fibonacci lines

The middle one is for me as an example. There will be a different, calculated level.
 
Forallf:
The middle is for me as an example. There will be another, calculated level.

You can find any point on a line by knowing the coordinates. In your case we know the start and end prices and dates of the segment. We can also find the price of the middle = (start price + end price)/2. Or any other formula you use.

Now we can use the first function to find the time of a point on a segment.

//находит дату точки (координату X) на прямой, на заданную цену (координата Y)
datetime GetPointTimeOnStraight(datetime eTime1, double ePrice1, datetime eTime2, double ePrice2, double ePrice3, string eSymbol, int eTimeFrame)
   {
   if(ePrice2-ePrice1==0) return(0.0);
   //индекс бара соответствующий заданному времени, возможно задавать будующее время
   int eIndex1=(eTime1>iTime(eSymbol,eTimeFrame,0))?(int)((iTime(eSymbol,eTimeFrame,0)-eTime1)/PeriodSeconds(eTimeFrame)):iBarShift(eSymbol,eTimeFrame,eTime1);
   int eIndex2=(eTime2>iTime(eSymbol,eTimeFrame,0))?(int)((iTime(eSymbol,eTimeFrame,0)-eTime2)/PeriodSeconds(eTimeFrame)):iBarShift(eSymbol,eTimeFrame,eTime2);
   int eIndex3=eIndex1+(int)((eIndex2-eIndex1)*(ePrice3-ePrice1)/(ePrice2-ePrice1));
   return(iTime(eSymbol,eTimeFrame,eIndex3));
   }

//находит цену точки (координату Y) на прямой, на заданное время (координата X)
double GetPointPriceOnStraight(datetime eTime1, double ePrice1, datetime eTime2, double ePrice2, datetime eTime3, string eSymbol, int eTimeFrame)
   {
   //индекс бара соответствующий заданному времени, возможно задавать будующее время
   int eIndex1=(eTime1>iTime(eSymbol,eTimeFrame,0))?(int)((iTime(eSymbol,eTimeFrame,0)-eTime1)/PeriodSeconds(eTimeFrame)):iBarShift(eSymbol,eTimeFrame,eTime1);
   int eIndex2=(eTime2>iTime(eSymbol,eTimeFrame,0))?(int)((iTime(eSymbol,eTimeFrame,0)-eTime2)/PeriodSeconds(eTimeFrame)):iBarShift(eSymbol,eTimeFrame,eTime2);
   if(eIndex2-eIndex1==0) return(0.0);
   int eIndex3=(eTime3>iTime(eSymbol,eTimeFrame,0))?(int)((iTime(eSymbol,eTimeFrame,0)-eTime3)/PeriodSeconds(eTimeFrame)):iBarShift(eSymbol,eTimeFrame,eTime3);
   return(ePrice1+(ePrice2-ePrice1)*(eIndex3-eIndex1)/(eIndex2-eIndex1));
   }
 
Aleksei Stepanenko:

Well, if you're not making any sense, then I'll have to give you a hint:

I think I got it, thank you!!!

Reason: