
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
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();
}
}
}
//+---------------------------------------------------------------