谁来帮忙解读一下策略进出原则,我看到有点头胀。
This line is for some reason very important. you'd better settle all your account at the end of day.*****
/*if (TimeHour(CurTime())==23 && MathAbs(faMiddle-faHighest)MathAbs(faMiddle-faLowest) )
{
CloseSellPositions();
return(0);
}
*/
//System Stoploss based on LongTerm Moving Average (Fibo 55 day MA)
//StopLoss For Buy Positions (Optional)
if ((maLongCurrent>closeCurrentD) && (maLongPreviousclosePreviousD))
{
CloseSellPositions();
return(0);
}
// Check for invalid bars and takeprofit
if(Bars 0)
realSL = Ask - stopLoss * Point;
if(takeProfit > 0)
realTP = Ask + takeProfit * Point;
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,realSL,realTP,nameEA+" - Magic: "+magicEA+" ",magicEA,0,Red); // Buy
if(ticket " + ErrorDescription(GetLastError()));
}
else
{
}
}
if(isSelling && !isBuying && !isBuyClosing && !isSellClosing)
{ // Check for SELL entry signal
if(stopLoss > 0)
realSL = Bid + stopLoss * Point;
if(takeProfit > 0)
realTP = Bid - takeProfit * Point;
ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,realSL,realTP,nameEA+" - Magic: "+magicEA+" ",magicEA,0,Red); // Sell
if(ticket " + ErrorDescription(GetLastError()));
}
else
{
}
}
return(0);
*/
calculateIndicators(); // Calculate indicators' value
//Check for TakeProfit Conditions
if(lTakeProfitfaMA1 && faBandWidthfaMA1))
{
OpenBuy();
//if (OrdersTotal()==1 && (faClose2faMA1)) {OpenBuy();}
//if (OrdersTotal()==2 && (faClose0>faMA1)) {OpenBuy();}
//if (OrdersTotal()==3 && (faClose0>faMA1)) {OpenBuy();}
return(0);
}
//Close Buy Condition
/* if ((faClose2300) && (sarCurrent600) && (sarCurrent900) && (sarCurrent1200) && (sarCurrent1500) && (sarCurrent1800) && (sarCurrent2100) && (sarCurrent2400) && (sarCurrent2700) && (sarCurrent3000) && (sarCurrent3300) && (sarCurrent3600) && (sarCurrent3900) && (sarCurrent4200) && (sarCurrent4500) && (sarCurrent4800) && (sarCurrent5100) && (sarCurrent5400) && (sarCurrent5700) && (sarCurrentcloseCurrent)
{
if ((CurTime()-OrderOpenTime()>300) && (sarCurrent>highCurrent)) {j=1;}
if ((CurTime()-OrderOpenTime()>600) && (sarCurrent>highCurrent)) {j=2;}
if ((CurTime()-OrderOpenTime()>900) && (sarCurrent>highCurrent)) {j=3;}
if ((CurTime()-OrderOpenTime()>1200) && (sarCurrent>highCurrent)) {j=4;}
if ((CurTime()-OrderOpenTime()>1500) && (sarCurrent>highCurrent)) {j=5;}
if ((CurTime()-OrderOpenTime()>1800) && (sarCurrent>highCurrent)) {j=6;}
if ((CurTime()-OrderOpenTime()>2100) && (sarCurrent>highCurrent)) {j=7;}
if ((CurTime()-OrderOpenTime()>2400) && (sarCurrent>highCurrent)) {j=8;}
if ((CurTime()-OrderOpenTime()>2700) && (sarCurrent>highCurrent)) {j=9;}
if ((CurTime()-OrderOpenTime()>3000) && (sarCurrent>highCurrent)) {j=10;}
if ((CurTime()-OrderOpenTime()>3300) && (sarCurrent>highCurrent)) {j=11;}
if ((CurTime()-OrderOpenTime()>3600) && (sarCurrent>highCurrent)) {j=12;}
if ((CurTime()-OrderOpenTime()>3900) && (sarCurrent>highCurrent)) {j=13;}
if ((CurTime()-OrderOpenTime()>4200) && (sarCurrent>highCurrent)) {j=14;}
if ((CurTime()-OrderOpenTime()>4500) && (sarCurrent>highCurrent)) {j=15;}
if ((CurTime()-OrderOpenTime()>4800) && (sarCurrent>highCurrent)) {j=16;}
if ((CurTime()-OrderOpenTime()>5100) && (sarCurrent>highCurrent)) {j=17;}
if ((CurTime()-OrderOpenTime()>5400) && (sarCurrent>highCurrent)) {j=18;}
if ((CurTime()-OrderOpenTime()>5700) && (sarCurrent>highCurrent)) {j=19;}
for(int i=j; itrailingStop*Point)
{
if (OrderStopLoss()[B]trailingStop*Point)
{
if (OrderStopLoss()>Ask+trailingStop*Point ||
OrderStopLoss()==0)
ModifyStopLoss(Ask+trailingStop*Point);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ModifyStopLoss(double ldStopLoss)
{
bool fm;
fm=OrderModify(OrderTicket(),OrderOpenPrice
(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenBuy()
{
double ldLot, ldStop, ldTake;
string lsComm;
ldLot=GetSizeLot();
ldStop=0;
ldTake=GetTakeProfitBuy();
lsComm=GetCommentForOrder();
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,ldStop,ldTake,nameEA,magicEA,0,clOpenBuy);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenSell()
{
double ldLot, ldStop, ldTake;
string lsComm;
//----
ldLot=GetSizeLot();
ldStop=0;
ldTake=GetTakeProfitSell();
lsComm=GetCommentForOrder();
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,ldStop,ldTake,nameEA,magicEA,0,clOpenSell);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetCommentForOrder() { return(nameEA); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetSizeLot() { return(Lots); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void calculateIndicators()
{
// Calculate indicators' value
macdHistCurrent =iMACD(NULL,0,12,26,9,PRICE_OPEN,MODE_MAIN,0);
macdHistPrevious =iMACD(NULL,0,12,26,9,PRICE_OPEN,MODE_MAIN,1);
macdSignalCurrent =iMACD(NULL,0,12,26,9,PRICE_OPEN,MODE_SIGNAL,0);
macdSignalPrevious =iMACD(NULL,0,12,26,9,PRICE_OPEN,MODE_SIGNAL,1);
stochHistCurrent =iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);
stochHistPrevious =iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
stochSignalCurrent =iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
stochSignalPrevious=iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1);
sarCurrent =iSAR(NULL,0,0.009,0.2,0); // Parabolic Sar Current
sarPrevious =iSAR(NULL,0,0.009,0.2,1); //Parabolic Sar Previous
momCurrent =iMomentum(NULL,0,14,PRICE_OPEN,0); // Momentum Current
momPrevious =iMomentum(NULL,0,14,PRICE_OPEN,1); // Momentum Previous
highCurrent =iHigh(NULL,0,0); //High price Current
lowCurrent =iLow(NULL,0,0); //Low Price Current
closeCurrent =iClose(NULL,PERIOD_H4,0); //Close Price Current for H4 TimeFrame
closeCurrentD =iClose(NULL,PERIOD_D1,0); //Close Price Current for D1 TimeFrame
closePreviousD =iClose(NULL,PERIOD_D1,1); //Close Price Previous for D1 TimeFrame
maLongCurrent =iMA(NULL,PERIOD_D1,55,1,MODE_SMMA,PRICE_TYPICAL,0); //Current Long Term Moving Average
maLongPrevious =iMA(NULL,PERIOD_D1,55,1,MODE_SMMA,PRICE_TYPICAL,1); //Previous Long Term Moving Average
maShortCurrent =iMA(NULL,0,2,1,MODE_SMMA,PRICE_TYPICAL,0); //Current Short Term Moving Average
maShortPrevious =iMA(NULL,0,2,1,MODE_SMMA,PRICE_TYPICAL,1); //Previous Long Term Moving Average
faRSICurrent =iRSI(NULL,0,14,PRICE_TYPICAL,0); //Current RSI
// Check for BUY, SELL, and CLOSE signal
isBuying =false;
isSelling=false;
isBuyClosing=false;
isSellClosing=false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseBuyPositions()
{
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==magicEA)
{
if (OrderType()==OP_BUY) OrderClose(OrderTicket(),Lots,Bid,Slippage);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseSellPositions()
{
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==magicEA)
{
if (OrderType()==OP_SELL) OrderClose(OrderTicket(),Lots,Ask,Slippage |