Now saya cuba buat post hanya akan masuk jika TF chart kita sama dengan TF Chart Trend ... default adalah 60 = H1
//+------------------------------------------------------------------+
//| escape.mq4 |
//| Copyright © 2008, OGUZ BAYRAM |
//|
[email protected] |
//+------------------------------------------------------------------+
extern double Lots = 0.1;
extern double lTakeProfit = 5;
extern double sTakeProfit = 5;
extern double lTrailingStop = 20;
extern double sTrailingStop = 10;
extern double StopLoss=0;
color clOpenBuy = Blue;
color clCloseBuy = Aqua;
color clOpenSell = Red;
color clCloseSell = Violet;
color clModiBuy = Blue;
color clModiSell = Red;
string Name_Expert = "Kucing MA";
int Slippage = 1;
bool UseSound = false;
extern bool FractionalPips = true;
string NameFileSound = "Alert.wav";
extern int MagicNo=222222;
extern string StringEma="Setting For EMA And TF";
extern int TrendTF=60;
extern int EMA=5;
extern int EMA1=4;
void deinit() {
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start(){
if(Bars<100){
Print("bars less than 100");
return(0);
}
if (Digits==3 || Digits==5)
double diClose0=iClose(NULL,0,0);
double diMA1=iMA(NULL,0,EMA,0,MODE_SMA,PRICE_OPEN,0);
double diClose2=iClose(NULL,0,0);
double diMA3=iMA(NULL,0,EMA1,0,MODE_SMA,PRICE_OPEN,0);
//Trend TF =================================================================================
double diTrendClose0=iClose(NULL,TrendTF,0);
double diTrendMA1=iMA(NULL,TrendTF,EMA,0,MODE_SMA,PRICE_OPEN,0);
double diTrendClose2=iClose(NULL,TrendTF,0);
double diTrendMA3=iMA(NULL,TrendTF,EMA1,0,MODE_SMA,PRICE_OPEN,0);
if (!ExistPositions()){
if ((diClose0<diMA1) && (diTrendClose0<diTrendMA1) ){
OpenBuy();
return(0);
}
if ((diClose2>diMA3) && (diTrendClose2>diTrendMA3)){
OpenSell();
return(0);
}
}
TrailingPositionsBuy(lTrailingStop);
TrailingPositionsSell(sTrailingStop);
return (0);
}
bool ExistPositions() {
for (int i=10; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNo) {
return(True);
}
}
}
return(false);
}
void TrailingPositionsBuy(int trailingStop) {
for (int i=10; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNo) {
if (OrderType()==OP_BUY) {
if (Bid-OrderOpenPrice()>trailingStop*Point) {
if (OrderStopLoss()<Bid-trailingStop*Point)
ModifyStopLoss(Bid-trailingStop*Point);
}
}
}
}
}
}
void TrailingPositionsSell(int trailingStop) {
for (int i=10; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNo) {
if (OrderType()==OP_SELL) {
if (OrderOpenPrice()-Ask>trailingStop*Point) {
if (OrderStopLoss()>Ask+trailingStop*Point ||
OrderStopLoss()==0)
ModifyStopLoss(Ask+trailingStop*Point);
}
}
}
}
}
}
void ModifyStopLoss(double ldStopLoss) {
bool fm;
fm = OrderModify(OrderTicket(),OrderOpenPrice
(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
if (fm && UseSound) PlaySound(NameFileSound);
}
void OpenBuy() {
double ldLot, ldStop, ldTake;
string lsComm;
ldLot = GetSizeLot();
if(StopLoss>0)
ldStop = StopLoss;
else
ldStop=0;
ldTake = GetTakeProfitBuy();
lsComm = GetCommentForOrder();
OrderSend(Symbol
(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,0,0,clOpenBuy);
if (UseSound) PlaySound(NameFileSound);
}
void OpenSell() {
double ldLot, ldStop, ldTake;
string lsComm;
ldLot = GetSizeLot();
if(StopLoss>0)
ldStop = StopLoss;
else
ldStop=0;
ldTake = GetTakeProfitSell();
lsComm = GetCommentForOrder();
OrderSend(Symbol
(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,0,0,clOpenSell);
if (UseSound) PlaySound(NameFileSound);
}
string GetCommentForOrder() { return(Name_Expert); }
double GetSizeLot() { return(Lots); }
double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); }
double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }