Does anyone know why this EA is only buying and not selling?

 

//+------------------------------------------------------------------+
//| Patrick's Expert Template.mq4 |
//| Copyright © 2006, InterbankFX llc |
//| http://www.interbankfx.com |
//+------------------------------------------------------------------+
// Version 0.11 Written by Patrick Nouvion |
// Last update September 25 2006 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| COPYRIGHT |
//| YOU SHOULD USE YOUR OWN COPYRIGHT HERE |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, InterbankFX llc"
#property link "http://www.interbankfx.com"
//+------------------------------------------------------------------+
//| COMMON DECLARATION |
//| YOU SHOULD NOT HAVE TO MODIFY ANYTHING BELOW THIS BOX |
//+------------------------------------------------------------------+
datetime timeprev=0;
bool EnterLong = false;
bool ExitLong = false;
bool EnterShort = false;
bool ExitShort = false;
//+------------------------------------------------------------------+
//| EXPERT COLORS |
//| ADJUST THESE VALUES TO MATCH REQUIREMENTS |
//+------------------------------------------------------------------+
//---- This is the name that will appear on the chart if the expert
//---- is attached
static string ExpertName = "Basic MACD V1";
//---- Enter Long Color
static color EnterLongColor = Green;
//---- Enter Short Color
static color EnterShortColor = Red;
//---- Exit Long Color
static color ExitLongColor = Blue;
//---- Exit Short Color
static color ExitShortColor = Pink;
//---- If using pending orders and if you need an expiration enter the value here
static int EXPIRATION = 0;

//+------------------------------------------------------------------+
//| EXPERT ID |
//+------------------------------------------------------------------+
// You need to give a unique id to each one of your expert
// This will be used as the magic number and then keep track of
// the orders generated by the expert.

//---- The expert ID has to be a 2 digit number followed by 0000
//---- For example: 550000 or 120000 etc ...
static int ExpertID = 070000;

//+------------------------------------------------------------------+
//| USER INPUT |
//| ADJUST THESE VALUES TO MATCH REQUIREMENTS |
//+------------------------------------------------------------------+
//| Trading Inputs/Indicators Inputs |
//+------------------------------------------------------------------+
// If you do not need to use one of these inputs simply comment it out
// For example:
// extern bool Multiple entries = false;

extern double Lots = 0.1;
//---- Set stoploss to 0.0 if you don't want to use it
extern double StopLoss= 30.0;
//---- Set ProfitTarget to 0.0 if you don't want to use it
extern double ProfitTarget = 50.0;
//---- Set TrailingStop to 0.0 if you don't want to use it
extern double TrailingStop = 20.0;
//---- Slippage / Max deviation from quoted price
extern int Slippage= 0;

//---- Do we want the expert to work accross all time frame
//---- or just the currently selected time frame
extern bool TimeSpecific = true;

// Create any user input for the indicators you will use here
// For example:
//extern string array = "Close";
//extern int Periods=14;
//extern int Deviation=0;
extern int FastEMA = 12;
extern int SlowEMA = 26;
extern int SignalEMA = 9;

//+------------------------------------------------------------------+
//| EXPERT BASIC INITIALISATION |
//| YOU SHOULD NOT HAVE TO MODIFY ANYTHING BELOW THIS BOX |
//+------------------------------------------------------------------+
int start()
{

if(timeprev==Time[0]){return(0);}
timeprev = Time[0];

int MagicNumber = 0;
MagicNumber = MakeMagicNumber( ExpertID, TimeSpecific );

EnterLong = false;
ExitLong = false;
EnterShort = false;
ExitShort = false;

TrailingAlls(0,TrailingStop);
//+------------------------------------------------------------------+
//| EXPERT BASIC CALCULATION |
//| START HERE |
//+------------------------------------------------------------------+

double MACD = iCustom(NULL,0,"Zero Lag MACD",FastEMA,SlowEMA,SignalEMA,MODE_MAIN,1)-iCustom(NULL,0,"Zero Lag MACD",FastEMA,SlowEMA,SignalEMA,MODE_SIGNAL,1);
double MACD1 = iCustom(NULL,0,"Zero Lag MACD",FastEMA,SlowEMA,SignalEMA,MODE_MAIN,2)-iCustom(NULL,0,"Zero Lag MACD",FastEMA,SlowEMA,SignalEMA,MODE_SIGNAL,2);
double MACD2 = iCustom(NULL,0,"Zero Lag MACD",FastEMA,SlowEMA,SignalEMA,MODE_MAIN,3)-iCustom(NULL,0,"Zero Lag MACD",FastEMA,SlowEMA,SignalEMA,MODE_SIGNAL,3);
double LastLongLevel = 0.0;
double LastShortLevel = 0.0;

if( MACD > MACD1 && MACD1 < MACD2)
{
if( Close[1] > LastLongLevel )
{
EnterLong = True;
}
LastLongLevel = Close[1];
}

if( MACD < MACD1 && MACD1 > MACD2)
{
if( Close[1] < LastShortLevel )
{
EnterShort = True;
}
LastShortLevel = Close[1];
}


//+------------------------------------------------------------------+
//| EXPERT BASIC CALCULATION |
//| END HERE |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| YOU SHOULD NOT HAVE TO MODIFY ANYTHING BELOW THIS BOX |
//+------------------------------------------------------------------+

// ENTER LONG CONDITION
if(EnterLong == true && CountLongs(MagicNumber)== 0)
{
//CLOSE OPEN ORDER
CloseShorts(MagicNumber);
// PLACE THE ORDER
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,StopLong(Bid,StopLoss),TakeLong(Ask,ProfitTarget),ExpertName,MagicNumber,EXPIRATION,EnterLongColor);
}
// ENTER SHORT CONDITION
if(EnterShort == true && CountShorts(MagicNumber)== 0)
{
//CLOSE OPEN ORDER
CloseLongs(MagicNumber);
// PLACE THE ORDER
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,StopShort(Ask,StopLoss),TakeShort(Bid,ProfitTarget),ExpertName,MagicNumber,EXPIRATION,EnterShortColor);
}
if(ExitLong == true && CountLongs(MagicNumber)== 1)
{
//CLOSE OPEN ORDER
CloseLongs(MagicNumber);
}
if(ExitShort == true && CountShorts(MagicNumber)== 1)
{
//CLOSE OPEN ORDER
CloseShorts(MagicNumber);
}
return(0);
}
//+------------------------------------------------------------------+
//| EXTERNAL FUNCTIONS |
//| YOU SHOULD NOT HAVE TO MODIFY ANYTHING BELOW THIS BOX |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Make Magic Number |
//+------------------------------------------------------------------+
int MakeMagicNumber( int ExpertID, bool TimeSpecific )
{
int SymbolCode = 0;
int PeriodCode = 0;
int MagicNumber = 0;

//---- Symbol Code
if( Symbol() == "AUDCAD" || Symbol() == "AUDCADm" ) { SymbolCode = 1000; }
else if( Symbol() == "AUDJPY" || Symbol() == "AUDJPYm" ) { SymbolCode = 2000; }
else if( Symbol() == "AUDNZD" || Symbol() == "AUDNZDm" ) { SymbolCode = 3000; }
else if( Symbol() == "AUDUSD" || Symbol() == "AUDUSDm" ) { SymbolCode = 4000; }
else if( Symbol() == "CHFJPY" || Symbol() == "CHFJPYm" ) { SymbolCode = 5000; }
else if( Symbol() == "EURAUD" || Symbol() == "EURAUDm" ) { SymbolCode = 6000; }
else if( Symbol() == "EURCAD" || Symbol() == "EURCADm" ) { SymbolCode = 7000; }
else if( Symbol() == "EURCHF" || Symbol() == "EURCHFm" ) { SymbolCode = 8000; }
else if( Symbol() == "EURGBP" || Symbol() == "EURGBPm" ) { SymbolCode = 9000; }
else if( Symbol() == "EURJPY" || Symbol() == "EURJPYm" ) { SymbolCode = 1000; }
else if( Symbol() == "EURUSD" || Symbol() == "EURUSDm" ) { SymbolCode = 1100; }
else if( Symbol() == "GBPCHF" || Symbol() == "GBPCHFm" ) { SymbolCode = 1200; }
else if( Symbol() == "GBPJPY" || Symbol() == "GBPJPYm" ) { SymbolCode = 1300; }
else if( Symbol() == "GBPUSD" || Symbol() == "GBPUSDm" ) { SymbolCode = 1400; }
else if( Symbol() == "NZDJPY" || Symbol() == "NZDJPYm" ) { SymbolCode = 1500; }
else if( Symbol() == "NZDUSD" || Symbol() == "NZDUSDm" ) { SymbolCode = 1600; }
else if( Symbol() == "USDCAD" || Symbol() == "USDCADm" ) { SymbolCode = 1700; }
else if( Symbol() == "USDCHF" || Symbol() == "USDCHFm" ) { SymbolCode = 1800; }
else if( Symbol() == "USDJPY" || Symbol() == "USDJPYm" ) { SymbolCode = 1900; }


//---- Period Code
if( TimeSpecific )
{
if( Period() == 1 ) { PeriodCode = 10; }
else if( Period() == 5 ) { PeriodCode = 20; }
else if( Period() == 15 ) { PeriodCode = 30; }
else if( Period() == 30 ) { PeriodCode = 40; }
else if( Period() == 60 ) { PeriodCode = 50; }
else if( Period() == 240 ) { PeriodCode = 60; }
else if( Period() == 1440 ) { PeriodCode = 70; }
else if( Period() == 10080 ){ PeriodCode = 80; }
}
else
{
PeriodCode = 0;
}
//---- Calculate MagicNumber
MagicNumber = ExpertID+SymbolCode+PeriodCode;
return(MagicNumber);
}

