//+-----------------------------------------------------------------------+
//| ~~ tes trigger op stoch ~~.mq4 |
//| @tes trigger op stoch |
//| |
//+-----------------------------------------------------------------------+
#property copyright "@tes trigger op stoch"
/*-- Parameter ini ditampilkan di EA dan bisa diubah --*/
extern int TakeProfit = 10; // Nilai TP setiap OP di EA Martingale ini
extern int PipStep = 10; // Jarak pip dimana akan buka OP baru
extern int Slippage = 3; // Apa itu slippage ? Googling sendiri ya..
extern double Lots = 0.05; // Nilai lots awal, nantinya akan digandakan setiap step
extern double Multiply = 3.0; // Nilai pengali setiap step OP baru
extern int MaxTrade = 7; // Banyak OP maksimal yang boleh dijalankan
extern bool UseTime = TRUE; // Pilihan apakah memakai waktu bekerjanya EA ?
extern int HourStart = 24; // Waktu mulai EA bekerja
extern int HourEnd = 13; // Waktu akhir EA bekerja
/*-- Parameter ini tidak ditampilkan di EA --*/
string EAName = "~~tes trigger op stoch~~"; // Nama EA, untuk ditampilkan di layar
string EAComment = "~~tes trigger op stoch~~"; // Variabel ini akan kita masukkan di setiap OP sebagai Comment
int EAMagicNumber = 8095; // Magic Number
double SetPoint = 0; // Variabel SetPoint untuk kode digit broker 4 atau 5
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
SetBroker();
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int iTrade=0;
Comment(EAName); // Tampilkan Nama EA di layar
/* -- Jika tidak ada OP sama sekali, maka jalankan fungsi berikut --*/
/* -- Disinilah tempat anda memasukkan koding indikator untuk memicu OP --*/
if(OrdersTotal()==0)
{
if ((iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_MAIN,0) > iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_SIGNAL,0)))
{
/*-- Order Buy --*/
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, EAMagicNumber);
}
else if ((iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_MAIN,0) < iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_SIGNAL,0)))
{
/*-- Order Sell --*/
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, EAMagicNumber);
}
}
/* -- Inilah Fungsi Martingale. Jika ada OP yang salah, maka lakukan martingale --*/
if(OrdersTotal()>=1)
{
GoMartingale();
}
//----
return(0);
}
//+------------------------------------------------------------------+
/*--agar EA bisa running di Broker 4 Digit atau 5 Digit--*/
void SetBroker()
{
if (Digits==3 || Digits==5) // Perintah untuk broker 5 Digits
{SetPoint=Point*10;}
else // Perintah untuk broker 4 Digits
{SetPoint=Point;}
}void GoMartingale()
{
int iCount = 0;
double LastOP = 0;
double LastLots = 0;
bool LastIsBuy = FALSE;
int iTotalBuy = 0;
int iTotalSell = 0;
int Spread=0;
Spread= MarketInfo(Symbol(), MODE_SPREAD);
for(iCount=0;iCount<OrdersTotal();iCount++)
{
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP>OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=TRUE;
iTotalBuy++;
/* Bila mencapai batas OP maksimal, jangan tambah OP lagi */
if(iTotalBuy==MaxTrade) {return(0);}
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP<OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=FALSE;
iTotalSell++;
/* Bila mencapai batas OP maksimal, jangan tambah OP lagi */
if(iTotalBuy==MaxTrade) {return(0);}
}
}
/* Jika arah Price adalah DOWNTREND...., Periksa nilai Bid (*/
if(LastIsBuy)
{
if(Bid<=LastOP-(Spread*SetPoint)-(PipStep*SetPoint))
{
OrderSend(Symbol(), OP_BUY, Multiply*LastLots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, EAMagicNumber);
ModifyTP();
LastIsBuy=FALSE;
return(0);
}
}
/* Jika arah Price adalah Sell...., Periksa nilai Ask (*/
else if(!LastIsBuy)
{
if(Ask>=LastOP+(Spread*SetPoint)+(PipStep*SetPoint))
{
OrderSend(Symbol(), OP_SELL, Multiply*LastLots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, EAMagicNumber);
ModifyTP();
return(0);
}
}
}
/*-- Fungsi ModifyTP ini untuk mengubah semua OP agar TP di titik yang sama --*/
void ModifyTP()
{
int iCount=0;
double NewTP=0;
/*- Ambil nilai Take Profit dari Order terakhir -*/
for(iCount=0;iCount<OrdersTotal();iCount++)
{
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);
/*-- Kalau OP-nya adalah BUY, ambil nilai TP yang paling kecil. Jadikan TP bersama --*/
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(NewTP==0) {NewTP=OrderTakeProfit();}
if(NewTP>OrderTakeProfit()) {NewTP=OrderTakeProfit();}
}
/*-- Kalau OP-nya adalah SELL, ambil nilai TP yang paling besar. Jadikan TP bersama --*/
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(NewTP==0) {NewTP=OrderTakeProfit();}
if(NewTP<OrderTakeProfit()) {NewTP=OrderTakeProfit();}
}
}
/*- Ubah semua nilai OP TakeProfit dengan yang baru (2x lipat) -*/
for(iCount=0;iCount<OrdersTotal();iCount++)
{
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);
/*- Kalau semua OP adalah BUY, maka ubahlah TP mereka -*/
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}
/*- Kalau semua OP adalah SELL, maka ubahlah TP mereka -*/
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}
}
}
Jumat, 07 Desember 2012
Rabu, 05 Desember 2012
Penggunaan VTTS dalam MACD EA
Пример
Оригинальный код советника MACD_Sample выглядит так:
После внедрения VTTS_Full код становится таким:
Оригинальный код советника MACD_Sample выглядит так:
- [-]
- Код://+------------------------------------------------------------------+
//| MACD Sample.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
// to simplify the coding and speed up access
// data are put into internal variables
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// check for long position (BUY) possibility
if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// check for short position (SELL) possibility
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
// it is important to enter the market correctly,
// but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDCloseLevel*Point))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*Point))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
// the end.
После внедрения VTTS_Full код становится таким:
- [-]
- Код://+------------------------------------------------------------------+
//| MACD Sample.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#import "VTTS_Full_lib.ex4"
void init_VTTS_Full();
void deinit_VTTS_Full();
void start_VTTS_Full(bool Modify_Order_Prop_By_Lines);
#import
extern bool Modify_Order_Prop_By_Lines=true;
extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;
int init()
{
//----
init_VTTS_Full();
//----
return(0);
}
int deinit()
{
//----
deinit_VTTS_Full();
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
start_VTTS_Full(Modify_Order_Prop_By_Lines);
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
// to simplify the coding and speed up access
// data are put into internal variables
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// check for long position (BUY) possibility
if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// check for short position (SELL) possibility
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
// it is important to enter the market correctly,
// but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDCloseLevel*Point))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*Point))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
// the end.
VTTS ENSED
Добавление кода VTTS Full в свои советники
Для того, чтобы внести VTTS Full в свой советник нужно:
1) установить сам комплекс;
2) скачать
3) в верхнюю часть кода вставить следующий код:
4) в код, после "int init() {" вставить следующий код:
5) в код, после "int deinit() {" вставить следующий код:
6) в код, после "int start() {" вставить следующий код:
Для того, чтобы внести VTTS Full в свой советник нужно:
1) установить сам комплекс;
2) скачать
Вложение:
и скопировать её в experts/libraries внутри папки терминала (со следующей версии будет по умолчанию включена в установщик комплекса);3) в верхнюю часть кода вставить следующий код:
Код:
#import "VTTS_Full_lib.ex4"
void init_VTTS_Full();
void deinit_VTTS_Full();
void start_VTTS_Full(bool Modify_Order_Prop_By_Lines);
#import
extern bool Modify_Order_Prop_By_Lines=true;
void init_VTTS_Full();
void deinit_VTTS_Full();
void start_VTTS_Full(bool Modify_Order_Prop_By_Lines);
#import
extern bool Modify_Order_Prop_By_Lines=true;
4) в код, после "int init() {" вставить следующий код:
Код:
init_VTTS_Full();
чтобы получилось примерно так:Код:
int init()
{
//----
init_VTTS_Full();
...
{
//----
init_VTTS_Full();
...
5) в код, после "int deinit() {" вставить следующий код:
Код:
deinit_VTTS_Full();
чтобы получилось примерно так:Код:
int deinit()
{
//----
deinit_VTTS_Full();
...
{
//----
deinit_VTTS_Full();
...
6) в код, после "int start() {" вставить следующий код:
Код:
start_VTTS_Full();
чтобы получилось примерно так:Код:
int start()
{
//----
start_VTTS_Full();
...
{
//----
start_VTTS_Full();
...
Selasa, 27 November 2012
trade history
trade history
This is a simple example to demonstrate the usage of plotNewOpenTrades() and plotNewClosedTrades() that can be found in common_functions.mqh. MT4 will not automatically plot manual trades or trades resulting from pending orders into the chart, it only plots them when an EA sends a market order. However, we would like to see all trades in the chart and we don't want to drag them manually from the history into the chart, we would like this to happen automatically. #property indicator_chart_window#include <common_functions.mqh>int start(){ plotNewOpenTrades(); plotNewClosedTrades();}The above code is a complete indicator that when put onto a chart will plot all trades (historic and currently open) into the chart and it will not interfere with the normal mechanism of MT4 plotting trades. You will not end up with duplicate objects in the chart when you already dragged a trade from the history or an EA is already plotting trades. Additionally the description of the closing arrows, visible as tooltip when hovering the mouse above them, will show the resulting profit of the trade denominated in the account currency and in pips. You can use this code in your own EAs if they use pending orders to make all trades visible to the user. Below you can download a compiled version of the above code, ready to put into the indicators folder and to be used as indicator on your charts. https://sites.google.com/site/prof7bit/common_functions/trade_history |
Langganan:
Komentar (Atom)