You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Here is what I have so far.
‎‏
//+------------------------------------------------------------------+
//| 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);
//+------------------------------------------------------------------+