I'm stuck - could use another set of eyes on this H-line label issue.

 

I have an EA I that I am trying to make a couple edits to.

The EA allows you to manages orders by dragging the H-lines and it displays a text label identifying the H-lines, currently the lines display on the right side on the chart (beyond Bar[0]) and I need them on the left side (where MT4 puts the ticket number on the order open line). (see picture below)

I have figured out how to find the first bar visible on the chart and use that value to set the text and it works for the initial display, but it does not adjust location as the window is re-sized, it retains the original value/location.

I have tried resetting the "bar" value after each pass, redrawing the window and setting the location by OBJPROP_XDISTANCE, all with no luck.

It's probably simple but I'm not seeing it. Could use some help.

Here is the section of the code with my changes highlighted.

void UpdateGFX(int tickets[]){
   
   bar=0;
   bar=(WindowFirstVisibleBar()-10);
   for(int i=ArraySize(tickets)-1;i>=0;i--){
      OrderSelect(tickets[i],SELECT_BY_TICKET);
      ObjectCreate(tickets[i]+"-sl",OBJ_HLINE,0,0,OrderStopLoss());
      ObjectSet(tickets[i]+"-sl",OBJPROP_PRICE1,OrderStopLoss());
      ObjectSet(tickets[i]+"-sl",OBJPROP_COLOR,StoplossColor);    
      
      ObjectCreate(tickets[i]+"-sl_l",OBJ_TEXT,0,OrderOpenTime(),OrderStopLoss());
      ObjectSet(tickets[i]+"-sl_l",OBJPROP_TIME1,Time[bar]);
      ObjectSet(tickets[i]+"-sl_l",OBJPROP_PRICE1,OrderStopLoss());
      ObjectSet(tickets[i]+"-sl_l",OBJPROP_COLOR,StoplossColor);  
      ObjectSetText(tickets[i]+"-sl_l","SL "+OrderTicket()+"  at "+DoubleToStr(MathAbs(OrderOpenPrice()-OrderStopLoss())/pmod,1)+" pips");  

      ObjectCreate(tickets[i]+"-tp",OBJ_HLINE,0,0,OrderTakeProfit());
      ObjectSet(tickets[i]+"-tp",OBJPROP_COLOR,TakeprofitColor);   
      ObjectSet(tickets[i]+"-tp",OBJPROP_PRICE1,OrderTakeProfit());
      
      ObjectCreate(tickets[i]+"-tp_l",OBJ_TEXT,0,OrderOpenTime(),OrderTakeProfit());
      ObjectSet(tickets[i]+"-tp_l",OBJPROP_TIME1,Time[bar]);
      ObjectSet(tickets[i]+"-tp_l",OBJPROP_PRICE1,OrderTakeProfit());
      ObjectSet(tickets[i]+"-tp_l",OBJPROP_COLOR,TakeprofitColor);  
      ObjectSetText(tickets[i]+"-tp_l","TP "+OrderTicket()+"  at "+DoubleToStr(MathAbs(OrderOpenPrice()-OrderTakeProfit())/pmod,1)+" pips");  


      
      ObjectCreate(tickets[i]+"-open",OBJ_HLINE,0,0,OrderOpenPrice());
      ObjectSet(tickets[i]+"-open",OBJPROP_COLOR,OpenPriceColor);      
      ObjectSet(tickets[i]+"-open",OBJPROP_PRICE1,OrderOpenPrice());
      ObjectSet(tickets[i]+"-open",OBJPROP_TIME1,Time[bar]);
      ObjectSetText(tickets[i]+"-open","OPEN "+OrderTicket()+"  at "+(OrderOpenPrice()/pmod,1)+" pips");  
      
   }   
}
                                                                           
