Problem in Strategy Tester Chart (Properties) ?

 

Hello,

the following Code simply opens a sell order:

#include <trade/trade.mqh>

CTrade         m_trade;                         // The Trade Class Object
MqlTick        last_tick;                       // Get bid and ask price for current tick   
bool           trade = true;

int OnInit() {

   return(INIT_SUCCEEDED);   
}

void OnTick() {
   
   // ChartSetInteger (0, CHART_SHOW_TRADE_LEVELS, false );
   
   if(trade) {
      
      m_trade.Sell(0.1, _Symbol, last_tick.ask, last_tick.ask, last_tick.ask);
      
      trade = false;
      
   }
}

This produces the following chart in the strategy tester:

img5

I am trying to get rid of the following Things:

1. green dotted sell line

2. the red arrow

3. the text #2 sell 0.10


I found the following two Forum posts:

https://www.mql5.com/en/forum/139145

https://www.mql5.com/en/forum/132892


From These posts, I found two possible Solutions:

1. Doing it via MQL5 code:

ChartSetInteger (0, CHART_SHOW_TRADE_LEVELS, false );

2. In the Strategy Tester Chart go to -> tools --> option --> uncheck "Show Trade Levels"


However, regardless what I do, the green line, as well as the arrow and the text stay.

I just read the post from syrvn 0 reporting a possible bug:

https://www.mql5.com/en/forum/216648#comment_5839187

That is why I also decided to ask whether anyone can confirm whether this is a bug or not or if I am doing something wrong.

Answers a greatly appreaciated.

how to hide orders, stop loss & TP lines in a chart?
how to hide orders, stop loss & TP lines in a chart?
  • 2012.04.23
  • www.mql5.com
Is it possible to hide all the trade's related lines in 1 chart only? the show trade levels options impacts all charts. thanks...
 
wokl: However, regardless what I do, the green line, as well as the arrow and the text stay.

Of course they do, they are objects once created. Turn them off before opening a trade.

 

Thanks for your comment @whroeder1.


How do I do that? If I put the code

ChartSetInteger (0, CHART_SHOW_TRADE_LEVELS, false );

in the OnInit() function before any trades are opened, it still has no effect.

How can I turn / delete objects before they are created. Could you please be more precisely on how you would do that?

 

I managed to get rid of the green dotted line by setting CHART_COLOR_VOLUME equal to the background color of the chart.

I also realized that the TEXT LABEL and the SELL_ARROW are one object? Still struggeling to delete it. Any ideas?

#include <trade/trade.mqh>

CTrade         m_trade;                         // The Trade Class Object
MqlTick        last_tick;                       // Get bid and ask price for current tick   
bool           trade = true;

int OnInit() {

ChartSetInteger(0, CHART_COLOR_VOLUME, clrBlack);

ChartRedraw();

   return(INIT_SUCCEEDED);   
}

void OnTick() {
   
   if(trade) {
      
      m_trade.Sell(0.1, _Symbol, last_tick.ask, 0, 0, NULL);
           
      trade = false;
      
   }
}
 
wokl:

However, regardless what I do, the green line, as well as the arrow and the text stay.


You have to delete the objects or they stay on screen.

https://docs.mql4.com/objects/objectdelete


- Jack

ObjectDelete - Object Functions - MQL4 Reference
ObjectDelete - Object Functions - MQL4 Reference
  • docs.mql4.com
When the function is used with no chart ID specified, the function is supposed to be working with the current chart to which it has a direct access. In this case, the return value means the function execution result. If the ID of a chart other than the current one is specified, the return value only informs whether the command has been added...
 
Jack Thomas:


You have to delete the objects or they stay on screen.

https://docs.mql4.com/objects/objectdelete


- Jack


Hi,

I am working with MQL5, so maybe there is a better way / functions I can use?

 
wokl:


Hi,

I am working with MQL5, so maybe there is a better way / functions I can use?


For MQL5: https://www.mql5.com/en/docs/objects/objectdelete

- Jack



Documentation on MQL5: Object Functions / ObjectDelete
Documentation on MQL5: Object Functions / ObjectDelete
  • www.mql5.com
When an object is renamed, two events are formed simultaneously. These events can be handled in an Expert Advisor or indicator by the OnChartEvent() function:
 

If you want to clear ALL the objects from your chart you can also use:

https://www.mql5.com/en/docs/objects/objectdeleteall

- Jack


Documentation on MQL5: Object Functions / ObjectsDeleteAll
Documentation on MQL5: Object Functions / ObjectsDeleteAll
  • www.mql5.com
[in]  Prefix in object names. All objects whose names start with this set of characters will be removed from chart. You can specify prefix as 'name' or 'name*' — both variants will work the same. If an empty string is specified as the prefix, objects with all possible names will be removed.
 

Thank you! I will have a look into that tomorrow. 

I just quickly checked the ObjectDelete function and it uses the Name of the object to delete. When I create the order above, I don't know the Name of the arrow object created automatically.

So I guess, I have to iterate over all existing objects and pick up the OBJ_ARROW_SELL (maybe _DOWN) and delete that one?

Are my thoughts plausible?

 
wokl:

Thank you! I will have a look into that tomorrow. 

I just quickly checked the ObjectDelete function and it uses the Name of the object to delete. When I create the order above, I don't know the Name of the arrow object created automatically.

So I guess, I have to iterate over all existing objects and pick up the OBJ_ARROW_SELL (maybe _DOWN) and delete that one?

Are my thoughts plausible?

No need to iterate all the existing objects.

If you want to just delete all the down arrows on screen for example, you can specify the object type.

Example from documentation:

https://www.mql5.com/en/docs/objects/objectdeleteall

int  ObjectsDeleteAll(
   long           chart_id,   // chart ID
   const string     prefix,   // prefix in object name
   int       sub_window=-1,   // window index
   int      object_type=-1    // object type
   );

I've found the following page helpful for object types.

https://www.mql5.com/en/docs/constants/objectconstants/enum_object

- Jack

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_ARROW_DOWN
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_ARROW_DOWN
  • www.mql5.com
//| Create Arrow Down sign                                           |               chart_ID=0,                           sub_window=0,                          time=0,                                  price=0,                              width=3,                             z_order=0)            ...
 
I edited the topic's title. There is no bug in Strategy Tester here.
Reason: