Delete all objects at INIT phase of an indicator????

 

Dear experts,

1/ FIRST PROBLEM:

My using indicator will draw many vertical lines and horizontal lines so to keep them in order I want to delete all these lines right after I added it (int INIT phase) then let it draws again (int START phase). But in that INIT phase, indicator can't delete all lines but just a few of them. I attached the code below for your comments please ....

void DeleteLines()
{
int    obj_total4 = ObjectsTotal();
for(int i4 = 0; i4 <= obj_total4; i4++)
  {
   name = ObjectName(i4);
   if(ObjectType(name) == OBJ_HLINE || ObjectType(name) == OBJ_VLINE) ObjectDelete(name);
  }
}

// INIT PHASE (I CALL ABOVE FUNCTION TO DELETE ALL LINES BUT IT DOESN'T WORK FULLY)
int init()
  {
//----
   DeleteLines();
//----
   return(0);
  }                

2/ SECOND PROBLEM:

I wrote an EA to place orders automatically everytimes when new Bar appears. But these orders are PENDING ones so they are with FIXED entry points while brokers' spreads keep changing every ticks, especially during specific market conditions spreads can be WIDEN up to few tens pips. So my EA placed PENDING orders with FIXED entry points, stop and target levels CAN'T BE UPDATED along with THE CHANCE OF SPREADS EVERY TICK. So my question is, is there anyway for EA to frequently modify my PENDING ORDERS every ticks?

Thanks so much for your help !!!

 

1. Is name defined globally as a string ?

2. Get a better Broker. Modifying your orders on every tick, if you have many orders, is going to be a problem. You can attempt to do it in code, sure, it's not difficult.

 
RaptorUK:

1. Is name defined globally as a string ?

2. Get a better Broker. Modifying your orders on every tick, if you have many orders, is going to be a problem. You can attempt to do it in code, sure, it's not difficult.


Hi again, RaptorUK

I hope you are doing well :-)

1. I just tried to define name as a string globally or inside void DeleteLines() function but still got same result. The indicator can't delete all the lines as I expected.

2. What brokers you may know to better solve my concern, RaptorUK? Can you please write a sample codes about how to modify pending orders every ticks?

Thanks so much !!!

 
  1. You MUST count down when deleting.
  2. Stop using pending orders, wait for price to reach and open.
 
WHRoeder:
  1. You MUST count down when deleting.
  2. Stop using pending orders, wait for price to reach and open.


Hi WHRoeder,

1. I tried your comment and the indicator seems work nicely.

Replace

for(int i4 = 0; i4 <= obj_total4; i4++)

With this working fine

for(int i4 = obj_total4; i4 >=0; i4--)

2. Can you please write a sample codes on how to wait for price to reach and open? My requirement is only one trade will be opened when new bar appears. Thanks so much, WHRoeder !!!

 
InvestDad:
My requirement is only one trade will be opened when new bar appears.
I assume you meant you decide on the open price at the new bar, not open at the new bar.
int start(){
    static datetime Time0;
    bool newBar = (Time0 != Time[0]);   Time0 = Time[0];
    static double openPrice, DIR;
    if (newBar){
        openPrice = 0;  // Assume don't open
        :
        if (wantToOpen){
            openPrice   = ..        // Open when Bid goes above/below
            DIR         = ..        // +1/-1
        }
    }
    if (openPrice != 0 && (Bid - openPrice)*DIR > 0){
        // Market above/below price - time to open.
    }
}
 
InvestDad ADMIN:

Dear experts,

1/ FIRST PROBLEM:

My using indicator will draw many vertical lines and horizontal lines so to keep them in order I want to delete all these lines right after I added it (int INIT phase) then let it draws again (int START phase). But in that INIT phase, indicator can't delete all lines but just a few of them. I attached the code below for your comments please ....

2/ SECOND PROBLEM:

I wrote an EA to place orders automatically everytimes when new Bar appears. But these orders are PENDING ones so they are with FIXED entry points while brokers' spreads keep changing every ticks, especially during specific market conditions spreads can be WIDEN up to few tens pips. So my EA placed PENDING orders with FIXED entry points, stop and target levels CAN'T BE UPDATED along with THE CHANCE OF SPREADS EVERY TICK. So my question is, is there anyway for EA to frequently modify my PENDING ORDERS every ticks?

Thanks so much for your help !!!

There is something weird here...

cuz... if you DELETE a line, the counter will be -1 ... how u pretent to run the last object ?

for exemplo
O1 - id 1
O2 - id 2
O3 - id 3

if we delete Object1 (id 1)

the Object 2 will assume the ID 1... so in the next loop you will delete ID 2 and the ID 1 will remain....

Its a array.... when you delete a position, the position counter change...

3 2 1 (WILL DELETE) 0
Object 4 Object 3 Object 2 Object 1
2 1 0
Object 4 Object 3 Object 1


You should to delete the first object while type OBJ_HLINE exist...


Am i right?

 
Mikio Nishiya: Am i right?
  1. Do you think OP is still waiting for a solution after nine (9) years?
    Generally: Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. 2014.02.03

  2. When you delete the position counter changes; thus the answer at #3.1
 
You can delete all graphic objects with this command.
ObjectsDeleteAll


Reason: