Hi People,
I am trying to add spike protection to an EA so when a buy stop gets hit via a spike it closes the Trade immediately and before it turns out badly. I am sure all you traders know exactly what I am talking about.
Anyway, I wrote this code but, I must be missing something because, it closes every Trade.. Not what I wanted of course.
Can anyone spot why it is doing this. (dont forget I am just knew at this)
thanks
if (spikeActivatedTrade ==true)
{
total = OrdersTotal();
for(i = total - 1; i >= 0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() != Symbol()) continue;
if((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
// Bears Spike
if (((type == _OP_BUY) && (iOpen(NULL,PERIOD_M15,1))>(iClose(NULL,PERIOD_M15,1))) && (iHigh(NULL,PERIOD_M15,1))+(iLow(NULL,PERIOD_M15,1))/2 > (iOpen(NULL,PERIOD_M15,1)))
{
if(PrintComments) Print("Closed spike activated order");
glOrderClose();
}
}
}
}
I am trying to add spike protection to an EA so when a buy stop gets hit via a spike it closes the Trade immediately and before it turns out badly. I am sure all you traders know exactly what I am talking about.
Anyway, I wrote this code but, I must be missing something because, it closes every Trade.. Not what I wanted of course.
Can anyone spot why it is doing this. (dont forget I am just knew at this)
thanks
if (spikeActivatedTrade ==true)
{
total = OrdersTotal();
for(i = total - 1; i >= 0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() != Symbol()) continue;
if((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
// Bears Spike
if (((type == _OP_BUY) && (iOpen(NULL,PERIOD_M15,1))>(iClose(NULL,PERIOD_M15,1))) && (iHigh(NULL,PERIOD_M15,1))+(iLow(NULL,PERIOD_M15,1))/2 > (iOpen(NULL,PERIOD_M15,1)))
{
if(PrintComments) Print("Closed spike activated order");
glOrderClose();
}
}
}
}