void RecalcByGFX(int &tickets[],double &sl[], double &tp[]){
   for(int i=ArraySize(tickets)-1;i>=0;i--){
      OrderSelect(tickets[i],SELECT_BY_TICKET);
      double gfx.tp,gfx.sl;
      bar=0;
      bar=(WindowFirstVisibleBar()-10);
      gfx.tp=NormalizeDouble(ObjectGet(tickets[i]+"-tp",OBJPROP_PRICE1),Digits);
      if(gfx.tp!=OrderTakeProfit()){
         if(gfx.tp!=tp[i]){
            if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(gfx.tp,Digits),0,Lime)){
               tp[i]=gfx.tp;
               ObjectSet(tickets[i]+"-tp_l",OBJPROP_TIME1,Time[bar]);
               ObjectSet(tickets[i]+"-tp_l",OBJPROP_PRICE1,gfx.tp);
               ObjectSet(tickets[i]+"-tp_l",OBJPROP_COLOR,TakeprofitColor);  
               ObjectSetText(tickets[i]+"-tp_l","TP "+OrderTicket()+"  at "+DoubleToStr(MathAbs(OrderOpenPrice()-gfx.tp)/pmod,1)+" pips");  

            }
         }else{
            ObjectSet(tickets[i]+"-tp",OBJPROP_PRICE1,OrderTakeProfit());
            ObjectSet(tickets[i]+"-tp_l",OBJPROP_TIME1,Time[bar]);
            ObjectSet(tickets[i]+"-tp_l",OBJPROP_PRICE1,OrderTakeProfit());
            ObjectSet(tickets[i]+"-tp_l",OBJPROP_COLOR,TakeprofitColor);  
            ObjectSetText(tickets[i]+"-tp_l","TP "+OrderTicket()+"  at "+DoubleToStr(MathAbs(OrderOpenPrice()-OrderTakeProfit())/pmod,1)+" pips");  

            tp[i]=gfx.tp;               
         }
      }

      gfx.sl=NormalizeDouble(ObjectGet(tickets[i]+"-sl",OBJPROP_PRICE1),Digits);
      if(gfx.sl!=OrderStopLoss()){
         if(gfx.sl!=sl[i]){
            if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(gfx.sl,Digits),OrderTakeProfit(),0,Lime)){
               sl[i]=gfx.sl;
               ObjectSet(tickets[i]+"-sl_l",OBJPROP_TIME1,Time[bar]);
               ObjectSet(tickets[i]+"-sl_l",OBJPROP_PRICE1,gfx.sl);
               ObjectSet(tickets[i]+"-sl_l",OBJPROP_COLOR,StoplossColor);  
               ObjectSetText(tickets[i]+"-sl_l","SL "+OrderTicket()+"  at "+DoubleToStr(MathAbs(OrderOpenPrice()-gfx.sl)/pmod,1)+" pips");  

            }
         }else{
            ObjectSet(tickets[i]+"-sl",OBJPROP_PRICE1,OrderStopLoss());
            ObjectSet(tickets[i]+"-sl_l",OBJPROP_TIME1,Time[bar]);
            ObjectSet(tickets[i]+"-sl_l",OBJPROP_PRICE1,OrderStopLoss());
            ObjectSet(tickets[i]+"-sl_l",OBJPROP_COLOR,StoplossColor);  
            ObjectSetText(tickets[i]+"-sl_l","SL "+OrderTicket()+"  at "+DoubleToStr(MathAbs(OrderOpenPrice()-OrderStopLoss())/pmod,1)+" pips");  

            sl[i]=gfx.sl;               
         }
      }
   }   
}




thanks,

dave

 
bdeyes:

I have figured out how to find the first bar visible on the chart and use that value to set the text and it works for the initial display, but it does not adjust location as the window is re-sized, it retains the original value/location.

I have tried resetting the "bar" value after each pass, redrawing the window and setting the location by OBJPROP_XDISTANCE, all with no luck.

It's probably simple but I'm not seeing it. Could use some help.

  1. Your calculation is correct. You only have to call it once per loop.
    shiftChart      =WindowFirstVisibleBar();
    shiftChartEnd   =shiftChart -WindowBarsPerChart();
    if (shiftChartEnd<0)    shiftChartEnd = 0;  // Tester/shift

  2. Code given is correct. Are you returning from start()? Screen isn't updated unless you do or call ObjectsRedraw().
 

Not sure I have an answer for you . . but, OBJPROP_XDISTANCE is only valid as far as I can see for Text Labels . . .

Try adding a print statement to see if you are picking up the correct bar number when the chart is re-sized . . .

bar=(WindowFirstVisibleBar()-10);

Print("Chart resized - new bar value= ", bar);  //  <--- add this
 
RaptorUK:

Not sure I have an answer for you . . but, OBJPROP_XDISTANCE is only valid as far as I can see for Text Labels . . .

Try adding a print statement to see if you are picking up the correct bar number when the chart is re-sized . . .


Log values returned from adding your "Print" statement seem to indicate that the bar numbers are updating. (below)


