Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
This program is not working, can You tell me why?? What is wrong??
I don't want use stoploss, I want close position, when fast MA cross slow MA.
GOLD
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
//extern double TakeProfit = 1000;
extern double Lots = 0.1;
//extern double TrailingStop = 400;
//extern double StopLoss = 500;
double Elliottfast,Elliottslow,Elliottcurrent,Elliottprevious;
int cnt, ticket, total;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
void OpBuySell()
{
Elliottcurrent=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,0);
Elliottprevious=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,1);
Elliottfast=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,0);
Elliottslow=iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,0);
if(Elliottfast>Elliottslow && Elliottprevious<Elliottslow)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Green);
return(0);
}
if(Elliottfast<Elliottslow && Elliottprevious>Elliottslow)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",16384,0,Red);
return(0);
}
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
void CloseOpBuySell()
{
if(OrderType()==OP_BUY) // long position is opened
{
if(Elliottfast<Elliottslow)
{
OrderClose(OrderTicket(),OrderLots(),Bid,1,White);
return(0);
}
}
if(OrderType()==OP_SELL) // short position is opened
{
if(Elliottfast>Elliottslow)
{
OrderClose(OrderTicket(),OrderLots(),Ask,1,Black);
return(0);
}
}
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int total=OrdersTotal();
total=OrdersTotal();
if(total<1)
{
OpBuySell();
return(0);
}
for(int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol
{
CloseOpBuySell();
}
}
}
//+---------------------------------------------------------------