Questions from Beginners MQL4 MT4 MetaTrader 4 - page 52

 
ilnur17021992:
Can the price tag(OBJ_ARROW_LEFT_PRICE) have its own text instead of the price, if so how?
ObjectCreate(Name,OBJ_TEXT,Window,aTime,aPrice);
 
Good day! Can someone explain why the prices on H4 and M15 charts do not match? In the screenshot on M15 the price has crossed the red line (to the left of the vertical line). And a minute later there is a screenshot of H4 where the price is still very far to it (to the right of the line).
And here in that program only another dtz has a shadow from the candle (the candle is outermost on the right)
 
Equal:
Good day! Can someone explain why the prices on H4 and M15 charts do not match? In the screenshot on M15 price has crossed the red line (to the left of the vertical line). And a minute later there is a screenshot of H4 where the price is still very far to it (to the right of the line).
And here is the screenshot of that program, but another dtz has a shadow of the candle (the candle is outermost on the right)
Are you new to the fact that quotes differ in different brokerage companies? They are different even for demo and real in one and the same brokerage company! What a surprise (:
 

Trying to write something similar:IceFX DrawProfit

Code:

void start()
{
   for(int i=0;i<OrdersHistoryTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderType()<=1)
      History();
   }
}
  
void History()
{
   string Ticket=IntegerToString(OrderTicket());
   color col=Red;
   if(OrderType()==0)col=Blue;
   datetime a=OrderOpenTime();
   double b=OrderOpenPrice();
   datetime c=OrderCloseTime();
   double d=OrderClosePrice();
   double profit=OrderProfit();
  
   ObjectCreate(Ticket+"Open",OBJ_ARROW,0,a,b);
   ObjectSet(Ticket+"Open",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Open",OBJPROP_ARROWCODE,1);
      
   ObjectCreate(Ticket+"Line",OBJ_TREND,0,a,b,c,d);
   ObjectSet(Ticket+"Line",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Line",OBJPROP_WIDTH,1);
   ObjectSet(Ticket+"Line",OBJPROP_STYLE,STYLE_DOT);
   ObjectSet(Ticket+"Line",OBJPROP_RAY,0);
      
   ObjectCreate(Ticket+"Close",OBJ_ARROW,0,c,d);
   ObjectSet(Ticket+"Close",OBJPROP_COLOR,Green);
   ObjectSet(Ticket+"Close",OBJPROP_ARROWCODE,3);
      
   ObjectCreate(Ticket+"Profit",OBJ_TEXT,0,c,d);
   ObjectSet(Ticket+"Profit",OBJPROP_WIDTH,2);
   ObjectSetText(Ticket+"Profit",DoubleToString(profit,2),10,"Arial",White);
   ObjectSet(Ticket+"Profit",OBJPROP_PRICE1,d+Point*5);
   ObjectSet(Ticket+"Profit",OBJPROP_TIME1,c+10000);      
}

Everything works, but I'm using a grid advisor, which at the moment covers a bunch of orders and as a result the profit is overlapping each other, I would like the profit of this closed bunch to be totaled and only the amount displayed (as implemented inIceFX DrawProfit indicator), rather than separately for each order as I have now. Help me to make it right :)


Files:
 
Vitalie Postolache:
Is it new to you that quotes in different brokerage companies are different? Yes, they are different even for demo and real trade in one and the same brokerage company! What a surprise (:
The surprise is different. This is one and the same real account and the price changes (not the same) just by switching to a different timeframe.
In another brokerage company also on a real account when changing the chart everything is OK! The fact that different prices are different is clear, it is not clear that one has as if two prices at once, one on the minutes, one on the hours is different (very different). I understand that it should not be like that but I wonder where the problem may be. By the way the candlestick "corrected" in about an hour after the opening of the next.
 
ilnur17021992:

Trying to write something similar:IceFX DrawProfit

Code:

void start()
{
   for(int i=0;i<OrdersHistoryTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderType()<=1)
      History();
   }
}
  
void History()
{
   string Ticket=IntegerToString(OrderTicket());
   color col=Red;
   if(OrderType()==0)col=Blue;
   datetime a=OrderOpenTime();
   double b=OrderOpenPrice();
   datetime c=OrderCloseTime();
   double d=OrderClosePrice();
   double profit=OrderProfit();
  
   ObjectCreate(Ticket+"Open",OBJ_ARROW,0,a,b);
   ObjectSet(Ticket+"Open",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Open",OBJPROP_ARROWCODE,1);
      
   ObjectCreate(Ticket+"Line",OBJ_TREND,0,a,b,c,d);
   ObjectSet(Ticket+"Line",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Line",OBJPROP_WIDTH,1);
   ObjectSet(Ticket+"Line",OBJPROP_STYLE,STYLE_DOT);
   ObjectSet(Ticket+"Line",OBJPROP_RAY,0);
      
   ObjectCreate(Ticket+"Close",OBJ_ARROW,0,c,d);
   ObjectSet(Ticket+"Close",OBJPROP_COLOR,Green);
   ObjectSet(Ticket+"Close",OBJPROP_ARROWCODE,3);
      
   ObjectCreate(Ticket+"Profit",OBJ_TEXT,0,c,d);
   ObjectSet(Ticket+"Profit",OBJPROP_WIDTH,2);
   ObjectSetText(Ticket+"Profit",DoubleToString(profit,2),10,"Arial",White);
   ObjectSet(Ticket+"Profit",OBJPROP_PRICE1,d+Point*5);
   ObjectSet(Ticket+"Profit",OBJPROP_TIME1,c+10000);      
}

Everything works, but I'm using a grid advisor, which at the moment covers a bunch of orders and as a result the profit is overlapping each other, I would like the profit of this closed bunch to be totaled and only the amount displayed (as implemented inIceFX DrawProfit indicator), rather than separately for each order as I have now. Help me to make it right :)


Profit is calculated in a separate cycle
 
Alekseu Fedotov:
Profit counts in a separate cycle
Which one? How do I know that specific orders are a group and their profits need to be summed?
 
ilnur17021992:
Which is it? How do I determine that specific orders are a group and their profit should be summed?
And what is the method of closing them, a group through a function, or some other way?
 
Vitaly Muzichenko:
How do you close them, are they closed as a group through a function or some other way?
Orders are opened by robot netmaker, for the whole group it calculates and sets one common TP, by which they are then closed.


I am attaching a screenshot:
 
ilnur17021992:
Orders are opened by the robot netmaker, for the whole group it calculates and puts one common TP, at which they are then closed.

Screenshot attached:

It goes like this:

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int TotalPos=-1;
void OnTick()
{
 // остальной код

//--
  if(OrdersTotal()!=TotalPos) { // не мучаем каждый тик
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
     if(OrderSymbol()==Symbol() && OrderType()<=1) {
      History();

      ...
     }
  }}} TotalPos=OrdersTotal(); // запомним количество

//--
}

//+------------------------------------------------------------------+
//| Create Object istory                                             |
//+------------------------------------------------------------------+
void History() {
  string Ticket=(string)OrderTicket();
  color col=Red;
  if(OrderType()==0)col=Blue;
  datetime a=OrderOpenTime();
  double b=OrderOpenPrice();
  datetime c=OrderCloseTime();
  double d=OrderClosePrice();
  double prSep=OrderProfit()+OrderCommission()+OrderSwap();
  double prAll=0;
  int    cn=0;
  string hTicket;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
     if(OrderSymbol()==Symbol() && OrderType()<=1) {
      datetime ct=OrderCloseTime();
      // 60 секунд разницы между закрытием первой и последней в сетке
      if(c<=ct+60 && c>=ct-60) {
        prAll+=OrderProfit()+OrderCommission()+OrderSwap();
        hTicket=(string)OrderTicket();
        cn++;
      }
   }}}
   ObjectCreate(Ticket+"Open",OBJ_ARROW,0,a,b);
   ObjectSet(Ticket+"Open",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Open",OBJPROP_ARROWCODE,1);
      
   ObjectCreate(Ticket+"Line",OBJ_TREND,0,a,b,c,d);
   ObjectSet(Ticket+"Line",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Line",OBJPROP_WIDTH,1);
   ObjectSet(Ticket+"Line",OBJPROP_STYLE,STYLE_DOT);
   ObjectSet(Ticket+"Line",OBJPROP_RAY,0);
      
   ObjectCreate(Ticket+"Close",OBJ_ARROW,0,c,d);
   ObjectSet(Ticket+"Close",OBJPROP_COLOR,Green);
   ObjectSet(Ticket+"Close",OBJPROP_ARROWCODE,3);
  
   Ticket=cn>1?hTicket:Ticket;
   ObjectCreate(Ticket+"Profit",OBJ_TEXT,0,c,d);
   ObjectSet(Ticket+"Profit",OBJPROP_ANCHOR,0);
   ObjectSetText(Ticket+"Profit",DoubleToString(prAll,2),10,"Arial",/*White*/clrBlack);
   ObjectSet(Ticket+"Profit",OBJPROP_PRICE1,d);
   ObjectSet(Ticket+"Profit",OBJPROP_TIME1,c+Period()*60*2);
}