//+--------------------------------------------------------------------------------+ //| | //| Copyright 2008, Yast77 | //| http://www.tradingsystemforex.com/ | //| http://forum.fxopen.com/showthread.php?t=39530 | //| http://cforum3.cari.com.my/viewthread.php?tid=1249423&extra=page%3D1&page=1 | //+--------------------------------------------------------------------------------+ //V1.1 Fixed open trade //V1.2 Fixed crash open order with other symbol #property copyright "Yast77" #property link "http://www.tradingsystemforex.com/" #include <stdlib.mqh> #include <stderror.mqh> extern bool TimeFilter = false; extern int HoursStart = 13; extern int HoursEnd = 7; extern int HoursClose = 7; extern int MinuteClose = 00; extern int TakeProfit =10; extern int StopLoss =200; extern bool MoneyMangement = false; extern double MaximumRisk = 0.1; extern bool MicroAccount = false; extern double Maxlot = 100; extern double FixLots=0.1; extern int Slippage =3; int tf=0; int Reference = 0; string EA_name = "Merdekarama V1.1 by Yast77"; string TradeComment; int lotPrecision; int total=0,ticket; //datetime Bar; bool permit=false; int cnt=0; static int prevtime = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD") Reference = 101001; if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY") Reference = 101002; if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD") Reference = 101003; if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD") Reference = 101004; if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY") Reference = 101005; if (Symbol() == "EURAUDm" || Symbol() == "EURAUD") Reference = 101006; if (Symbol() == "EURCADm" || Symbol() == "EURCAD") Reference = 101007; if (Symbol() == "EURCHFm" || Symbol() == "EURCHF") Reference = 101008; if (Symbol() == "EURGBPm" || Symbol() == "EURGBP") Reference = 101009; if (Symbol() == "EURJPYm" || Symbol() == "EURJPY") Reference = 101010; if (Symbol() == "EURUSDm" || Symbol() == "EURUSD") Reference = 101011; if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF") Reference = 101012; if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY") Reference = 101013; if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD") Reference = 101014; if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY") Reference = 101015; if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD") Reference = 101016; if (Symbol() == "USDCHFm" || Symbol() == "USDCHF") Reference = 101017; if (Symbol() == "USDJPYm" || Symbol() == "USDJPY") Reference = 101018; if (Symbol() == "USDCADm" || Symbol() == "USDCAD") Reference = 101019; if (Reference == 0) Reference = 101999; TradeComment = StringConcatenate(Symbol()," ",EA_name); CalculateLotPrecision(); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } void CalculateLotPrecision(){ double lotstep=MarketInfo(Symbol(),MODE_LOTSTEP); if(lotstep==1) lotPrecision=0; if(lotstep==0.1) lotPrecision=1; if(lotstep==0.01) lotPrecision=2; if(lotstep==0.001) lotPrecision=3; } double GetLots() { double lot; if(MoneyMangement) { lot=NormalizeDouble(AccountBalance()/10000,lotPrecision)*MaximumRisk; if(MicroAccount)lot=NormalizeDouble(lot/10,lotPrecision); if(lot>Maxlot)lot=Maxlot; } else { lot=FixLots; } return(lot); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- Comment("Yast77"); //----------------------- CHECK CHART NEED MORE THAN 100 BARS if(Bars<100) { Print("bars less than 100"); return(0); } //orderclose time for(cnt=0;cnt<OrdersTotal();cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==Reference) // check for symbol { total++; if(OrderType()==OP_BUY) // long position is opened { // should it be closed? if(TimeFilter) { if(Hour()== HoursClose && Minute()>MinuteClose) { OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue); // close position return(0); // exit } } } if(OrderType()==OP_SELL) // short position is opened { // should it be closed? if(TimeFilter) { if(Hour()== HoursClose && Minute()>MinuteClose) { OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red); // close position return(0); // exit } } } } } if(prevtime!=Time[0]) { //Bar=iTime(NULL,0,0); if(TimeFilter) { //Check Trading Hours permit=false; if(HoursStart<HoursEnd) if(Hour()>=HoursStart && Hour()<HoursEnd) permit=true; if(HoursStart>HoursEnd) { if(Hour()>=HoursStart) permit=true; if(Hour()>=0 && Hour()<HoursEnd) permit=true; } if(HoursStart==HoursEnd) permit=true; } else permit=true; // total=OrdersTotal(); if(total<1 && permit==true) { //open buy if(GetSignal()==1) { ticket=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,Slippage,Ask - (StopLoss * Point),Ask+TakeProfit*Point,TradeComment,Reference,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); prevtime=Time[0]; } else Print("Error opening BUY order : ",GetLastError()); return(0); } // open sell if(GetSignal()==-1) { ticket=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,Slippage,Bid + (StopLoss * Point),Bid-TakeProfit*Point,TradeComment,Reference,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); prevtime=Time[0]; } else Print("Error opening SELL order : ",GetLastError()); return(0); } } } ///---- return(0); } int GetSignal() { int TradeDirection =0; RefreshRates(); double value1a=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,0,0); double value1b=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,0,1); double value2a=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,1,0); double value2b=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,1,1); double value3a=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,2,1); double value3b=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,2,2); double value4a=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,3,1); double value4b=iCustom(Symbol(),tf,"TraderWawasan TE v2.0",3,2,1,0,0,3,2); double value5=iCustom(Symbol(),tf,"TraderWawasan MACD 2",false,60,5,8,9,0,1500,0,0,2,0); double value6=iCustom(Symbol(),tf,"TraderWawasan MACD 2",false,60,5,8,9,0,1500,0,0,3,0); double value7=iCustom(Symbol(),tf,"traderwawasan 4G1",240,0,0); double value8=iCustom(Symbol(),tf,"traderwawasan 4G1",240,1,0); /* Print("UpTrendEnv current= ",value1a); Print("UpTrendEnv prev= ",value1b); Print("DnTrendEnv current= ",value2a); Print("DnTrendEnv prev= ",value2b); Print("UpSignal prev= ",value3a); Print("UpSignal prev2= ",value3b); Print("DnSignal prev= ",value4a); Print("DnSignal prev2= ",value4b); Print("Macd up = ",value5); Print("Macd down = ",value6); Print("trader 4G1 down = ",value7); Print("trader 4G1 up = ",value8); */ //buy signal if(value8>0 && value5>0 && ((value1a<1000 && value3a<1000) || (value1a<1000 && value1b<1000 && value3b<1000))) { TradeDirection = 1; } if(value7>0 && value6<0 && ((value2a<1000 && value4a<1000) || (value2a<1000 && value2b<1000 && value4b<1000))) { TradeDirection = -1; } return(TradeDirection); }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
TraderWawasan TE v2.0
TraderWawasan MACD 2
traderwawasan 4G1
Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
It automatically opens orders when conditions are reached
Other Features: