您需要 登录 才可以下载或查看,没有帐号?注册
extern double StopLoss = 30;
extern double TakeProfit = 1000;
extern double Lots = 0.1;
extern double TrailingStop = 200;
extern int ShortEma = 5;
extern int LongEma = 13;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function +
//| This is where we initialize internal variables for program use +
//+------------------------------------------------------------------+
int start()
{
//----
//LotCalc Declarations
int cnt, ticket, total;
//MAs
double FEMAnow,FEMAprevious,FEMA2previous,SEMAnow,SEMAprevious,SEMA2previous;
if(Bars 100)
{
Print( bars less than 100
return(0);
}
if(TakeProfit 10)
{
Print( TakeProfit less than 10
return(0); // check TakeProfit
}
//MA and Filter Variable Definition
FEMAnow = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);
FEMAprevious = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,1);
FEMA2previous = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,2);
SEMAnow = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_OPEN,0);
SEMAprevious = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_OPEN,1);
SEMA2previous = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_OPEN,2);
int isCrossed = 0;
if (FEMAnow SEMAnow FEMAprevious SEMAprevious FEMA2previous SEMAprevious)
{isCrossed = 1;
}
if (FEMAnow SEMAnow FEMAprevious SEMAprevious FEMAprevious SEMAprevious)
{isCrossed = 2;
}
//We check the trading terminal to see if it is empty
total = OrdersTotal();
if(total 1) //If trading terminal is empty...
{
if(isCrossed == 1) //if cross indicates LONG swing...
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,Ask-StopLoss*Point,Ask+TakeProfit*Point, EMa cross ,12345,0,Yellow);
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) //if cross indicates SHORT swing...
{
ticket=Orde
rSend(Symbol(),OP_SELL,Lots,Bid,2,Bid+StopLoss*Point,Bid-TakeProfit*Point, EMA cross ,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);
}
//Position exit function...
for(cnt=0;cnt total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
OrderPrint();
if(OrderType() =OP_SELL OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
// Check if we have a SHORT cross condition...
if(isCrossed == 2)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// Check our trailing stop to see if it needs to be adjusted
if(TrailingStop 0)
{
if(Bid-OrderOpenPrice() Point*TrailingStop)
{
if(OrderStopLoss() Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// Check if we have a LONG cross condition...
if(isCrossed == 1)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
// Check our trailing stop to see if it needs to be adjuste
if(TrailingStop 0)
{
if((OrderOpenPrice()-Ask) (Point*TrailingStop))
{
if((OrderStopLoss() (Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
外汇交易有很大的风险性,本站所有资源均来自网络,请选择使用,如若出现亏损,本站不承担任何责任!