|
周末做个EA小程序,编译看不出问题,测试一直不开单啊,拜求版主帮我看看啊
//---- input parameters
extern double TakeProfit = 20;
extern double StopLoss = 30;
extern double Lots = 2;
extern double TrailingStop = 50;
int period=26;
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double UPBuffer[];
double DOWNBuffer[];
double MO[];
double DO[];
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(3,DRAW_ARROW);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(3,233);
SetIndexArrow(4,234);
IndicatorDigits(Digits+1);
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,UPBuffer);
SetIndexBuffer(4,DOWNBuffer);
SetIndexBuffer(5,MO);
SetIndexBuffer(6,DO);
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;
int limit;
int counted_bars=IndicatorCounted();
double prev,current,old;
double Value=0,Value1=0,Value2=0,Fish=0,Fish1=0,Fish2=0;
double price;
double MinL=0;
double MaxH=0;
static int isCrossed = 0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<Bars; i++)
{
MaxH = High[Highest(NULL,0,MODE_HIGH,period,i)];
MinL = Low[Lowest(NULL,0,MODE_LOW,period,i)];
price = (High[i]+Low[i])/2;
if(MaxH-MinL == 0) Value =0.67 *2*(0-0.5) +0.33 *Value1;
else Value = 0.67*2*((price-MinL)/(MaxH-MinL)-0.5) +0.33 *Value1;
Value=MathMin(MathMax(Value,-0.999),0.999);
if(1-Value == 0) ExtBuffer0[i]=0.5+0.5*Fish1;
else ExtBuffer0[i]=0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
Value1=Value;
Fish1=ExtBuffer0[i];
}
bool up=true;
for(i=Bars; i>=0; i--)
{
current=ExtBuffer0[i];
prev=ExtBuffer0[i+1];
MO[i]=ExtBuffer0[i];
DO[i]=ExtBuffer0[i+1];
if (((current<0)&&(prev>0))||(current<0)) up=false;
if (((current>0)&&(prev<0))||(current>0)) up=true;
if(!up)
{
ExtBuffer2[i]=current;
ExtBuffer1[i]=0.0;
}
else
{
ExtBuffer1[i]=current;
ExtBuffer2[i]=0.0;
}
}
for(i=Bars; i>=0; i--)
{
if (MO[i]>0 && MO[i+1]<0)
isCrossed = 1;
UPBuffer[i]=-0.1 ;
if (MO[i]<0 && MO[i+1]>0)
isCrossed =2 ;
DOWNBuffer[i]=0.1;
return(0);
}
//----
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - StopLoss*Point,
Ask + TakeProfit*Point, "Fisher", 0, 0, Green);
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)
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + StopLoss*Point,
Bid - TakeProfit*Point, "Fisher", 0, 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);
}
//----
for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY) // long position is opened
{
// check for trailing stop
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 for trailing stop
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);
}
//+------------------------------------------------------------------+ |
|