Ignore entering more trades

 

I have an EA that I want to start when price nears a specified level in an array:


double stops_array[11] = {1.0, 1.1, 1.2, 1.25, 1.3, 1.4, 1.5, 1.6, 1.75, 1.8, 1.9, 2.0};

So, I need to check the current Bid or Ask and round it to see which level it is near.
However, once it has reached that level and entered some orders and the orders have been closed, I don't want the EA to enter another order 
until the next level is reached, then it can reset itself.

Any ideas on how to do this?


double stops_array[11] = {1.0, 1.1, 1.2, 1.25, 1.3, 1.4, 1.5, 1.6, 1.75, 1.8, 1.9, 2.0};
   double currPANearest = NormalizeDouble(Bid,1);
   Comment("currPANearest="+DoubleToStr(currPANearest,1));
   int Arrayint = ArrayBsearch(stops_array,currPANearest,WHOLE_ARRAY,0,MODE_DESCEND);

   if (currPANearest == stops_array[Arrayint])
{
//do something
}
 

see the pseudo code:


if(currPANearest == stops_array[Arrayint])
{
   if( !near_existing_trade(OP_BUY, currPANearest, 100))   //  a range of 100 points around the levels?
   {
     //do something
   }
   if( !near_existing_trade(OP_SELL, currPANearest, 100))   //  a range of 100 points around the levels?
   {
     //do something
   }
}



bool near_existing_trade(int order_type, double level, int range)
{
  for(int i=0; i< OrdersTotal(); i++)
  if(OrderSelect(....))
  {
     if( (OrderType()==order_type) && (MathAbs(OrderOpenPrice()-level)<range*Point) )
       return(true);
  }
  return(false));
}

 
abstract_mind:



see the pseudo code:


Interesting, I'll rewrite some of that.

It's more that once the orders have been set, filled and closed for one of the variables in the array, I don't want to resend them for that same price until it has at least reached another price.

So if the orders are set for 1.6, maybe I could remove 1.6 from the array?

However, it would have to be added back into the array once price reached 1.7 and orders were set but then 1.7 removed from the array.

 
int trades_near = trades_near_level(OP_BUY, currPANearest, 100) +  closed_trades_near_level(OP_BUY, currPANearest, 100);

if( trades_near < max_trades) // max_trades=3?
{
   //....
}




int trades_near_level(int order_type, double level, int range)
{
  int counter=0; 
  for(int i=0; i< OrdersTotal(); i++)
  if(OrderSelect(....))
  {
     if( (OrderType()==order_type) && (MathAbs(OrderOpenPrice()-level)<range*Point) )
       counter++;
  }
  return(counter);
}



int closed_trades_near_level(int order_type, double level, int range)
{
  int counter=0; 
  for(int i=0; i< OrdersHistoryTotal(); i++)
  if(OrderSelect(i ,... ,MODE_HISTORY))
  {
     if( (OrderType()==order_type) && (MathAbs(OrderOpenPrice()-level)<range*Point) )
       counter++;
  }
  return(counter);
}




 
abstract_mind:


Aren't there any remove functions with arrays?

The above code checks the orderhistory but I'd still need a time limit.

Wouldn't it be easier to add a 2nd array and add in levels that had already been used then take them out again or reset the array?

 

if you are considering eurusd, you just need a single variable, not an array. See at the chart the time that goes between 1.1, 1.2, 1.3, ...

With a single variable for the level, you have more than enough time to update that variable, when it is about to approach a significant level.

A function to delete an element from an array might exist, or can be done. But see firstly whether you still go on with the array approach.

 
abstract_mind:

if you are considering eurusd, you just need a single variable, not an array. See at the chart the time that goes between 1.1, 1.2, 1.3, ...

With a single variable for the level, you have more than enough time to update that variable, when it is about to approach a significant level.

A function to delete an element from an array might exist, or can be done. But see firstly whether you still go on with the array approach.

Well, yes but I need to list all the different levels that the code must check.

It must action the code when a level reaches 1.1, 1.2, 1.25, 1.3, 1.4, 1.5, 1.6, 1.7, 1.75, 1.8, 1.9, 2.0.

As soon as it has created orders for 1 level and those orders have closed, eg 1.6. It must send orders for 1.6 again until a different level has been hit.

So, when it next hits 1.7 it sends orders for 1.7 and 1.6 is now available again but 1.7 won't be.

Maybe I just add a second variable called IgnoreLevel and change this when the order is sent?

But it would need to remember this variable permanently as the EA or computer might be turned off occasionally.

eg attached textfile

Files:
a.txt  7 kb
 
SanMiguel:

Well, yes but I need to list all the different levels that the code must check.

It must action the code when a level reaches 1.1, 1.2, 1.25, 1.3, 1.4, 1.5, 1.6, 1.7, 1.75, 1.8, 1.9, 2.0.

As soon as it has created orders for 1 level and those orders have closed, eg 1.6. It must send orders for 1.6 again until a different level has been hit.

So, when it next hits 1.7 it sends orders for 1.7 and 1.6 is now available again but 1.7 won't be.

Maybe I just add a second variable called IgnoreLevel and change this when the order is sent?

But it would need to remember this variable permanently as the EA or computer might be turned off occasionally.

eg attached textfile



?

Reason: