How to change text value after it down?

 

This code shows position's profit as pips,

But when position is close, it's still shows the last profit! I want it to show "0" after close the position (or shows "SomeTex") . What should I do?

When I change time frame, it change to "0". I want it change to "0" or some text when position was close.

   color LabelColor;

   LabelColor = CommentColor;

   if (pipVal < 0) LabelColor = Red;
   else  LabelColor = Lime;

   {
   string Pip = "PIP";
   string PipValue = DoubleToStr(pipVal, 0);
   if(ObjectFind(Pip) < 0) ObjectCreate(Pip, OBJ_LABEL, 0 , 0, 0); // check if Object exists

   ObjectSet(Pip, OBJPROP_CORNER, 1);
   ObjectSet(Pip, OBJPROP_XDISTANCE, 10);
   ObjectSet(Pip, OBJPROP_YDISTANCE, 27);
   ObjectSetText(Pip, PipValue, 8, "Tahoma Bold", LabelColor);
   }
 
Konnj:

This code shows position's profit as pips,

But when position is close, it's still shows the last profit! I want it to show "0" after close the position (or shows "SomeTex") . What should I do?

When I change time frame, it change to "0". I want it change to "0" or some text when position was close.

You need to show your code, didn't I say ? how are you selecting the Order ? you could simply check the OrderCloseTime() if it is non zero it is closed then you can set the PipValue to 0
 
Problem is in PiP Count !
 
Konnj:
Problem is in PiP Count !

In this function . . .

//========== FUNCTION getOpenOrders
void getOpenOrders()
   {
   int totalorders = OrdersTotal();

   if(totalorders == 0)    //  add these 5 lines
   {
   pipVal = 9999;
   return;
   }

   for(int j=0; j<totalorders;j++)
      {  
      OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
      if((OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderSymbol() == Symbol())
         {
         double val=getPipValue(OrderOpenPrice(),OrderType()); 
         pipVal = val;
         //int val = OrderProfit()/(OrderLots()*10);
         }
      }  
   }

in this code . . .

      if (pipVal < 0) LabelColor = Red;
      else if(pipVal == 9999)               // add these 5 lines
         {
         LabelColor = Black;
         pipVal = 0;
         }
      else  LabelColor = Lime;


So when you have no open trades pipVal will be set to 0 and shown in black.

 
You change it for all position, Now when all position are close, it shows black color, but I need it for current chart. For current chart still the same!
 
Konnj:
You change it for all position, Now when all position are close, it shows black color, but I need it for current chart. For current chart still the same!
OK, change the code so it only sets pipVal to 9999 when there is no Order for the current symbol . . .
 

I did change, what about the current chart?

When I close the current chart position and other position is still open, current chart shows the last profit (freez number) until the other position be close or new position be open in current chart!

 
Konnj:

I did change, what about the current chart?

When I close the current chart position and other position is still open, current chart shows the last profit (freez number) until the other position be close or new position be open in current chart!

If you change it inside the loop and there are no open orders the loop is not executed and pipVal is not changed.

You also have many Object where you are not checking if they exists before you try to create them . . .

 

I think I can't explain what I need!!

If you check the indicator, It shows open position's profit as pip.

When a position is open it works so good, but after close position ( with +/- profit) still we can see the last profit of current chart in the chart (freezing), it goes to change when:

1. New position in current chart open.

2. Change the chart time frame.

3. All position are close ( when I add new code line RaptorUk made it).


What I need ?

I need change profit too "0" (zero) or "some text" after close position in current chart.

 
Konnj:


What I need ?

I need change profit too "0" (zero) or "some text" after close position in current chart.

Yes I know . . . try this
 
No, still the same!!
Reason: