I have a completed EA and it was working but there was a glitch in its process but after I tweaked it, it will now not enter trades when the entry signal appears.
It used to enter fine but the problem was that the signal for the close of the order was appearing while the bar was still open. So the EA would open and close a position several times in one bar. When i tried to fix that by changing the paramters for the closing price of the bar it considers it won't open trades at all.
Here is the full code.
My hunch is that the problem is where I wrote told the indicators to look at the close of the previous bar because that is what I changed. It used to be set to the current bar. As I understand it I have programed the EA to now look for a signal at the closing price of the previous bar.
I am having the same trouble on another EA I am working on that is formatted almost exactly like this one but uses the Awesome Oscillator. If anyone has any thoughts, I am open to just about anything.
My goal is to get the EA to open trades when the signal appears and close when the close appears but I don't want the EA to consider close signal until the bar actually closes.
It used to enter fine but the problem was that the signal for the close of the order was appearing while the bar was still open. So the EA would open and close a position several times in one bar. When i tried to fix that by changing the paramters for the closing price of the bar it considers it won't open trades at all.
Here is the full code.
PHP Code
//Entry opportunity Functions
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
//Input Variables
extern int MagicNumber = 193916915;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 0.1;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 200;
extern bool UseTakeProfit = True;
extern int TakeProfit = 3;
extern bool UseTrailingStop = False;
extern int TrailingStop = 0;
extern double Shift=0;
//Global Variables
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
BarCount = Bars;
if (EachTickMode) Current = 0;
else Current = 1;
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//+------------------------------------------------------------------+
//| Variable Declaration |
//+------------------------------------------------------------------+
int Total, Ticket, Order, i;
double StopLossLevel, TakeProfitLevel;
double OsMA;
double CCI;
bool IsTrade;
//+------------------------------------------------------------------+
//| Variable Definition |
//+------------------------------------------------------------------+
IsTrade = False;
OsMA = iOsMA(NULL,0,12,26,9,PRICE_CLOSE,1);
CCI = iCCI(NULL,0,14,PRICE_CLOSE,1);
if(OsMA > 0 && CCI > 0) Order = SIGNAL_BUY;
if(OsMA < 0 && CCI < 0) Order = SIGNAL_SELL;
if(EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;
//+------------------------------------------------------------------+
//| Limit Open Positions |
//+------------------------------------------------------------------+
for(i=0; i<Total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
IsTrade = True;
}
}
//+------------------------------------------------------------------+
//| Check For Already Open Position |
//+------------------------------------------------------------------+
if(IsTrade == True)
{
if(OrderType()==OP_BUY)
{
if(OsMA < 0 || CCI < 0)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); //Close Long Position
return(0);
}
}
else
{
if(OsMA > 0 || CCI > 0)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //Close Short Position
return(0);
}
}
}
//+------------------------------------------------------------------+
//| Open Long Position |
//+------------------------------------------------------------------+
if(Order==SIGNAL_BUY)
{
if(!IsTrade)
{
Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*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);
}
}
//+------------------------------------------------------------------+
//| Open Short Position |
//+------------------------------------------------------------------+
if(Order==SIGNAL_SELL)
{
if(!IsTrade)
{
Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*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);
}
}
return(0);
}
//+------------------------------------------------------------------+]
I am having the same trouble on another EA I am working on that is formatted almost exactly like this one but uses the Awesome Oscillator. If anyone has any thoughts, I am open to just about anything.
My goal is to get the EA to open trades when the signal appears and close when the close appears but I don't want the EA to consider close signal until the bar actually closes.
Rhoman