Ask! - page 21

 
billworld2:
Is there a way to delete objects based on a select text string within the object name?

Here is the example:

datetime currentDay = StrToTime(Year()+"."+Month()+"."+Day()+" 00.00");

for(int i=0;i<ObjectsTotal();i++)

{

string name = ObjectName(i);

if( ObjectGet(name,OBJPROP_TIME1) < currentDay && ObjectGet(name,OBJPROP_TIME2) < currentDay && ObjectGet(name,OBJPROP_TIME3) < currentDay)

{

ObjectDelete(ObjectName(i));

return (false);

}

}

return(true);

 
billworld2:
One of my learning projects is going about customizing the tester.tpl which governs the chart display option for the Strateg Tester. I find the default chart style very difficult to visualize. So, I created a new template and then built a script for replacing all arrows to more attractive arrows.

However, I'd also like to grab info in the arrow names and display that as text on the chart. The arrow names include stuff like "#62 buy" or "73 sell close". That way you can look at the chart and see exactly when a particular trade # is entered/exited. I don't know why this isn't included by default with the Strategy Tester as it is with other platforms (e.g. TradeStation).

Anyway, I'd like to grab the text in question and insert new text objects just below the existing arrows on the chart. But, I'm not figuring out how to accomplish this.

How do I go about doing this?

Thanks

Bill

Well, u can write script, or function with will read arrow info and make text label bellow it. Then run the script each time when a new arrow is draw. Or just place the function at the end of main function of the ea. I dont know why this info isnt standard in metatrader, but it is simple to code that kind of functionality.

 
Kalenzo:
U should read about Date and Time functions, and use iBarShift function to get the shift of the first bar from specified month from specified timeframe.

I know it must be trivial for you. I'm just not getting it yet by following the limited documenation (not many examples provided there). Could you kindly provide an example for how to do this?

Thanks

Bill

 
Kalenzo:
Well, u can write script, or function with will read arrow info and make text label bellow it. Then run the script each time when a new arrow is draw. Or just place the function at the end of main function of the ea. I dont know why this info isnt standard in metatrader, but it is simple to code that kind of functionality.

Thanks, but, I'm stuck specifically on how to code the script. If you have time to provide a short example, that would be most appreciated.

Thanks again.

Bill

 

Not sure I follow. To be clear, I'm looking for a way to do a sub-string match based on an object name. Say for example I have a group of objects with the string "-206" in them (along with other text). I want to locate and delete all of the objects which contain "-206" in their name.

What's confusing me in the example below is the association with OBJPROP_TIME1, OBJPROP_TIME2 and OBJPROP_TIME3. I know objects can have up to three time coordinates. I'm not following how that fits in with what I'm trying to do.

Kalenzo:
Here is the example:

datetime currentDay = StrToTime(Year()+"."+Month()+"."+Day()+" 00.00");

for(int i=0;i<ObjectsTotal();i++)

{

string name = ObjectName(i);

if( ObjectGet(name,OBJPROP_TIME1) < currentDay && ObjectGet(name,OBJPROP_TIME2) < currentDay && ObjectGet(name,OBJPROP_TIME3) < currentDay)

{

ObjectDelete(ObjectName(i));

return (false);

}

}

return(true);
 
billworld2:
Not sure I follow. To be clear, I'm looking for a way to do a sub-string match based on an object name. Say for example I have a group of objects with the string "-206" in them (along with other text). I want to locate and delete all of the objects which contain "-206" in their name. What's confusing me in the example below is the association with OBJPROP_TIME1, OBJPROP_TIME2 and OBJPROP_TIME3. I know objects can have up to three time coordinates. I'm not following how that fits in with what I'm trying to do.

Ok , try this:

for(int i=0;i<ObjectsTotal();i++)

{

string name = ObjectName(i);

if(StringSubstr( name, 0, 3)==206)

{

ObjectDelete(ObjectName(i));

}

}

If the first 3 leters of the name of the object will be 206 then the object will be deleted

 
billworld2:
Thanks, but, I'm stuck specifically on how to code the script. If you have time to provide a short example, that would be most appreciated.

Thanks again.

Bill

first declare global variable (global for the script) int objectCount;

then at the end of the ea process all objects (u can for eg search them by name)

for(int i=0;i>=ObjectsTotal(OBJ_ARROW) ;i++)

{

//then if object label dont exists draw it, lets say that we will take the

//name of existing arrow and add L label to it, to identify it

if(ObjectFind(ObjectName(i)+"L")== -1)

{

ObjectCreate(ObjectName(i)+"L",OBJ_ARROW,0,ObjectGet(ObjectName(i), OBJPROP_TIME1),ObjectGet(ObjectName(i),(OBJPROP_PRICE1+3*Point)));

// and that is it

}

}

That is just an example, I havent got time to check it for possible bugs but this should work, and u know now the right way.

 

Okay. Got it. I actually needed to use StringFind(). Thanks for the pointers!

#property show_inputs

extern string stringname="blah";

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

//----

for(int i=0;i<ObjectsTotal();i++)

if(StringFind(ObjectName(i),stringname,0)>0)

{

ObjectDelete(ObjectName(i));

}

Kalenzo:
Ok , try this:

for(int i=0;i<ObjectsTotal();i++)

{

string name = ObjectName(i);

if(StringSubstr( name, 0, 3)==206)

{

ObjectDelete(ObjectName(i));

}

}

If the first 3 leters of the name of the object will be 206 then the object will be deleted
 

Thanks, but, this doesn't work. First, I changed "i>=ObjectsTotal" to "i<=ObjectsTotal" (typo). Then, I noticed that you're creating another arrow object where we want to create a new text object which includes the name of the arrow object. Anyway, the code below is creating a bunch of arrows (around 50) all overlapping on the same coordinates.

Still lost on this one. If you have a chance to take another look, that would be much appreciated. To be clear, I'm looking to create one new text object which gets positioned below each existing arrow object where the text description of the text object is equal to the name of the arrow object.

Bill

Kalenzo:
first declare global variable (global for the script) int objectCount;

then at the end of the ea process all objects (u can for eg search them by name)

for(int i=0;i>=ObjectsTotal(OBJ_ARROW) ;i++)

{

//then if object label dont exists draw it, lets say that we will take the

//name of existing arrow and add L label to it, to identify it

if(ObjectFind(ObjectName(i)+"L")== -1)

{

ObjectCreate(ObjectName(i)+"L",OBJ_ARROW,0,ObjectGet(ObjectName(i), OBJPROP_TIME1),ObjectGet(ObjectName(i),(OBJPROP_PRICE1+3*Point)));

// and that is it

}

}

That is just an example, I havent got time to check it for possible bugs but this should work, and u know now the right way.
 

contains-based object deletion

Is there a way to delete objects based on a select text string within the object name?

Edit: Figured it out with pointer from Kalenzo. Answer is in post #212.