//+------------------------------------------------------------------+
//| Calculate Stop Long |
//+------------------------------------------------------------------+
double StopLong(double price,int stop)
{
if(stop==0)
{
return(0);
}
else
{
return(price-(stop*Point));
}
}
//+------------------------------------------------------------------+
//| Calculate Stop Short |
//+------------------------------------------------------------------+
double StopShort(double price,int stop)
{
if(stop==0)
{
return(0);
}
else
{
return(price+(stop*Point));
}
}
//+------------------------------------------------------------------+
//| Calculate Profit Target Long |
//+------------------------------------------------------------------+
double TakeLong(double price,int take)
{
if(take==0) { return(0);}
else { return(price+(take*Point));}
}
//+------------------------------------------------------------------+
//| Calculate Profit Target Short |
//+------------------------------------------------------------------+
double TakeShort(double price,int take)
{
if(take==0) { return(0);}
else { return(price-(take*Point));}
}
//+------------------------------------------------------------------+
//| Calculate concurrent Long position |
//+------------------------------------------------------------------+
int CountLongs(int MagicNumber)
{
int count=0;
int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if( OrderSymbol()!=Symbol() || OrderMagicNumber() != MagicNumber )
continue;

if(OrderType()==OP_BUY)
count++;
}//for
return(count);
}
//+------------------------------------------------------------------+
//| Calculate concurrent short position |
//+------------------------------------------------------------------+
int CountShorts(int MagicNumber)
{
int count=0;
int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol() || OrderMagicNumber() != MagicNumber )
continue;

if(OrderType()==OP_SELL)
count++;
}//for
return(count);
}
//+------------------------------------------------------------------+
//| Close Long Position |
//+------------------------------------------------------------------+
void CloseLongs(int MagicNumber)
{
int i = OrdersTotal();

while( CountLongs(MagicNumber) != 0 && i >= 0 )
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if( OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber )
{
i--;
continue;
}
else if(OrderType()==OP_BUY || OrderType()== OP_BUYLIMIT)
{
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,ExitLongColor);
i--;
}
}
}
//+------------------------------------------------------------------+
//| Close Short Position |
//+------------------------------------------------------------------+
void CloseShorts(int MagicNumber)
{
int i = OrdersTotal();

while( CountShorts(MagicNumber) != 0 && i >= 0 )
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if( OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)
{
i--;
continue;
}
else if(OrderType()== OP_SELL || OrderType()==OP_SELLLIMIT )
{
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,ExitShortColor);
}
}
}
//+------------------------------------------------------------------+
//| Calculates Trailing Stops |
//+------------------------------------------------------------------+
void TrailingAlls(int start,int stop)
{
int profit;
double stoptrade;
double stopcal;

if(stop==0) return;

int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
continue;

if(OrderSymbol()!=Symbol())
continue;

if(OrderType()==OP_BUY)
{
profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);
if(profit<start)
continue;
stoptrade=OrderStopLoss();
stopcal=Bid-(stop*Point);
if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,EnterLongColor);
}//Long

if(OrderType()==OP_SELL)
{
profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);
if(profit<start)
continue;
stoptrade=OrderStopLoss();
stopcal=Ask+(stop*Point);
if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,EnterShortColor);
}//Shrt

}//for
}

 
 

Ed

Something like this

Print("Place SELL order lots: ", Lots);

immediately prior to the OrderSend will tell you if you have got into the code section you expect.

The Journal would then show if SELL orders are initiated but failing to complete.

-BB-

 

I JUST DID AND THIS IS THE MESSAGE IN THE JOURNAL TAB

2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4827 at 2008.02.25 04:15 and price 1.4829 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4827 at 2008.02.25 04:05 and price 1.4828 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4827 at 2008.02.25 04:00 and price 1.4828 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4830 at 2008.02.25 03:00 and price 1.4831 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4825 at 2008.02.25 02:55 and price 1.4822 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4825 at 2008.02.25 02:50 and price 1.4821 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4831 at 2008.02.25 02:50 and price 1.4832 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4833 at 2008.02.25 01:55 and price 1.4830 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4833 at 2008.02.25 01:50 and price 1.4829 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4833 at 2008.02.25 01:45 and price 1.4832 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:45 and price 1.4837 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:40 and price 1.4838 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:35 and price 1.4838 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:30 and price 1.4840 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:25 and price 1.4839 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:20 and price 1.4840 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:15 and price 1.4839 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:10 and price 1.4837 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4835 at 2008.02.25 01:05 and price 1.4837 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4838 at 2008.02.25 00:50 and price 1.4840 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4838 at 2008.02.25 00:35 and price 1.4842 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4834 at 2008.02.25 00:30 and price 1.4833 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4838 at 2008.02.25 00:30 and price 1.4841 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4834 at 2008.02.25 00:25 and price 1.4833 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (low value 1.4834 at 2008.02.25 00:15 and price 1.4833 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4838 at 2008.02.25 00:10 and price 1.4839 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4838 at 2008.02.25 00:05 and price 1.4841 mismatched)
2008.07.04 11:08:30 TestGenerator: unmatched data error (high value 1.4838 at 2008.02.25 00:00 and price 1.4842 mismatched)

 

Ed

Set your Slippage to 3 and have another go.

If that isnt it you have to put a Print statement for your OrderSend values

Print("StopShort(Ask,StopLoss) ", StopShort(Ask,StopLoss), "TakeShort(Bid,ProfitTarget) ", TakeShort(Bid,ProfitTarget));

-BB-

 

Moderator
4059
stringo 2007.09.19 14:16

It means for example M1 data and other (for example H1) data mismatched. At 19:00 1minute bar shows high 224.55 but appropriate 1hour bar has high 224.50. Mismatching.

Ask your broker for correct data.

 

This is what I get when I try to compile, maybe I didnt insert it in the right place.

'(' - function definition unexpected C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (196, 20)
'MagicNumber' - variable already defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (200, 8)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (203, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (204, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (205, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (206, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (207, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (208, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (209, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (210, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (211, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (212, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (213, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (214, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (215, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (216, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (217, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (218, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (219, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (220, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (221, 61)
'SymbolCode' - variable not defined C:\Program Files\FXDD - MetaTrader 4\experts\MACD.mq4 (241, 27)
22 error(s), 0 warning(s)

 
phy wrote
 

@Eduardo Igmacio Balda Salomon

Dear Eduado,


Following EA of SMA 20 Crossover 50 code not Buying and selling in Demo Account 

Kindly Suggest me to solve this 


void OnTick()

  {

   // creat an array for several price

   double myMovingAverageArray1[],myMovingAverageArray2[];


   // define the properrties of the Moving Average1 

   int movingAverageDefinitionl = iMA (_Symbol,_Period,20,0,MODE_EMA,PRICE_CLOSE);


   // define the properrties of the Moving Average2

   int movingAverageDefinition2 = iMA (_Symbol,_Period,50,0,MODE_EMA,PRICE_CLOSE);


   // sort the price array1 from the current candle downwards

   ArraySetAsSeries(myMovingAverageArray1,true);


   // sort the price array1 from the current candle downwards

   ArraySetAsSeries(myMovingAverageArray2,true);


   //Defined MA1, one line,current candle,3 candles, store result

   CopyBuffer(movingAverageDefinitionl,0,0,3,myMovingAverageArray1);

   

   //Defined MA2, one line,current candle,3 candles, store result

   CopyBuffer(movingAverageDefinition2,0,0,3,myMovingAverageArray2);


    if (  // Check if the 20 candle EA is above the 50 candle EA

         (myMovingAverageArray1[0]>myMovingAverageArray2[0])

      && (myMovingAverageArray1[1]<myMovingAverageArray2[1])

      )

         {

         Comment ("BUY");

         }

         

   if (   // Check if the 50 candle EA is above the 20 candle EA

         (myMovingAverageArray1[0]<myMovingAverageArray2[0])

      && (myMovingAverageArray1[1]>myMovingAverageArray2[1])

      )

         {

         Comment ("SELL");

         }

  }

 
edwin:
if(EnterShort == true && CountShorts(MagicNumber)== 0)
{
//CLOSE OPEN ORDER
CloseLongs(MagicNumber);
// PLACE THE ORDER
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,StopShort(Ask,StopLoss),TakeShort(Bid,ProfitTarget),ExpertName,MagicNumber,EXPIRATION,EnterShortColor);
}

it is because EnterShort is never true ... :-)

And why EnterShort is nerver true ?

if( MACD < MACD1 && MACD1 > MACD2)
{
if( Close[1] < LastShortLevel )
{
EnterShort = True;
}
LastShortLevel = Close[1];
}

it is because Close[1] is never below

LastShortLevel 

And why is it never below, it is because LastShortLevel is not initialised, so it is ==  0.

Try to give it a value like 1 000 000 to see


line 119    double LastShortLevel = 10000000.0;

Reason: