EA: needs some help

 
First I would like to say thanks to anyone who helps me with this EA. Im a newb at programming and have been working really hard to try and get an EA that will trade based on the standard momentum indicator. My idea is to only have one position open at a time. If no position is open then the EA will buy only if momentum is < 100.01 and then crosses above this point. For a short I want the EA to sell only if momentum is > 99.99 and then drops down to or below this level. Stop loss and take profit would set as soon as a position is taken.

Here is what I have so far.
&#8206;&#8207;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
extern int Expert_ID = 1234;

int start()
{

double MOM_1 = iMA(NULL,0,14,0,MODE_SMMA,PRICE_CLOSE,0);


int _GetLastError = 0, _OrdersTotal = OrdersTotal();
//---- search in all open positions
for ( int z = _OrdersTotal - 1; z>= 0; z -- )
{
//---- if an error occurs when searching for a position, go to the next one
if ( !OrderSelect( z, SELECT_BY_POS ) )
{
_GetLastError = GetLastError();
Print( "OrderSelect( ", z, ", SELECT_BY_POS ) - Error #", _GetLastError );
continue;
}

//---- if a position is closed not for the current symbol, skip it
if ( OrderSymbol() != Symbol() ) continue;

//---- if the MagicNumber is not equal to the Expert_ID, skip this position
if ( OrderMagicNumber() != Expert_ID ) continue;

//---- if a BUY position is opened,
if ( OrderType() == OP_BUY )
{
//---- if the Momentum has met the 99.99 line top-down,
if ( NormalizeDouble( MOM_1, Digits + 1 ) < 99.99 &&
NormalizeDouble( MOM_1, Digits + 1 )>= 99.99 )
{
//---- close the position
if ( !OrderClose( OrderTicket(), OrderLots(), Bid, 5, Green ) )
{
_GetLastError = GetLastError();
Alert( "Error OrderClose # ", _GetLastError );
return(-1);
}
}
//---- if the alert has not changed, exit: it is too early to open a new position
else
{ return(0); }
}
//---- if a SELL position is opened,
if ( OrderType() == OP_SELL )
{
//---- if the Momentum has met the zero line bottom-up,
if ( NormalizeDouble( MOM_1, Digits + 1 )> 100.01 &&
NormalizeDouble( MOM_1, Digits + 1 ) <= 100.01 )
{
//---- close the position
if ( !OrderClose( OrderTicket(), OrderLots(), Ask, 5, Red ) )
{
_GetLastError = GetLastError();
Alert( "Error OrderClose No ", _GetLastError );
return(-1);
}
}
//---- if the alert has not changed, exit: it is too early to open a new position
else return(0);
}
}

//+------------------------------------------------------------------+
//| if execution reached this point, there is no open position |
//| EA will look to open a position |
//+------------------------------------------------------------------+

//---- if the Momentum has met the zero line bottom-up,
if ( NormalizeDouble( MOM_1, Digits + 1 )> 100.01 &&
NormalizeDouble( MOM_1, Digits + 1 ) <= 100.01 )
{
//---- open a BUY position
if ( OrderSend( Symbol(), OP_BUY, 0.1, Ask, 5, Ask-5.0*Point, Ask+5.0*Point, "MOM_test",
Expert_ID, 0, Green ) < 0 )
{
_GetLastError = GetLastError();
Alert( "Error OrderSend # ", _GetLastError );
return(-1);
}
return(0);
}
//---- if the Momentum has met the zero line top-down,
if ( NormalizeDouble( MOM_1, Digits + 1 ) < 99.99 &&
NormalizeDouble( MOM_1, Digits + 1 )>= 99.99 )
{
//---- open a SELL position
if ( OrderSend( Symbol(), OP_SELL, 0.1, Bid, 5, Bid+5.0*Point, Bid-5.0*Point, "MOM_test",
Expert_ID, 0, Red ) < 0 )
{
_GetLastError = GetLastError();
Alert( "Error OrderSend # ", _GetLastError );
return(-1);
}
return(0);
}

return(0);
}


//----
return(0);

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