[MT4-EA]EA
//+------------------------------------------------------------------+
//| BBQ_EA_V1.0.6 |
//| M5 EURUSD |
//| created by Monty666 2013-05-08 |
//+------------------------------------------------------------------+
//
#property copyright ""
#property link ""
#include
#include
//
//---- input parameters
extern string mm = "MoneyManagement";
extern double StopLoss = 33;
extern double TakeProfit = 120;
extern double Lots = 0.1;
extern bool UseMM = FALSE;
extern double PercentageMM = 10.0;
extern int SlipPage = 3;
extern double MaxSpread = 2.0;
extern int TrailingStop = 4;
extern int TrailingStep = 8;
extern int BreakEven = 3;
extern int movestopto = 2;
extern double Distance = 15;
extern int exp = 2600;
extern string deleteOrders = "delete pending after 5 minutes";
extern int DelOrders = 10;
extern string Timefilter = "Time shift between local and broker";
extern int ServerTimeZone = 0;
extern int TimeControl = 1;
extern int HourStartGMT = 9;
extern int HourStopGMT = 5;
extern string News = "Newsfilter";
extern bool AvoidNews = TRUE;
extern int MinimumImpact = 3;
extern int MinsBeforeNews = 60;
extern int MinsAfterNews = 30;
extern string Friday = "FridayFinalHour";
extern bool UseFridayFinalTradeTime = TRUE;
extern int FridayFinalHourGMT = 10;
extern string SignalSettings = "Signals";
extern int MA_Period = 99;
extern int Slippage_MA = 28;
extern int Williams_Period = 21;
extern int Level_High = 5;
extern int Level_Low = 95;
extern int ATR_Period = 18;
extern int Level_ATR_Stop = 4;
extern int CCI_Period = 16; //14
extern int Level_CCI_High = 90;
extern int Level_CCI_Low = -110;
// HMA
extern int MaMetod=2;
extern int MaPeriod=6;
extern int MaMetod2=3;
extern int MaPeriod2=2;
// Stoch
extern double First_Stoch_KP = 4;
// RSI
//extern string SignalRSI = "RSI settings";
//extern int rsitimeframe1=1;
//extern int rsiperiod1=6;
//extern int rsitimeframe2=5;
//extern int rsiperiod2=10;
//extern int rsitimeframe3=15;
//extern int rsiperiod3=20;
//extern int rsilevel1=92;
//extern int rsilevel2=128;
//extern int shift2=0;
// highlow
extern int PipsAdd = 4;
// macd
//extern double MACDOpenLevel = 3;
//extern double MACDCloseLevel = 2;
//extern double MATrendPeriod = 24;
extern string SignalClose = "Close settings";
extern int Close_Williams = 0;
extern int Williams_Close_Buy = 80;
extern int Williams_Close_Sell = 40;
extern int Only_Profit = 5;
extern int Close_CCI = 0;
extern int CCI_Close_Buy = 20;
extern int CCI_Close_Sell = -70;
extern int MagicNumber = 19777;
extern int MagicNumber2 = 18777;
extern int MagicNumber3 = 17771;
extern int MagicNumber4 = 16777;
extern string TradeComment = "BBQ";
double point;
int digits,i,D;
int BarCount;
int Current;
int bc=-1,tpb,tps,cnt,total;
int gi_240 = 0;
int gi_244 = 0;
int gi_224 = 0;
int gi_228 = 6;
int gi_328;
int g_error_332;
double g_price_336;
double g_price_344;
double g_price_352;
double gd_360;
double gd_368;
double g_iclose_376;
double g_iatr_384;
double g_iwpr_392;
double g_icci_400;
double g_ima_408;
int g_datetime_420;
// pivot
bool AsLongAs=true;
int ExtFormula=0;
datetime PreviousBarTime1;
datetime PreviousBarTime2;
datetime LastTradeTime = 0;
int ThisBarTrade = 0;
int bartime = 0;
//+------------------------------------------------------------------+
//| Time Filter |
//+------------------------------------------------------------------+
bool TradeSession() {
int Hour_Start_Trade;
int Hour_Stop_Trade;
Hour_Start_Trade = HourStartGMT + ServerTimeZone;
Hour_Stop_Trade = HourStopGMT + ServerTimeZone;
if (Hour_Start_Trade < 0)Hour_Start_Trade = Hour_Start_Trade + 24;
if (Hour_Start_Trade >= 24)Hour_Start_Trade = Hour_Start_Trade - 24;
if (Hour_Stop_Trade > 24)Hour_Stop_Trade = Hour_Stop_Trade - 24;
if (Hour_Stop_Trade <= 0)Hour_Stop_Trade = Hour_Stop_Trade + 24;
if ((UseFridayFinalTradeTime && (Hour()>=FridayFinalHourGMT + ServerTimeZone) && DayOfWeek()==5)||DayOfWeek()==0)return (FALSE); // Friday Control
if((TimeControl(Hour_Start_Trade,Hour_Stop_Trade)!=1 && TimeControl==1 && Hour_Start_TradeHour_Stop_Trade)
||TimeControl==0)return (TRUE); // "Trading Time";
return (FALSE); // "Non-Trading Time";
}
int TimeControl(int StartHour, int EndHour)
{
if (Hour()>=StartHour && Hour()< EndHour)
{
return(0);
}
return(1);
}
//+------------------------------------------------------------------+
//| Lots Sizes and Automatic Money Management |
//+------------------------------------------------------------------+
double GetLots()
{
if (UseMM)
{
double a, maxLot, minLot;
a = (PercentageMM * AccountFreeMargin() / 100000);
double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
maxLot = MarketInfo(Symbol(), MODE_MAXLOT );
minLot = MarketInfo(Symbol(), MODE_MINLOT );
a = MathFloor(a / LotStep) * LotStep;
if (a > maxLot) return(maxLot);
else if (a < minLot) return(minLot);
else return(a);
}
else return(Lots);
}
//+------------------------------------------------------------------+
//| close by signal |
//+------------------------------------------------------------------+
bool close_signal(int ai_0, double ad_4) {
if (ai_0 == 0) {
if (Close_Williams > 0 && (-1.0 * g_iwpr_392) < Williams_Close_Buy && Only_Profit < 0 || Bid > ad_4 + Only_Profit * gi_328 * Point) return (1);
if (Close_CCI > 0 && g_icci_400 > CCI_Close_Buy) return (1);
if (gi_224 > 0 && g_iatr_384 < gi_228 * gi_328 * Point) return (1);
if (gi_240 == 1 && iClose(NULL, 0, 1) < g_ima_408) return (1);
if (gi_244 == 1 && g_ima_408 < iMA(NULL, 0, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 2)) return (1);
}
if (ai_0 == 1) {
if (Close_Williams > 0 && (-1.0 * g_iwpr_392) > Williams_Close_Sell && Only_Profit < 0 || Ask < ad_4 - Only_Profit * gi_328 * Point) return (1);
if (Close_CCI > 0 && g_icci_400 < CCI_Close_Sell) return (1);
if (gi_224 > 0 && g_iatr_384 < gi_228 * gi_328 * Point) return (1);
if (gi_240 == 1 && iClose(NULL, 0, 1) > g_ima_408) return (1);
if (gi_244 == 1 && g_ima_408 > iMA(NULL, 0, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 2)) return (1);
}
return (0);
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//Calculate for 4 or 5 digits broker
if(Digits==5||Digits==3){ D=10;}
else{D=1;}
if(Digits<4)
{
point=0.01;
digits=2;
gi_328 = 10;
}
else
{
point=0.0001;
digits=4;
gi_328 = 1;
}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| MaxSpread |
//+------------------------------------------------------------------+
bool Mspread() {
double Spread = Ask-Bid;
if(Spread <= MaxSpread * point)return (TRUE);
return (FALSE);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, ticket2, ticket3, ticket4, total;
double SL,TP;
total=OrdersTotal();
int OpenedOrders=0;
//+------------------------------------------------------------------+
//| newsfilter |
//+------------------------------------------------------------------+
bool ContinueTrading=true;
if(AvoidNews && !IsTesting())
{
static int PrevMinute=-1;
int MinSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,0);
int MinToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,1);
int ImpactSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,0);
int ImpactToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,1);
if(Minute()!=PrevMinute)
{
PrevMinute=Minute();
if((MinToNews<=MinsBeforeNews && ImpactToNews>=MinimumImpact) || (MinSinceNews<=MinsAfterNews && ImpactSinceNews>=MinimumImpact))ContinueTrading=false;
}
}
//+------------------------------------------------------------------+
//| trailing |
//+------------------------------------------------------------------+
createlstoploss(StopLoss);
createltakeprofit(TakeProfit);
createsstoploss(StopLoss);
createstakeprofit(TakeProfit);
if(TrailingStop>0)MoveTrailingStop();
if(BreakEven>0)MoveBreakEven();
//+------------------------------------------------------------------+
//| signals |
//+------------------------------------------------------------------+
int sign1, sign2, sign3, sign4, sign5, sign6;
// wsr signals
g_iclose_376 = iClose(NULL, 0, 1);
g_ima_408 = iMA(NULL, 0, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 1);
g_iwpr_392 = iWPR(NULL, 0, Williams_Period, 1);
g_iatr_384 = iATR(NULL, 0, ATR_Period, 1);
g_icci_400 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, 1);
g_datetime_420 = iTime(Symbol(), 0, 0);
// buy
if (g_iclose_376 > g_ima_408 + Slippage_MA * gi_328 * point && g_iwpr_392 < (-1 * Level_Low) && g_icci_400 < Level_CCI_Low && g_iatr_384 > Level_ATR_Stop * gi_328 * point) sign1=1;
// sell
if (g_iclose_376 < g_ima_408 - Slippage_MA * gi_328 * point && g_iwpr_392 > (-1 * Level_High) && g_icci_400 > Level_CCI_High && g_iatr_384 > Level_ATR_Stop * gi_328 * point) sign1=-1;
// Pivot
int limit=1;
for(int i=1;i<=limit;i++)
{
double DPa=iCustom(Symbol(),0,"DailyPivot_Shift",ServerTimeZone,ExtFormula,0,i);
double DP=iCustom(Symbol(),0,"DailyPivot_Shift",ServerTimeZone,ExtFormula,0,0);
string BUY="false";
string SELL="false";
if((AsLongAs==false&&OpenDP)||(AsLongAs==true&&Open[0]>DP))BUY="true";
if((AsLongAs==false&&Open>DPa&&Open[0]80 && STOM2>80 && STOM3>80 && STOM4>80 && STOM5>80 && STOM6>80 && STOM7>80 && STOM8>80 && STOM9>80 && STOM10>80) sign3=1;
// HeikenAshi
double HA1a=iCustom(Symbol(),0,"Heiken Ashi MA",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,i+1);
double HA2a=iCustom(Symbol(),0,"Heiken Ashi MA",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,i+1);
double HA1=iCustom(Symbol(),0,"Heiken Ashi MA",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,i);
double HA2=iCustom(Symbol(),0,"Heiken Ashi MA",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,i);
string BUYh="false";
string SELLh="false";
if(HA2aHA1)BUYh="true";
if(HA2a>HA1a&&HA2rsilevel2) sign5=-1;
*/
// highlow
GlobalVariableSet("uplevel", High[1] + PipsAdd*point);
GlobalVariableSet("dnlevel", Low[1] - PipsAdd*point);
/*
// macd
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious(MACDOpenLevel*point) && MaCurrent>MaPrevious && sign5==1) sign4=1;
if(MacdCurrent>0 && MacdCurrentSignalPrevious &&
MacdCurrent>(MACDOpenLevel*point) && MaCurrent Level_ATR_Stop * gi_328 * point)
{
Buy2="true";
Buy3Check="false";
}
if (SELLh=="true" && sign3==-1 && sign5==-1 && sign2==-1 && sign2==-1 && g_iatr_384 > Level_ATR_Stop * gi_328 * point)
{
Sell2="true";
Sell3Check="false";
}
*/
// stoporders
if (BUYh=="true" && Bid>=GlobalVariableGet("uplevel") && bartime != Time[0] && sign2==1 && g_iatr_384 > Level_ATR_Stop * gi_328 * point)
{
Buy3="true";
Buy4Check="false";
}
if (SELLh=="true" && Bid<=GlobalVariableGet("dnlevel") && bartime != Time[0] && sign2==-1 && g_iatr_384 > Level_ATR_Stop * gi_328 * point)
{
Sell3="true";
Sell4Check="false";
}
//+------------------------------------------------------------------+
//| count open orders |
//+------------------------------------------------------------------+
int totalo;
totalo=0;
for(int io=0;ioMinutes_2delete*60 || Buy1=="true") && OrderType()==OP_BUYSTOP)
{
OrderDelete(OrderTicket());
}
else
if((TimeCurrent()-OrderOpenTime()>Minutes_2delete*60 || Sell1=="true") && OrderType()==OP_SELLSTOP)
{
OrderDelete( OrderTicket() );
}
}
}
//+------------------------------------------------------------------+
//| open orders |
//+------------------------------------------------------------------+
//
double MyAsk = Ask + Distance*point;
double MyBid = Bid - Distance*point;
double MyAsk2 = Ask + Distance*point;
double MyBid2 = Bid - Distance*point;
if (ThisBarTrade != Bars) {
// wsfr indis standardorder ////////////////////////
// buyorder
if (TradeSession() && ContinueTrading && Mspread() && totalo<1 && Buy1=="true")
{
ThisBarTrade = Bars;
ticket=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,SlipPage,0,0,TradeComment,MagicNumber,0,Green);
LastTradeTime = LocalTime();
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
// Sellorder
if (TradeSession() && ContinueTrading && Mspread() && totalo<1 && Sell1=="true")
{
ThisBarTrade = Bars;
ticket=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,SlipPage,0,0,TradeComment,MagicNumber,0,Red);
LastTradeTime = LocalTime();
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
/*
// rsi stoch standardorder ////////////////////////
// buyorder
if (TradeSession() && ContinueTrading && Mspread() && totalo<1 && totalo2<1 && totalo3<1 && Buy2=="true" && Buy2Check=="true")
{
ThisBarTrade = Bars;
ticket2=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,SlipPage,0,0,TradeComment,MagicNumber2,0,Green);
LastTradeTime = LocalTime();
if(ticket2<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
// Sellorder
if (TradeSession() && ContinueTrading && Mspread() && totalo<1 && totalo2<1 && totalo3<1 && Sell2=="true" && Sell2Check=="true")
{
ThisBarTrade = Bars;
ticket2=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,SlipPage,0,0,TradeComment,MagicNumber2,0,Red);
LastTradeTime = LocalTime();
if(ticket2<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
*/
// highlow stoporder ////////////////////////
// buy stoporder
if (Buy3=="true" && totalp<1 && TradeSession() && ContinueTrading && Mspread())
{
ThisBarTrade = Bars;
ticket3 = OrderSend(Symbol(), OP_BUYSTOP, GetLots(), MyAsk, SlipPage, 0, 0, TradeComment, MagicNumber3, expire, Lime);
LastTradeTime = LocalTime();
Sleep(10000);
RefreshRates();
if(ticket3<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
// Sell stoporder
if (Sell3=="true" && totalp<1 && TradeSession() && ContinueTrading && Mspread())
{
ThisBarTrade = Bars;
ticket3 = OrderSend(Symbol(), OP_SELLSTOP, GetLots(), MyBid, SlipPage, 0, 0, TradeComment, MagicNumber3, expire, Orange);
LastTradeTime = LocalTime();
Sleep(10000);
RefreshRates();
if(ticket3<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
/*
// macd stoporder ////////////////////////
// buy stoporder
if (sign4==1 && sign2==1 && totalp<1 && totalo<1 && totalo2<1 && totalo3<1 && totalo4<1 && Buy2Check=="true" && Buy4Check=="true" && TradeSession() && ContinueTrading && Mspread())
{
ThisBarTrade = Bars;
ticket4 = OrderSend(Symbol(), OP_BUYSTOP, GetLots(), MyAsk2, SlipPage, 0, 0, TradeComment, MagicNumber4, expire, Lime);
LastTradeTime = LocalTime();
Sleep(10000);
RefreshRates();
if(ticket4<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
// Sell stoporder
if (sign4==-1 && sign2==-1 && totalp<1 && totalo<1 && totalo2<1 && totalo3<1 && totalo4<1 && Sell2Check=="true" && Sell4Check=="true" && TradeSession() && ContinueTrading && Mspread())
{
ThisBarTrade = Bars;
ticket4 = OrderSend(Symbol(), OP_SELLSTOP, GetLots(), MyBid2, SlipPage, 0, 0, TradeComment, MagicNumber4, expire, Orange);
LastTradeTime = LocalTime();
Sleep(10000);
RefreshRates();
if(ticket4<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
*/
}
//+------------------------------------------------------------------+
//| open orders end |
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| trailing functions 1 |
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
int cnt,total=OrdersTotal();
for(cnt=0; cnt0&&NormalizeDouble(Ask-TrailingStep*point,digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*point,digits))
{
if((NormalizeDouble(OrderStopLoss(),digits)0&&NormalizeDouble(Bid+TrailingStep*point,digits)(NormalizeDouble(Ask+TrailingStop*point,digits)))||(OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*point,digits),OrderTakeProfit(),0,Red);
}
}
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//| breakeven 1 |
//+------------------------------------------------------------------+
void MoveBreakEven()
{
int cnt,total=OrdersTotal();
for(cnt=0; cnt0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),digits)>BreakEven*point)
{
if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+movestopto*point,digits),OrderTakeProfit(),0,Blue);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),digits)>BreakEven*point)
{
if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-movestopto*point,digits),OrderTakeProfit(),0,Red);
}
}
}
}
}
}
}
return(0);
}
// add TP & SL
void createlstoploss(double StopLoss){
RefreshRates();
for(int i=0;i
发表于:2014-04-05 16:04只看该作者
2楼
下次记得贴代码的时候 上code符号
遇到矛盾 先站在对方的立场上想想问题,先试着去理解别人
● 如何使用WinMTR查询平台连接流畅度
发表于:2016-06-14 15:16只看该作者
3楼
这是个什么类型的EA
韬客社区www.talkfx.co
发表于:2016-07-18 11:41只看该作者
4楼
多谢分享
韬客社区www.talkfx.co
发表于:2022-09-10 03:20只看该作者
5楼
多谢分享