//+——————————————————————+
//| Omen.mq4 |
//| |
//| Modified by Nax and updtaded by NAX |
//+——————————————————————+
#property copyright “Modified by Nax_NAX PC TECHNICIAN PTY Ltd”
#property link “NPT.GATES@GMAIL.COM”
#property version “2.3”
#property strict
enum tf
{M1,
M5,
M15,
M30,
H1,
H4,
D1,
W1,
MN1,
};
enum rule
{FollowTrend,
OppositeTrend,
};
input double Lot=0.01;
input int TP =300;
input int SL =300;
input int PercentRisk = 1.0;
input int MagicNumber = 205;
input int TrailingDistance =300;
input int Slippage = 3.0;
input int Xbar=5;
input tf TrendTf=M15;
input int FirstTrade=2;
input int WaitTrade=3;
input int MaxTrades=2;//Ongoing trades
input int TradeCount=3;
input rule TrendRule=FollowTrend;
extern int MaMetod = 2;
extern int MaPeriod = 3;
extern int MaMetod2 = 2;
extern int MaPeriod2 = 1;
int MaxSpreadAllowed = 0;
bool HiddenTrailing = false;
bool UseTrailing = False;
int TrailingPips = 10;
bool VisualTrailingLine = False;
int TrailingStep = 2;
int StartTrailingATProfit = 1;
bool HiddenLockPip = false;
extern bool LockPipsEnabled = true;
extern int LockPipsThreshold = 10;
extern int LockPips = 2;
int ticks[];
int dia=-1;
extern string MA1_Settings = ” ====MA#1 Settings====”;
extern bool UseSMAFilter = true;
ENUM_TIMEFRAMES MA1_TimeFrame = 0;
extern int MA1_Period = 15;
extern ENUM_MA_METHOD MA1_Method = 0;
extern ENUM_APPLIED_PRICE MA1_APrice = 0;
int MA1_Shift = 0;
extern string MA2_Settings = ” ====MA#2 Settings====”;
ENUM_TIMEFRAMES MA2_TimeFrame = 0;
extern int MA2_Period = 15;
extern ENUM_MA_METHOD MA2_Method = 0;
extern ENUM_APPLIED_PRICE MA2_APrice = 0;
int MA2_Shift = 0;
extern string MACD_Settings = “==== MACD Settings ==== “;
extern int MACD_FastEMA = 12;
extern int MACD_SlowEMA = 26;
extern int MACD_SignalPeriod = 9;
extern string ChannelSurfer_Settings = “==== ChannelSurfer Settings ==== “;
extern bool UseChannelSurfer_Fitler = 0;
extern int AllBars = 240;
extern int BarsForFract = 0;
extern string GATES911_Settings= “==== GATES911 Settings====”;
extern bool Use_GATES911 = true;
extern int Len = 7;
extern double Filter = 0;
extern int OverBoughtLine = 80;
extern int OverSoldLine = 20;
extern string General_Settings = “==== General Settings ====”;
extern string EAName = “ExpertAdvisor”;
extern bool DrawArrows = true;
bool DrawObjectWhenTheOrderGetsClosed = false;
bool EMailAlert = false;
extern bool PopUpAlert = true;
bool WriteLogs = true;
bool JournalLogs = true;
int SizeLabel = 20;
color Colour = DodgerBlue;
int PosX = 15;
int PosY = 420;
bool debug = true;
bool mod,sel,cl;
int tic,z;
ENUM_TIMEFRAMES tff=PERIOD_CURRENT;
string tfname;
static datetime Beg;
//+——————————————————————+
//| Expert initialization function |
//+——————————————————————+
int OnInit()
{if(TrendTf==M1){tff=PERIOD_M1;tfname=”M1″;}
if(TrendTf==M5){tff=PERIOD_M5;tfname=”M5″;}
if(TrendTf==M15){tff=PERIOD_M15;tfname=”M15″;}
if(TrendTf==M30){tff=PERIOD_M30;tfname=”M30″;}
if(TrendTf==H1){tff=PERIOD_H1;tfname=”H1″;}
if(TrendTf==H4){tff=PERIOD_H4;tfname=”H4″;}
if(TrendTf==D1){tff=PERIOD_D1;tfname=”D1″;}
if(TrendTf==W1){tff=PERIOD_W1;tfname=”W1″;}
if(TrendTf==MN1){tff=PERIOD_MN1;tfname=”MN1″;}
Beg=TimeCurrent();
//—
//—
return(INIT_SUCCEEDED);
}
//+——————————————————————+
//| Expert deinitialization function |
//+——————————————————————+
void OnDeinit(const int reason)
{
//—
}
//+——————————————————————+
//| Expert tick function |
//+——————————————————————+
void OnTick()
{
int totalhist=0;
datetime lastcl=0;
datetime clt=0;
for(z=OrdersHistoryTotal()-1;z>=0;z–)
{sel=OrderSelect(z,SELECT_BY_POS,MODE_HISTORY);
if((OrderType()==OP_SELL||OrderType()==OP_BUY)&&OrderSymbol()==Symbol()&&OrderOpenTime()>Beg)
{totalhist++;
}
}
int total=0;
bool newb=NewBar();
double distsl=0;
double disttp=0;
datetime last=0;
for(z=OrdersTotal()-1;z>=0;z–)
{sel=OrderSelect(z,SELECT_BY_POS);
if(OrderSymbol()==Symbol())
{if(OrderOpenTime()>last)
{
last=OrderOpenTime();
}
if(TrailingDistance!=0)Trailing();
if(OrderType()==OP_BUY)
{total++;
if(OrderStopLoss()!=0)distsl=Bid-OrderStopLoss();
if(OrderTakeProfit()!=0)disttp=OrderTakeProfit()-Bid;
}
if(TrailingDistance!=0)Trailing();
if(OrderType()==OP_BUY)
if(OrderType()==OP_SELL)
{total++;
if(OrderStopLoss()!=0)distsl=OrderStopLoss()-Ask;
if(OrderTakeProfit()!=0)disttp=Ask-OrderTakeProfit();
}
}
}
int distsl1=int(distsl/Point);
int disttp1=int(disttp/Point);
string name=TrendName();
string count;
if(MaxTrades-total==0)count=”No trade”;
else
{
count=string(MaxTrades-total);
}
string rulee;
if(TrendRule==OppositeTrend)
{rulee=”Opposite of trend”;
}
else
{
rulee=”Follow trend”;
}
Comment(“TakeProfit = “,TP,
“\n”,”TakeProfit = “,TP,
“\n”,”StopLoss = “,SL,
“\n”,”Distance to StopLoss = “,distsl1,
“\n”,”Distance to TakeProfit = “,disttp1,
“\n”,” Trend higher timeframe = “,tfname,
“\n”,” Waiting for trend = “,name,
“\n”,” First trade = “,FirstTrade,” min”,
“\n”,” Next trade = “,WaitTrade,” min”,
“\n”,” Number of ongoing trades : “,MaxTrades,
“\n”,” Trade Count : “,TradeCount,
“\n”,” Trading rule: “,rulee
);
if(total+totalhist>=TradeCount)return;
if(total==0&&(TimeCurrent()>Beg+FirstTrade*60||FirstTrade==0)
&&total<MaxTrades)
{OpenOrderF();
}
if(total!=0&&total<MaxTrades
&&(TimeCurrent()>clt+WaitTrade*60||WaitTrade==0))
{OpenOrder();
}
//—
}
//+——————————————————————+
string TrendName()
{int tr=Trend();
if(tr==1)return(“Long trend”);
else
{
if(tr==-1)return(“Short trend”);
else
{
return(“No trend”);
}
}
}
int Trend()
{int r=-2;
if(Xbar==0)return(0);
bool sell=true;
bool buy=true;
for(z=Xbar;z>=1;z–)
{double open1=iCustom(NULL,tff,”GATES911″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,10,z);
double close1=iCustom(NULL,tff,”SHI_SIGNAL”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,1,z);
double close3=iCustom(NULL,0,”Waddah_Attar_BUY_SELL_Vol”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
double close4=iCustom(NULL,0,”kg_ggh_signal_v1.1.2″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
double close5=iCustom(NULL,0,”HOLY GRAIL 1.6″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
if(close1>open1)
{sell=false;
}
if(close1<open1)
{buy=false;
}
}
if(buy)return(1);
if(sell)return(-1);
return(-2);
}
bool NewBar()
{
static datetime lastbar = 0;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else return(false);
}
int Signal()
{int r=0;
double open1=iCustom(NULL,0,”GATES911″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,10);
double open2=iCustom(NULL,0,”SHI_SIGNAL”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,0,2);
double open3=iCustom(NULL,0,”Waddah_Attar_BUY_SELL_Vol”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
double open4=iCustom(NULL,0,”kg_ggh_signal_v1.1.2″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
double open5=iCustom(NULL,0,”HOLY GRAIL 1.6″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
double close1=iCustom(NULL,0,”GATES911″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,10);
double close2=iCustom(NULL,0,”SHI_SIGNAL”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,1,2);
double close3=iCustom(NULL,0,”Waddah_Attar_BUY_SELL_Vol”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
double close4=iCustom(NULL,0,”kg_ggh_signal_v1.1.2″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
double close5=iCustom(NULL,0,”HOLY GRAIL 1.6″,MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,2);
int tr=Trend();
if(open2<close2&&open1>close1)
return(-1);
if(open2>close2&&open1<close1)
return(1);
return(r);
}
int SignalF()
{int r=0;
int tr=Trend();
if((((tr==0||tr==-1)&&TrendRule==FollowTrend)
||((tr==0||tr==1)&&TrendRule==OppositeTrend)))
return(-1);
if((((tr==0||tr==1)&&TrendRule==FollowTrend)
||((tr==0||tr==-1)&&TrendRule==OppositeTrend)))
return(1);
return(r);
}
void OpenOrder()
{int sign=Signal();
if(sign==1)
{BuyOrder();
}
if(sign==-1)
{SellOrder();
}
}
void OpenOrderF()
{int sign=SignalF();
if(sign==1)
{BuyOrder();
}
if(sign==-1)
{SellOrder();
}
}
void BuyOrder()
{double sl=SL*Point;
tic=OrderSend(NULL,OP_BUY,Lot,Ask,3,0,0);
sel=OrderSelect(tic,SELECT_BY_TICKET);
if(sl>0&&TP>0)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sl,OrderOpenPrice()+TP*Point,0);
else
{if(sl>0)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sl,OrderTakeProfit(),0);
if(TP>0)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+TP*Point,0);
}
}
void SellOrder()
{double sl=SL*Point;
tic=OrderSend(NULL,OP_SELL,Lot,Bid,3,0,0);
sel=OrderSelect(tic,SELECT_BY_TICKET);
if(sl>0&&TP>0)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sl,OrderOpenPrice()-TP*Point,0);
else
{if(sl>0)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sl,OrderTakeProfit(),0);
if(TP>0)
mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-TP*Point,0);
}
}
void Trailing()
{double bid=Bid;
double ask=Ask;
if(OrderType()==OP_BUY)
{if(//bid-OrderOpenPrice()>StartTrailing*Point&&
NormalizeDouble(bid-OrderStopLoss(),Digits)>NormalizeDouble(TrailingDistance*Point,Digits))
{mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(bid-TrailingDistance*Point,Digits),OrderTakeProfit(),0);
}
}
if(OrderType()==OP_SELL)
{if(//OrderOpenPrice()-ask>StartTrailing*Point&&
NormalizeDouble(OrderStopLoss()-ask,Digits)>NormalizeDouble(TrailingDistance*Point,Digits)||OrderStopLoss()==0)
{mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask+TrailingDistance*Point,Digits),OrderTakeProfit(),0);
}
}
}
相关资源
暂无评论...