WeeklyBreakout EA
WeeklyBreakout EA

WeeklyBreakout EA

更新日期:
1970-01-01
分类标签:
语言:
中文
平台:
没限制

7KB338 人已下载 手机查看

WeeklyBreakout EAWeeklyBreakout EA

#property copyright “TradeMater , www.forex-trade-master.com”
#property link “http://www.forex-trade-master.com/”

extern int startDay=2; // Tuesday
extern int startTime=0; // GMT time
extern int endpendingDay=2;
extern int endpendingTime=23;
extern int endDay=5; // Close all orders at the end of Friday
extern int endTime=19;
extern int stopLoss=100;
extern double takeProfit=100;
extern int trailingStop=0; //trailing stop
int TS_Step=1; //trailing step
extern double lots=0.1;
extern bool MM=false; //money management
extern double Risk=10; //risk in percentage
extern int breakEven=0;
extern int magicNumber=2007411;
//+——————————————————————+
//| expert initialization function |
//+——————————————————————+
int init()
{
//—-

//—-
return(0);
}
//+——————————————————————+
//| expert deinitialization function |
//+——————————————————————+
int deinit()
{
//—-

//—-
return(0);
}
//+——————————————————————+
//| expert start function |
//+——————————————————————+
int start()
{
//—-
// expert money management
if(MM){if(Risk<0.1||Risk>100){Comment(“Invalid Risk Value.”);return(0);}
else{lots=MathFloor((AccountFreeMargin()*AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);}}
if(MM==false){lots=lots;}

if(DayOfWeek()==startDay && TimeCurrent() > StrToTime(startTime+”:00″)&& TimeCurrent()< StrToTime(startTime+”:10″)){
if(currentOrders_By_Type(OP_BUYSTOP)==0) // Send BuyStop order
{
double buyPrice = NormalizeDouble(Ask + 50*Point,Digits);
double buyStopPrice = NormalizeDouble(buyPrice – stopLoss*Point,Digits);
OrderSend(Symbol(),OP_BUYSTOP,lots,buyPrice,3,buyStopPrice,buyPrice+takeProfit*Point,”weekly breakout 1.0″,magicNumber,0,Green);
}
if(currentOrders_By_Type(OP_SELLSTOP)==0){
double sellPrice = NormalizeDouble(Bid – 50*Point,Digits);
double sellStopPrice = NormalizeDouble(sellPrice + stopLoss*Point,Digits);
OrderSend(Symbol(),OP_SELLSTOP,lots,sellPrice,3,sellStopPrice,sellPrice-takeProfit*Point,”weekly breakout 1.0″,magicNumber,0,Yellow);
}
}
if(breakEven > 0) moveToBreakeven();
MoveTrailingStopsPerMN(magicNumber);
if(DayOfWeek()==endDay && TimeCurrent()>=StrToTime(endTime+”:00″)&& TimeCurrent()<=StrToTime(endTime+”:10″)) {
closeAll();
}

if(DayOfWeek()==endpendingDay && TimeCurrent()>=StrToTime(endpendingTime+”:00″)&& TimeCurrent()<=StrToTime(endpendingTime+”:10″)){
DeleteBuyStop();DeleteSellStop();
}

//—-
return(0);
}
//+——————————————————————+

int currentOrders_By_Type(int type){
int cur_orders = 0;

for(int i=0;i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicNumber && OrderType()==type){
cur_orders++;
}
}
return(cur_orders);
}

void DeleteBuyStop(){
for (int i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && (OrderMagicNumber() == magicNumber) && (OrderType()==OP_BUYSTOP)) {
OrderDelete(OrderTicket());
}
}
}

void DeleteSellStop(){
for (int i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && (OrderMagicNumber() == magicNumber) && (OrderType()==OP_SELLSTOP)) {
OrderDelete(OrderTicket());
}
}
}

void closeAll(){
for(int i=0; i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol() == Symbol() && OrderMagicNumber() == magicNumber){
if(OrderType()==OP_BUY){
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
}
else if(OrderType()==OP_SELL) {
OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
}
else{
OrderDelete(OrderTicket());
}
}
}//end for
}// end closeAll

void moveToBreakeven(){
for(int i=0;i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicNumber){
if(OrderType()==OP_BUY) {
if(breakEven > 0 && Bid-OrderOpenPrice()> breakEven*Point && OrderOpenPrice()!= OrderStopLoss()){
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Orange);
}
}//end buy
if(OrderType()==OP_SELL){
if(breakEven > 0 && OrderOpenPrice()-Ask>breakEven*Point && OrderOpenPrice()!= OrderStopLoss()){
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Orange);
}
}//end sell
}
}//end for
}

void MoveTrailingStopsPerMN(int iMN){
string symbol = Symbol();int icnt, itotal;itotal=OrdersTotal();
for(icnt=0;icnt<itotal;icnt++){
OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_SELL && OrderSymbol()==symbol && OrderMagicNumber()==iMN){
if(OrderStopLoss()==0){
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trailingStop,OrderTakeProfit(),0,Red);
}
if((OrderOpenPrice()-Ask)>(Point*trailingStop)){
if(OrderStopLoss()>(Ask+Point*trailingStop+TS_Step-1)){
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trailingStop,OrderTakeProfit(),0,Red);
}
}
}
if(OrderType()==OP_BUY && OrderSymbol()==symbol && OrderMagicNumber()==iMN){
if(OrderStopLoss()==0){
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*trailingStop,OrderTakeProfit(),0,Green);
}
if(Bid-OrderOpenPrice()>Point*trailingStop){
if(OrderStopLoss()<Bid-Point*trailingStop+TS_Step-1){
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*trailingStop,OrderTakeProfit(),0,Green);
}
}
}
}

}

 

如果你对文件有了解,请帮助投票!

If you are familiar with the file, please help vote!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位投票人。

相关资源

暂无评论

none
暂无评论...