I've created a couple of simple EA's based on some indicators. (Thank you to those who helped with an earlier question I had) And the EA's work in that they are entering the market when they are supposed to. But I am having a problem with where they are entering the market. I tried to write the EA's so that if a signal appeared the EA would enter the market as close to the open as possible.
Now I know that it will not hit the open exactly and that I need to account for the spreadh and that's all right but my problem is that entry is nowhere near the open. It seems to happen more for long positions than for shorts but when the EA enters the position it when accounting for the spread seems to be based on the high of a bar rather than the open. Or if it's a short the low of the bar. Can any one help with this.
Here is the code for the indicators I am using:
And here is the code for the buy and sell:
This is what I assume would be the relevant parts of the code. If more is needed please let me know. Basically, I tried to write the code so that any signals that would appear would be centered around the open of a bar but as I said my problem is the positions seem to be made relative to the high or low.
Thanks for listening and to any one who can offer advice.
Now I know that it will not hit the open exactly and that I need to account for the spreadh and that's all right but my problem is that entry is nowhere near the open. It seems to happen more for long positions than for shorts but when the EA enters the position it when accounting for the spread seems to be based on the high of a bar rather than the open. Or if it's a short the low of the bar. Can any one help with this.
Here is the code for the indicators I am using:
PHP Code
double OsMA_Current=iOsMA(NULL,0,12,26,9,PRICE_OPEN,0);
double OsMA_Previous=iOsMA(NULL,0,12,26,9,PRICE_OPEN,1);
double ADX_Current1=iADX(NULL,0,14,PRICE_OPEN,MODE_PLUSDI,0); //DI+
double ADX_Current2=iADX(NULL,0,14,PRICE_OPEN,MODE_MINUSDI,0); //DI-
double ADX_Previous1=iADX(NULL,0,14,PRICE_OPEN,MODE_PLUSDI,1); //DI+
double ADX_Previous2=iADX(NULL,0,14,PRICE_OPEN,MODE_MINUSDI,1); //DI-
PHP Code
//+------------------------------------------------------------------+
//| Entry Signal Begin (Long Position) |
//+------------------------------------------------------------------+
if(Order == SIGNAL_BUY1 || Order == SIGNAL_BUY2 || Order == SIGNAL_BUY3)
{
if(!IsTrade)
{
Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-200*Point,Ask+TakeProfit*Point,NULL,0,0,Green);
if(Ticket>0)
{
if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
}
//+------------------------------------------------------------------+
//| Entry Signal End (Long Position) |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Entry Signal Begin (Shot Position) |
//+------------------------------------------------------------------+
if(Order == SIGNAL_SELL1 || Order == SIGNAL_SELL2 || Order == SIGNAL_SELL3)
{
if(!IsTrade)
{
Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+200*Point,Bid-TakeProfit*Point,NULL,0,0,Red);
if(Ticket>0)
{
if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
}
//+------------------------------------------------------------------+
//| Entry Signal End (Short Position) |
//+------------------------------------------------------------------+
Thanks for listening and to any one who can offer advice.
Rhoman