Thanks to Ronald and Fry who helped me out with my last thread. I took what you said and was able to reslove that problem. But now I have a new one and I don't know what cause it. My code works but I cannot get it to open orders at the same time on different currencies. Now here is the twist. Last night the code was opening orders on mulitple currencies at the same time. This morning I tweaked one part of the code. It still works in making the order but it no longer will open orders on multiple currencies. I am looking for feedback on what caused this problem and any way to fix it. I will post the code in its entirety as it is and then I will post the segment that I changed.
Here is the EA:
Now here is the code as it was before I changed it. This segment is from the PriceChannel() function.
The part that I changed was how I told the EA to look for a cross. It originally said:
Then I tweaked it to say:
This is where I got the problem that the EA would no logner open trades on multiple currencies. So I tried to fix the problem by changing it to:
This did not fix the problem. Just to be clear, the reason I changed the code was because I was tweaking the presice time when the EA makes an entry. I will say the tweak worked to satisfy that problem. I would appreciate any advice people have.
Here is the EA:
PHP Code
extern string SEP01 = "*----Parameter Values------*";
extern double Lot_Size = 0.1;
extern int StopLoss = 200;
extern int TakeProfit = 50;
extern int Slippage = 3;
extern int Channel_Count = 15;
extern int Margins=-2;
extern int Magic_Number = 914189114;
int BarsCount=0, CounterTrend=0, Signal=0, ticket=0;
double smin1=0, smax1=0, Ssmax1=0, Ssmin1=0;
bool BuyInTrade = false, SellInTrade = false;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
// ---- Scan Trades
int ScanTrades()
{
int total = OrdersTotal();
int numords = 0;
for(int k=0; k<total; k++)
{
OrderSelect(k, SELECT_BY_POS);
if(OrderSymbol() == Symbol() && OrderType()<=OP_SELLSTOP && OrderMagicNumber() == Magic_Number)
numords++;
}
return(numords);
}
// ---- Price Channel
void PriceChannel()
{
Ssmin1=(Open[Lowest(NULL,0,MODE_OPEN,Channel_Count,0)]+Low[Lowest(NULL,0,MODE_LOW,Channel_Count,0)])/2;
Ssmax1=(Open[Highest(NULL,0,MODE_OPEN,Channel_Count,0)]+High[Highest(NULL,0,MODE_HIGH,Channel_Count,0)])/2;
smin1 = Ssmin1+(Ssmax1-Ssmin1)*Margins/100;
smax1 = Ssmax1-(Ssmax1-Ssmin1)*Margins/100;
if (iHigh(NULL,0,0) > smax1 && smax1 > 0) CounterTrend = -1;
if (iLow(NULL,0,0) < smin1 && smin1 > 0) CounterTrend = 1;
}
// ---- Trade Signal
void TradeSignal()
{
if (CounterTrend>0) Signal= 1;
if (CounterTrend<0) Signal= -1;
}
// ---- Open Long Position
void OrdBuyOpen()
{
ticket = OrderSend(Symbol(), OP_BUY, Lot_Size, Ask, 3, Ask-(StopLoss*Point), Ask+(TakeProfit*Point), NULL, Magic_Number, 0, Blue);
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
void OrdSellOpen()
{
ticket = OrderSend(Symbol(), OP_SELL, Lot_Size, Bid, 3, Bid+(StopLoss*Point), Bid-(TakeProfit*Point), NULL, Magic_Number, 0, Red);
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);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int total,ticket;
if (Bars > BarsCount)
{
PriceChannel();
TradeSignal();
if (ScanTrades()<1 && Signal>0) OrdBuyOpen();
if (ScanTrades()<1 && Signal<0) OrdSellOpen();
BarsCount = Bars;
}
return(0);
}
//+------------------------------------------------------------------+
PHP Code
void PriceChannel()
{
Ssmin1=(Open[Lowest(NULL,0,MODE_OPEN,Channel_Count,0)]+Low[Lowest(NULL,0,MODE_LOW,Channel_Count,0)])/2;
Ssmax1=(Open[Highest(NULL,0,MODE_OPEN,Channel_Count,0)]+High[Highest(NULL,0,MODE_HIGH,Channel_Count,0)])/2;
smin1 = Ssmin1+(Ssmax1-Ssmin1)*Margins/100;
smax1 = Ssmax1-(Ssmax1-Ssmin1)*Margins/100;
if (close[0] > smax1 && smax1 > 0) CounterTrend = -1;
if (close[0] < smin1 && smin1 > 0) CounterTrend = 1;
}
PHP Code
if (Close[0] > smax1 && smax1 > 0) CounterTrend = -1;
if (close[0] < smin1 && smin1 > 0) CounterTrend = 1;
PHP Code
if (High[0] > smax1 && smax1 > 0) CounterTrend = -1;
if (Low[0]< smin1 && smin1 > 0) CounterTrend = 1;
PHP Code
if (iHigh(NULL,0,0) > smax1 && smax1 > 0) CounterTrend = -1;
if (iLow(NULL,0,0) < smin1 && smin1 > 0) CounterTrend = 1;
Rhoman