How can I solve the redraw of chart object after timeframe change? - page 2

 
for (counter2=OrdersHistoryTotal()-1;counter2 >= 0;counter2--) {
   if (OrderSelect(counter2,SELECT_BY_POS,MODE_HISTORY)==true && OrderSymbol()==szimbolum && OrderMagicNumber()==magic_number) {
        close_order_profit=OrderProfit() + OrderSwap() + OrderCommission();
        total_profit=total_profit+close_order_profit;

with this code I get total_profit. The total_profit is summarizing the profit of closed trades.


The chart draw depend on how I get total_profit? Gooly, with Alert() I see the right profit calculation, and everything is working fine. Except this chart draw code.

 
ObjectSetString(ChartID(),"profit_usd",OBJPROP_TEXT,infowindow_upper);

Try replacing all ChartID() with 0.


ObjectSetString(0,"profit_usd",OBJPROP_TEXT,infowindow_upper);
 
pecskeke1976:

with this code I get total_profit. The total_profit is summarizing the profit of closed trades.


The chart draw depend on how I get total_profit? Gooly, with Alert() I see the right profit calculation, and everything is working fine. Except this chart draw code.

When (where) do you calculate total_profit?
 
gooly:
When (where) do you calculate total_profit?
I calculate after trade close from the history list. Thats working. I have checked with Alert() and Print().
 
deysmacro:

Try replacing all ChartID() with 0.


I will try. Ty.
 
pecskeke1976:
I calculate after trade close from the history list. Thats working. I have checked with Alert() and Print().
Well, doesn't that mean total_profit is zero until the next trade close?
 
gooly:
Well, doesn't that mean total_profit is zero until the next trade close?
At start the total_profit is zero. 1st trade closed total_profit get value, that <>0. I can repeat myself: I start the EA, takes trade, profit 0. The EA writes it on the chart. I see "Profit: 0" on the chart. After this the trade makes +10 usd profit and closed. This profit will be written on the chart with code above. Now I see "Profit: +10" on the chart. So far the code works good. Now if I change the timeframe of the current chart, I will see "Profit: 0" instead of "Profit: +10". Then I change the TF back, and I see "Profit: +10". The total_profit value doesn't changed! But I see 2 different text on the same chart if I change timeframe on the chart. I can't explain simplier. I hope you understand.
 

Sorry but I don't understand why is important to know what value got total_profit.

Please check this code, compile and put on a chart and during running change please timeframe, and you will see what about I am talking.

int OnInit()
  {
//---
ObjectCreate(0,"line1",OBJ_LABEL,0,0,0);                        
ObjectSet("line1",OBJPROP_XDISTANCE,ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0)-120);
ObjectSet("line1",OBJPROP_YDISTANCE,20);                                   
ObjectSet("line1",OBJPROP_COLOR,clrWhite);                                    
ObjectSet("line1",OBJPROP_FONTSIZE,14);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 

ObjectSetString(0,"line1",OBJPROP_TEXT,"first");
WindowRedraw();
Sleep(10000);
ObjectSetString(0,"line1",OBJPROP_TEXT,"second!");
//WindowRedraw();
  }
 
pecskeke1976:

Sorry but I don't understand why is important to know what value got total_profit.

Please check this code, compile and put on a chart and during running change please timeframe, and you will see what about I am talking.

This code seems to work as expected. I don't know what you are trying to demonstrate here.
 
Solved.