Problem with my first EA using T3 tilson

Hi good day, I’m just learning how to program in mql4, I read an interesting tutorial which gave an EA basics, and I made small modifications to it so I could built my own. Here is the code, as you can see it’s a simple T3 Tilson crossover, that gets called with the iCustom function, the T3 indicator I downloaded it from metaquites site.

However when I add the EA into any chart the expert logs starts going crazy. let’s say I add the EA to a USDCAD chart, the log says

T3EA USDCAD loaded successfullly

T3EA USDCAD inputs…

T3EA USDCAD iniitialized

but then it starts going crazy right away, and it says

T3 USDCAD, M1 initialized
T3 USDCAD, M1 loaded successfully

T3 USDCAD, M1 initialized
T3 USDCAD, M1 loaded successfully

T3 USDCAD, M1 initialized
T3 USDCAD, M1 loaded successfully

T3 USDCAD, M1 initialized
T3 USDCAD, M1 loaded successfully

all over again over and over…

and when I remove the EA the log will say

T3EA USDCAD denitialized
T3 EA USDCAD uninit reason 1

and then right away

T3 USDCAD M1, deinitialized
T3 USDCAD M1, uninit reason 1
T3 USDCAD M1, removed.

T3 USDCAD M1, deinitialized
T3 USDCAD M1, uninit reason 1
T3 USDCAD M1, removed.

all over again… until I close the chart I was working on.

so far I haven’t seen the EA placing any trades… So I think all of this is related…

any ideas how can I get it to work??

here is the code, thank in advance.

//---- input parameters
extern double TakeProfit=250.0;
extern double Lots=0.1;
extern double TrailingStop=35.0;
//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----

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

int Crossed (double line1, double line2)
{
static int last_direction = 0;
static int current_dirction = 0;

if(line1>line2)current_dirction = 1; //up
if(line1<line2)current_dirction = 2; //down

if(current_dirction != last_direction) //changed
{
last_direction = current_dirction;
return (last_direction);
}
else
{
return (0);
}
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
//----

int cnt, ticket, total;
double shortT3, longT3;

if(Bars<100)
{
Print(“bars less than 100”);
return(0);
}
if(TakeProfit<10)
{
Print(“TakeProfit less than 10”);
return(0); // check TakeProfit
}

shortT3 = iCustom(NULL,0,“T3”,10,0,0);
longT3 = iCustom(NULL,0,“T3”,21,0,0);

int isCrossed = Crossed (shortT3,longT3);

total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,“My EA”,12345,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);
}
if(isCrossed == 2)
{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfitPoint,“My EA”,12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(isCrossed == 2)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point
TrailingStop)
{
if(OrderStopLoss()<Bid-PointTrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point
TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(isCrossed == 1)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(PointTrailingStop))
{
if((OrderStopLoss()>(Ask+Point
TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
//±-----------------------------------------------------------------+