BreakdownLevelDay EA 是一个由 Hlystov Vladimir 开发的外汇交易专家顾问(Expert Advisor),用于MetaTrader 4平台。该EA的设计目的是在每日市场收盘后根据特定的价格水平进行交易决策,以便在次日市场开盘时执行交易。
### 主要特性和功能
– **时间设置**:EA允许用户设置订单执行的具体时间,例如,如果TimeSet设置为“08:10”,EA将在每日的08:10执行交易。
– **价格移动**:EA根据High和Low价格以及预设的Delta值来确定交易的价格水平。例如,MaxPrice和MinPrice分别代表基于前一天的最高价和最低价加上或减去Delta值后的价格水平。
– **风险管理**:EA提供了Stop Loss(止损)和Take Profit(止盈)的设置,允许用户根据点数来管理风险。
– **固定手数**:如果Lot参数设置为非零值,EA将使用固定的交易手数进行交易。
– **突破事件**:EA可以配置为在价格突破前一天的最高价或最低价时执行交易。
– **追踪止损**:通过设置trailing参数,EA可以激活追踪止损功能,以保护盈利并减少潜在的亏损。
### 使用说明和注意事项
– **初始化和启动**:在初始化(init)函数中,EA会设置一些基本的参数,并检查是否有未完成的订单。启动(start)函数则是执行交易逻辑的核心部分。
– **订单执行**:EA会检查当前时间是否符合预设的交易时间,并根据市场情况发送买入或卖出限价订单。
– **删除和修改订单**:EA提供了删除所有止损订单(DelAllStop)和根据市场变动调整订单(TrailingStop)的功能。
– **代码注释**:EA的代码中包含了详细的注释,帮助用户理解各个函数和参数的作用。
### 结论
BreakdownLevelDay EA 是一个专注于每日市场收盘后价格水平突破的交易策略,它提供了一系列的风险管理工具和灵活的参数设置。用户在使用该EA时,应充分了解其工作原理,并在实盘交易前进行充分的测试。需要注意的是,尽管EA提供了多种设置和功能,但任何交易系统都无法保证盈利,且可能面临亏损的风险。
//+——————————————————————+
//| Daily Breakdown BreakdownLevelDay.mq4 |
//| Copyright ?2011, Hlystov Vladimir |
//| cmillion@narod.ru |
//+——————————————————————+
#property copyright “Copyright ?2011, http://cmillion.narod.ru”
#property link “cmillion@narod.ru”
//——————————————————————–
extern string TimeSet = “08:10”; //Order place time, if TimeSet = “00:00″, the EA works on the breakdown of the previous day.
extern int Delta = 6, //Order price shift (in points) from High/Low price
SL = 120, //Stop Loss (in points)
TP = 120, //Take Profit (in points)
risk = 200, //if 0, fixed lot is used
NoLoss = 0, //if 0, it doesn’t uses break-even
trailing = 30; //if 0, it doesn’t uses trailing
extern double Lot = 0.10; //used only if risk = 0
extern bool OpenStop = true; //Place stop orders if order is opened
extern color color_BAR = DarkBlue; //info color
//——————————————————————–
double MaxPrice,MinPrice;
int STOPLEVEL,magic=123321,tip,TimeBarbuy,TimeBarSell,LastDay;
//——————————————————————–
int init()
{
STOPLEVEL = MarketInfo(Symbol(),MODE_STOPLEVEL);
if (SL < STOPLEVEL) SL = STOPLEVEL;
if (TP < STOPLEVEL) TP = STOPLEVEL;
if (NoLoss < STOPLEVEL && NoLoss != 0) NoLoss = STOPLEVEL;
if (trailing < STOPLEVEL && trailing != 0) trailing = STOPLEVEL;
LastDay=0;
//if (TimeSet==”00:00”) LastDay=1;
return(0);
}
//——————————————————————–
int start()
{
MaxPrice=iHigh(NULL,PERIOD_D1,0)+NormalizeDouble(Delta*Point,Digits);
MinPrice=iLow(NULL,PERIOD_D1,0)-NormalizeDouble(Delta*Point,Digits);
Comment(“Copyright ?2011 cmillion@narod.ru\n BreakdownLevelDay input parameters”+”\n”+
“MaxPrice ” , MaxPrice, “\n”,
“MinPrice ” , MinPrice, “\n”,
“TimeSet ” , TimeSet, “\n”,
“Delta ” , Delta, “\n”,
“SL “, SL, “\n”,
“TP ” , TP, “\n”,
“Lot “, DoubleToStr(Lot,2),”\n”,
“risk “, risk, “\n”,
“NoLoss ” , NoLoss, “\n”,
“trailing “, trailing);
if (OpenStop) magic=TimeDay(CurTime());
if (!IsDemo()) {Comment(“Demo version, contact cmillion@narod.ru”);return;}
//—————————————————————–
int buy,sel,error;
bool BUY=false,SEL=false;
for (int i=0; i<OrdersTotal(); i++)
{ if (OrderSelect(i, SELECT_BY_POS)==true)
{
if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
tip=OrderType();
if (tip==0) BUY = true;
if (tip==1) SEL = true;
if (tip==4) buy++;
if (tip==5) sel++;
}
}
if ((BUY||SEL)&&(buy!=0||sel!=0)) DelAllStop(); // delete stop orders if order opened
if ( BUY||SEL)
{
if (trailing!=0) TrailingStop(trailing);
if (NoLoss!=0) No_Loss(NoLoss);
return; // opened order exist
}
if (TimeStr(CurTime())!=TimeSet) return; // if time isn’t equal to order set time
int expiration=CurTime()+(23-TimeHour(CurTime()))*3600+(60-TimeMinute(CurTime()))*60; //set order expiration time
double TrPr,StLo;
if (risk!=0) Lot = LOT();
if (buy<1&&TimeBarbuy!=TimeDay(CurTime()))
{
if (Ask+STOPLEVEL*Point>MaxPrice) MaxPrice = NormalizeDouble(Ask+STOPLEVEL*Point,Digits);
if (TP!=0) TrPr = NormalizeDouble(MaxPrice + TP * Point,Digits);
if (SL!=0) StLo = NormalizeDouble(MaxPrice – SL * Point,Digits);
error=OrderSend(Symbol(),OP_BUYSTOP ,Lot,MaxPrice,3,StLo,TrPr,”BUYSTOP BLD”,magic,expiration,Blue);
if (error==-1) Print(“Error BUYSTOP “,GetLastError(),” “,Symbol(),” Lot “,Lot,” Price “,MaxPrice,” SL “,StLo,” TP “,TrPr,” expiration “,expiration);
else TimeBarbuy=TimeDay(CurTime());
}
if (sel<1&&TimeBarSell!=TimeDay(CurTime()))
{
if (Bid-STOPLEVEL*Point<MinPrice) MinPrice = NormalizeDouble(Bid-STOPLEVEL*Point,Digits);
if (TP!=0) TrPr = NormalizeDouble(MinPrice – TP * Point,Digits);
if (SL!=0) StLo = NormalizeDouble(MinPrice + SL * Point,Digits);
error=OrderSend(Symbol(),OP_SELLSTOP,Lot,MinPrice,3,StLo,TrPr,”SELLSTOP BLD”,magic,expiration,Red );
if (error==-1) Print(“Error SELLSTOP “,GetLastError(),” “,Symbol(),” Lot “,Lot,” Price “,MinPrice,” SL “,StLo,” TP “,TrPr,” expiration “,expiration);
else TimeBarSell=TimeDay(CurTime());
}
if (buy<1&&sel<1)
{
ObjectDelete(“bar0”);
ObjectCreate(“bar0”, OBJ_RECTANGLE, 0, 0,0, 0,0);
ObjectSet (“bar0”, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet (“bar0”, OBJPROP_COLOR, color_BAR);
ObjectSet (“bar0”, OBJPROP_BACK, true);
ObjectSet (“bar0”, OBJPROP_TIME1 ,iTime( NULL, 1440, 0));
ObjectSet (“bar0”, OBJPROP_PRICE1,MaxPrice);
ObjectSet (“bar0”, OBJPROP_TIME2 ,CurTime());
ObjectSet (“bar0”, OBJPROP_PRICE2,MinPrice);
}
return(0);
}
//——————————————————————–
void DelAllStop()
{
int tip2;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol()!=Symbol()||OrderMagicNumber()!=magic) continue;
tip2=OrderType();
if (tip2==4||tip2==5) OrderDelete(OrderTicket());
}
}
}
//——————————————————————–
void TrailingStop(int trailing)
{
double StLo;
int tip2;
bool error;
//color col;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS)==true)
{
tip2 = OrderType();
if (tip2<2 && OrderSymbol()==Symbol())
{
if (OrderMagicNumber()!=magic) continue;
if (tip2==0) //Buy
{
StLo = Bid – trailing*Point;
if (StLo > OrderStopLoss() && StLo > OrderOpenPrice())
{error=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(StLo,Digits),OrderTakeProfit(),0,White);Comment(“Trailing “+OrderTicket());Sleep(500);}
}
if (tip2==1) //Sell
{
StLo = Ask + trailing*Point;
if (StLo < OrderStopLoss() && StLo < OrderOpenPrice())
{error=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(StLo,Digits),OrderTakeProfit(),0,White);Comment(“Trailing “+OrderTicket());Sleep(500);}
}
//if (error==false && SL!=0) Print(“Error SELLSTOP “,GetLastError(),” “,Symbol(),” SL “,StLo);
}//tip2<2
}//OrderSelect
}//for
}
//——————————————————————+
double LOT()
{
double MINLOT = MarketInfo(Symbol(),MODE_MINLOT);
double LOT = AccountFreeMargin()*risk/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED)/15;
if (LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT);
if (LOT<MINLOT) LOT = MINLOT;
if (MINLOT<0.1) LOT = NormalizeDouble(LOT,2); else LOT = NormalizeDouble(LOT,1);
return(LOT);
}
//——————————————————————+
void No_Loss(int NoLoss)
{
double StLo;
int tip2;
bool error;
//color col;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS)==true)
{
tip2 = OrderType();
if (tip2<2 && OrderSymbol()==Symbol())
{
if (OrderMagicNumber()!=magic) continue;
if (tip2==0) //Buy
{
if (OrderStopLoss()>=OrderOpenPrice()) return;
StLo = Bid – NoLoss*Point;
if (StLo > OrderStopLoss() && StLo > OrderOpenPrice())
{error=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(StLo,Digits),OrderTakeProfit(),0,White);Comment(“Trailing “+OrderTicket());Sleep(500);}
}
if (tip2==1) //Sell
{
if (OrderStopLoss()<=OrderOpenPrice()) return;
StLo = Ask + NoLoss*Point;
if (StLo < OrderStopLoss() && StLo < OrderOpenPrice())
{error=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(StLo,Digits),OrderTakeProfit(),0,White);Comment(“Trailing “+OrderTicket());Sleep(500);}
}
if (error==false && SL!=0) Print(“Error SELLSTOP “,GetLastError(),” “,Symbol(),” SL “,StLo);
}//tip<2
}//OrderSelect
}//for
}
//——————————————————————+
string TimeStr(int taim)
{
string sTaim;
int HH=TimeHour(taim); // Hour
int MM=TimeMinute(taim); // Minute
if (HH<10) sTaim = StringConcatenate(sTaim,”0″,DoubleToStr(HH,0));
else sTaim = StringConcatenate(sTaim,DoubleToStr(HH,0));
if (MM<10) sTaim = StringConcatenate(sTaim,”:0″,DoubleToStr(MM,0));
else sTaim = StringConcatenate(sTaim,”:”,DoubleToStr(MM,0));
return(sTaim);
}
//——————————————————————–
相关资源
暂无评论...