Won't lock into trades

 

My goal is to always be Long or Short. For whatever reason the EA work for about 2 consecutive trades and then the EA will stop. Any reason why? thanks



//+------------------------------------------------------------------+

//| xxx.mq4 |
//| Tim Maz |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Tim Maz"
#property link "http://www.metaquotes.net"


//--General variables

extern int MAGICNUM = 1;
extern double numberOfLots = 1;
extern double lotSize = 0.1;
double tradeSize;
int count;
int ticketNum;
bool trade;
bool reverseStrategyL;
bool reverseStrategyS;
bool Long1;
bool Short1;
bool openLongOrder;
bool openShortOrder;
double num1 = 1000000;


//--Part I
string AE;
double A,C,AA,AB,AC,AN,AU,K,G8,W,Z,X,G9,AM,V,AT,H,I,J,S,A7,D,Y,e575,AAA,AAB,AW,AZ,AV,AX,AI,AAM,AJ,AAT,Sp,Yp;
double D10,D11,F11,C10,C11,F10,G7,G6,G5,G4,E4,E5,E6,E7,E8,E9,F4,F5,F6,F7,F8,F9,e574,e573,e572,e571,e570,e1505;
double HH,II,JJ,M;
double fib1[];
double fib2[];
double fib3[];
double fib4[];
double fib5[];
double fib6[];


//--Part II
extern string EE = "EURUSD";
double pip = 10;
bool checkedL1 = true;
bool checkedL2 = true;
bool checkedS1 = true;
bool checkedS2 = true;
double stop_loss,point;


//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
count = 0;
ticketNum = 0;
trade = false;
tradeSize = numberOfLots*lotSize;
openShortOrder = false;
openLongOrder = false;
AE = Symbol(); // currency pair from current chart

//----
return(0);
}

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{

//----Part I

if(Bars<2)
{
return(0);
}
else
{

e15 = iMA(NULL, 0, 15, 0, MODE_EMA, PRICE_CLOSE, 1);
F9 = 1.40;

Y = (F9 - e15);


if ((Y > 0))

{
Long1 = true;
Short1 = false;
if(checkedL1)
{
CreateSignal(StringConcatenate("Long1",TimeToStr(TimeLocal())),White,5,(Bid+(10*Point*pip)));
//checkedL1 = false;
}
}
else
{
Long1 = false;
checkedL1 = true;
}


if ((Y < 0))
{
Short1 = true;
Long1 = false;
if(checkedS1)
{
CreateSignal(StringConcatenate("Short1",TimeToStr(TimeLocal())),White,5,(Bid-(10*Point*pip)));
//checkedS1 = false;
}
}
else
{
Short1 = false;
checkedS1 = true;
}




//----Entry and Exit Logic

if(Long1)
{
if(!openLongOrder)
{
OrderSend(AE, OP_BUY, tradeSize, Ask, 0, 0, 0, "", MAGICNUM,0, Blue); // buy

openLongOrder = true;
}

}
else
{
if(openLongOrder)
{
CloseIt();

openLongOrder = false;
}
}

if(Short1)
{
if(!openShortOrder)
{

OrderSend(AE, OP_SELL, tradeSize, Bid, 0, 0, 0, "", MAGICNUM,0, Red); // sell

openShortOrder = true;
}
}
else
{

if(openShortOrder)
{
CloseIt();

openShortOrder = false;
}

}

}


//----
return(0);
}
void CloseIt()
{
//----


int total = OrdersTotal();
int i = total -1;
while(i>=0)
{
OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol()!=AE || OrderMagicNumber()!=MAGICNUM )
{
i--;
continue;
}
int type = OrderType();

bool result = false;

switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;


//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Blue );
break;

//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT :
case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
}

if(result == false)
{
Alert("Order ", OrderTicket(), " failed to close. Error:", GetLastError() );
Sleep(3000);
}
else
{
i--;
}
}

return(0);
}
void CreateSignal(string LabelName, color cl, int level, double price)
{

}




//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
 
HedgeForward:

My goal is to always be Long or Short. For whatever reason the EA work for about 2 consecutive trades and then the EA will stop. Any reason why? thanks

1. Please use the SRC button to paste your code so it will retain formatting. It's very hard to read like this.

2. What the hell is this:

double A,C,AA,AB,AC,AN,AU,K,G8,W,Z,X,G9,AM,V,AT,H,I,J,S,A7,D,Y,e575,AAA,AAB,AW,AZ,AV,AX,AI,AAM,AJ,AAT,Sp,Yp;
double D10,D11,F11,C10,C11,F10,G7,G6,G5,G4,E4,E5,E6,E7,E8,E9,F4,F5,F6,F7,F8,F9,e574,e573,e572,e571,e570,e1505;

Decompiled code, or are u just being artistic?