12:47:15 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:15 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:15 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:15 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:16 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:16 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:18 OrderManager AUDNZD,H1: Chart resized - new bar value= 240
12:47:20 OrderManager AUDNZD,H1: Chart resized - new bar value= 240
12:47:20 OrderManager AUDNZD,H1: Chart resized - new bar value= 240
12:47:21 OrderManager AUDNZD,H1: Chart resized - new bar value= 240
12:47:21 OrderManager AUDNZD,H1: Chart resized - new bar value= 491
12:47:24 OrderManager AUDNZD,H1: Chart resized - new bar value= 491
12:47:24 OrderManager AUDNZD,H1: Chart resized - new bar value= 491
12:47:25 OrderManager AUDNZD,H1: Chart resized - new bar value= 491
12:47:27 OrderManager AUDNZD,H1: Chart resized - new bar value= 491
12:47:29 OrderManager AUDNZD,H1: Chart resized - new bar value= 993
12:47:30 OrderManager AUDNZD,H1: Chart resized - new bar value= 993
12:47:33 OrderManager AUDNZD,H1: Chart resized - new bar value= 1998
12:47:39 OrderManager AUDNZD,H1: Chart resized - new bar value= 1998
12:47:40 OrderManager AUDNZD,H1: Chart resized - new bar value= 1998
12:47:42 OrderManager AUDNZD,H1: Chart resized - new bar value= 1998
12:47:44 OrderManager AUDNZD,H1: Chart resized - new bar value= 1998
12:47:45 OrderManager AUDNZD,H1: Chart resized - new bar value= 993
12:47:51 OrderManager AUDNZD,H1: Chart resized - new bar value= 993
12:47:51 OrderManager AUDNZD,H1: Chart resized - new bar value= 993
12:47:52 OrderManager AUDNZD,H1: Chart resized - new bar value= 993
12:47:53 OrderManager AUDNZD,H1: Chart resized - new bar value= 491
12:47:53 OrderManager AUDNZD,H1: Chart resized - new bar value= 491
12:47:54 OrderManager AUDNZD,H1: Chart resized - new bar value= 240
12:47:56 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:56 OrderManager AUDNZD,H1: Chart resized - new bar value= 114
12:47:57 OrderManager AUDNZD,H1: Chart resized - new bar value= 114

I have attached the whole EA file to my reply to WHRoeder as maybe there is something in one of the other functions i have missed

Dave

 
WHRoeder:
  1. Your calculation is correct. You only have to call it once per loop.

  2. Code given is correct. Are you returning from start()? Screen isn't updated unless you do or call ObjectsRedraw().

Yeah, i tried from start and from each of the functions and have also tried WindowsRedraw().

I have attached the whole EA as maybe there is something in one of the other functions I am missing.

Wasn't really clear on the code snippet you included - does it do something I am not doing? (and where would I put it?).

Thanks,

Dave

Files:
 
  1.          ArrayResize(tickets,OpenOrdersOnSymbol);
             ArrayResize(tp,OpenOrdersOnSymbol);
             ArrayResize(tp,OpenOrdersOnSymbol);
             int j=0;
             for(i=OrdersTotal()-1;i>=0;i--){
                OrderSelect(i,SELECT_BY_POS);
                if(OrderSymbol()==Symbol()){
                   tickets[j]=OrderTicket();
                   sl[j]=OrderStopLoss();
                   tp[j]=OrderStopLoss();
                   j++;
    Those two don't look right.
  2.       for(i=OrdersTotal()-1;i>=0;i--){
             OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
             if(OrderSymbol()==Symbol()){
                OpenOrdersOnSymbol++;
    You should always test return codes
          for(i=OrdersTotal()-1;i>=0;i--) if(
             OrderSelect(i,SELECT_BY_POS)
          && OrderSymbol()==Symbol()
          ){
                OpenOrdersOnSymbol++;

 
WHRoeder:
  1. Those two don't look right.
  2. You should always test return codes

WHRoeder,


Good eye - They were both good catch's. I did not see that (even after some 10 hours of staring at the screen trying to figure out what was wrong with my text display).

I can only assume that had not caused an issue because i usually only have one trade at a time open and the lines are locations are calculated in the other functions.

Now if i could just find a solution to the original question...

I will try some more Print tests and see if i can discover where things are going wrong.

I will post the solution (and the revised EA) when i figure it out .

Thanks for your help on this.

dave

 

Доброго времени суток уважаемые форумчане!

Меня зовут Герман, мне 23 года, я являюсь трейдером компании "Инстафорекс"

Помогите в поиске нужного скрипта! Скрипт нужен для сетки отложенных ордеров.

 
GERICH:

Доброго времени суток уважаемые форумчане!

Меня зовут Герман, мне 23 года, я являюсь трейдером компании "Инстафорекс"

Помогите в поиске нужного скрипта! Скрипт нужен для сетки отложенных ордеров.

Привет Герман,

Предложить Вам искать разделе Code Base, чтобы убедиться, что вам нужно уже есть.

Если не было бы лучше, чтобы начать новую тему на форуме со своим вопросом.

Кроме того, я верю, есть русский раздел этого форума, где вы можете получить лучший ответ. Не многие из английски говорить люди пойдут на себя труд перевести.

Надеюсь, что это нормально использовать Google Translate.

Дейв
Reason: