ما هو هذا السورس ياشباب
كود://+------------------------------------------------------------------+
//| !ObjectGet_EA.mq4 |
//| Copyright © 2011, Daengrani |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//---- includes
//#include <debug.mqh>
#include <WinUser32.mqh>
#include <LibOrderReliable.mqh>
extern string Set1_________ = "====== main_setting =======";
extern int JarakPips = 5;
extern int TakeProfit = 120;
extern int StopLoss = 120;
extern int magic = 9999;
extern int maxspread = 5;
extern double slippage = 3.0;
extern string Set2_________ = "====== lot_management =====";
extern double Lots = 0.1; // basic lot
extern bool Dynamic_Lots = false; //TRUE jika ingin EA mengatur Lot berdasar RiskPercent
extern double LotPercent = 10.0; //Persentase Lot dari Free Margin
extern int lotsdigit = 1; //untuk Broker dgn minimal Lot = 0.01
extern bool Martingale = true; // false to deactivated this feature
extern double Multiplier = 1.1; // previous lotsize will multiplied
extern int DeepLevel = 10; // how many continue losses
extern string Set3_________ = "======= Time Filter =======";
extern bool Trade1 = TRUE; //time filter untuk hari minggu
extern bool Trade2 = TRUE; //time filter untuk hari senin s/d kamis
extern int StartHour2 = 0; //start hour untuk hari senin s/d kamis
extern int EndHour2 = 24; //end hour untuk hari senin s/d kamis
extern bool Trade3 = TRUE; //time filter untuk hari jumat
extern int StartHour3 = 0; //start hour untuk hari jumat
extern int EndHour3 = 23; //end hour untuk hari jumat
extern bool close_all = TRUE; //close all order setelah non-aktif trading (termasuk pending order)
extern int CloseMinute = 1; //end hour untuk hari jumat
//<< Global Variables >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
string gs_148;
string gs_156;
double gd_176;
string gs_comment_120 = "!ObjectGet_EA";
double pips2points, // slippage 3 pips 3=points 30=points
pips2dbl; // Stoploss 15 pips 0.0015 0.00150
int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips)
double dGaris,
stoplevel,
spread,
dAsk,
dBid;
//<< End >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//+==================================================================+
//| expert initialization function |
//+==================================================================+
int init() {
if (Digits == 3 || Digits == 5){ // Adjust for five (5) digit brokers.
pips2dbl = Point*10; pips2points = 10; Digits.pips = 1;
} else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; }
// OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
return (0);
}
//+==================================================================+
//| expert deinitialization function |
//+==================================================================+
int deinit() {
Comment("");
return (0);
}
//+==================================================================+
//| expert start function |
//+==================================================================+
int start() {
//////////////////////////////////////////////////////////////
// membatasi User dengan Expired Date
string expire_date = "2020.09.30"; //<-- hard coded datetime
datetime e_d = StrToTime(expire_date);
if (CurTime() >= e_d)
{
Alert ("Versi Trial/Gratis udah expired Bos!");
return(0);
}
//////////////////////////////////////////////////////////////
if (IsTradeAllowed() == FALSE) return (0);
if (!IsTradeTime())
{
if (close_all && Minute() >= CloseMinute)
CloseAll();
CloseAll();
CloseAll();
return(0);
}
//<<< risk management >>>>>>>>>>>>
if (Dynamic_Lots)LotCalculate();
//<<< Indicators & MarketInfo >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
dGaris = NormalizeDouble(ObjectGet("Garis",1),Digits);
stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL)*Point;
spread = MarketInfo(Symbol(), MODE_SPREAD)*Point;
dAsk = NormalizeDouble(MarketInfo(Symbol(), MODE_ASK), Digits);
dBid = NormalizeDouble(MarketInfo(Symbol(), MODE_BID), Digits);
InfoLayar();
//<<< Counting Order >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// ini untuk menghitung Order
int i_ord_total = OrdersTotal();
int i_count = 0;
int i_countB = 0;
int i_countS = 0;
for (int i_pos = 0; i_pos < i_ord_total; i_pos++) {
OrderSelect(i_pos, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
if (OrderMagicNumber() == magic) {
i_count++;
if (OrderType() == OP_BUY||OrderType() == OP_BUYSTOP||OrderType() == OP_BUYLIMIT) i_countB++;
if (OrderType() == OP_SELL||OrderType() == OP_SELLSTOP||OrderType() == OP_SELLLIMIT) i_countS++;
}
}
}
//<<< Open & Close Order >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (i_countB == 0 && spread <= maxspread*pips2points)
{
if (ObjectFind("Garis")!=-1)
{
if (Close[1] > dGaris)
{
OrderSendReliableMKT(Symbol(), OP_BUY, mylot(), dAsk, slippage * pips2points,
dBid-StopLoss*pips2dbl, dAsk+TakeProfit*pips2dbl, gs_comment_120, magic, 0 , DodgerBlue);
}
}
}
if (i_countS == 0 && spread <= maxspread*pips2points)
{
if (ObjectFind("Garis")!=-1)
{
if (Close[1] < dGaris)
{
OrderSendReliableMKT(Symbol(), OP_SELL, mylot(), dBid, slippage * pips2points,
dAsk+StopLoss*pips2dbl, dBid-TakeProfit*pips2dbl, gs_comment_120,magic,0,Pink);
}
}
}
// OrderSendReliable2Step digunakan agar bisa trade di ECN
return (0);
}
void InfoLayar()
{
///////////////////////////////////////////////////////////////////////////
Comment("");
komentar (1, ":::::::::::::::::::::::::::::::::::::::","");
komentar (2, "T I M E", TimeToStr(CurTime(),TIME_DATE|TIME_MINUTES));
komentar (3, "NAMA", AccountName());
komentar (4, "No. ACC", AccountNumber());
komentar (5, "BROKER", AccountCompany());
komentar (6, "LEVERAGE", "1:"+DoubleToStr(AccountLeverage(),0));
komentar (7, "BALANCE", DoubleToStr (AccountBalance(),2));
komentar (8, "EQUITY", DoubleToStr (AccountEquity(),2));
komentar (9, "MAGIC", DoubleToStr (magic,0));
komentar (10, ":::::::::::::::::::::::::::::::::::::::","");
komentar (11, "Spread", DoubleToStr(spread/Point,1));
komentar (12, "StopLevel", DoubleToStr(stoplevel/Point,1));
komentar (13, "Trend", gs_148);
komentar (14, "Action", gs_156);
komentar (15, ":::::::::::::::::::::::::::::::::::::::","");
///////////////////////////////////////////////////////////////////////////
return;
}
//<<< Trailing Stop >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Di bawah ini adalah fungsi untuk Trailing Stop berdasarkan Bands dari indicator Envelope
//<<< Check For Losses >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool checkforlosses() // we check our last closed order
{ // from losses here
int losses=0; // total of losses
int i; // pos of our order
for(i=0; i<OrdersHistoryTotal(); i++) // looping to check all of our
{ // order history from pos 0 until
// last pos
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); // is it right our order?
if(OrderSymbol()!=Symbol() || // if symbol of order didn't match
OrderMagicNumber()!=magic) // with current chart symbol
continue; // or the magic numb of order
// didn't match with our magic
// number, it is not our's, just don't check it
if(OrderProfit()<0) losses++; // so we count it as a losses 'cause negative profit
else losses=0; // otherwise we leave it as is
}
if(losses>0) return(true); // if last of our order is in losses
// true "value" will returned from this function
return(false); // when there is no losses false will returned
}
//<<< Last Lot >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
double lastlot() // we will find last lot size
{ // order with this function
double lot=0; // lot size
int i; // pos of our order
for(i=0; i<OrdersHistoryTotal(); i++) // looping to check all of our
{ // order history from pos 0 until
// last pos
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); // is it right our order?
if(OrderSymbol()!=Symbol() || // if symbol of order didn't match
OrderMagicNumber()!=magic) // with current chart symbol
continue; // or the magic numb of order
// didn't match with our magic
// number, it is not our's
lot=OrderLots(); // last lot
}
return(lot); // last lot size returned
}
//<<< Martingale Function >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
double mylot() // we calculate for next lot here
{ // when a loss occured or not
int prec=0; // precision value
double lot, // lot size
minlot, // minimal size of lot
maxlot, // maximal size of lot
maxlotX; // maximal size of martingale lot
minlot=MarketInfo(Symbol(),MODE_MINLOT); // get brokers minimal lot size
maxlot=MarketInfo(Symbol(),MODE_MAXLOT); // get brokers maximal lot size
if(lotsdigit == 2) prec=2; // get precision value
if(lotsdigit == 1) prec=1; // get precision value
maxlotX=NormalizeDouble(Lots*MathPow(Multiplier,DeepLevel), prec); //get max.
// martingale lotsize
/////////////////////////////////////////////////////////////////////////////
if(Martingale) // if martingale activated
{
if(checkforlosses()) // if last order is in losses
{
lot=NormalizeDouble(lastlot()*Multiplier,prec); // martingale lot
}
else
{
lot=Lots; // normal lot
}
}
else
{
lot=Lots; // normal lot
}
////////////////////////////////////////////////////////////////////
if(lot>maxlot) return(Lots); // if lot size is bigger than broker rules,
// we change it into StartLot value
if(lot>maxlotX) return(Lots); // if lot size is bigger than martingale level,
// we change it into StartLot value
if(lot<minlot) return(minlot); // if lot size smaller than minlot, we change
// into monlot value
return(lot); // lot size returned
}
////////////////////////////////////////////////////////////////////
void LotCalculate()
{
double MinLots=MarketInfo(Symbol(),MODE_MINLOT);
double MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);
Lots=AccountEquity()/100000*LotPercent;
Lots=MathMin(MaxLots,MathMax(MinLots,Lots));
if(lotsdigit == 2)Lots=NormalizeDouble(Lots,2);
else
{
if(lotsdigit == 1)Lots=NormalizeDouble(Lots,1);
else Lots=NormalizeDouble(Lots,0);
}
if(Lots<MinLots)Lots=MinLots;
if(Lots>MaxLots)Lots=MaxLots;
return(0);
}
//<<< Time Filter >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool IsTradeTime() {
if((Trade1==false && DayOfWeek()==0) ||
(Trade2 && DayOfWeek()>=1 && DayOfWeek()<=4 &&
!(Hour()>=StartHour2 && Hour()<EndHour2)) ||
(Trade3 && DayOfWeek()==5 &&
!(Hour()>=StartHour3 && Hour()<EndHour3)))
return(FALSE);
else
return(TRUE);
}
//<<< Close All Trades >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void CloseAll()
{
int total = OrdersTotal();
bool do_again = false;
for(int i=total-1; !do_again && i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderCloseReliableMKT( OrderTicket(), OrderLots(), dBid, slippage * pips2points, DodgerBlue );
do_again = true;
break;
//Close opened short positions
case OP_SELL : result = OrderCloseReliableMKT( OrderTicket(), OrderLots(), dAsk, slippage * pips2points, Pink );
do_again = true;
break;
//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT :
case OP_SELLSTOP : result = OrderDeleteReliable( OrderTicket() );
do_again = true;
break;
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
return(0);
}
//<<< Comment >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void komentar (int baris, string label1, string label2)
{
if (!IsTradeAllowed() || !IsExpertEnabled()) {ObjectDelete("baris0"); return (0);}
int x,y;
switch(baris)
{
case 1: x=15; y= 60; break;
case 2: x=15; y= 75; break;
case 3: x=15; y= 90; break;
case 4: x=15; y=105; break;
case 5: x=15; y=120; break;
case 6: x=15; y=135; break;
case 7: x=15; y=150; break;
case 8: x=15; y=165; break;
case 9: x=15; y=180; break;
case 10: x=15; y=195; break;
case 11: x=15; y=210; break;
case 12: x=15; y=225; break;
case 13: x=15; y=240; break;
case 14: x=15; y=255; break;
case 15: x=15; y=270; break;
case 16: x=15; y=285; break;
case 17: x=15; y=300; break;
case 18: x= 15; y=315; break;
}
Monitor("baris0", WindowExpertName()+ " IS RUNNING", 9, 15, 35, Aqua,1);
Monitor("baris00", "Modified by [email protected] (>_<)", 12, 20, 10, Aqua,3);
Monitor("baris"+baris, label1, 8, x, y, Aqua,1);
Monitor("baris_"+baris, ":", 8, x+70, y, Aqua,1);
Monitor("baris-"+baris, label2, 8, x+80, y, Aqua,1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Monitor(string nama, string isi, int ukuran, int x, int y, color warna, int pojok)
{
if (ObjectFind(nama)<0) {ObjectCreate (nama,OBJ_LABEL,0,0,0,0,0);}
ObjectSet (nama,OBJPROP_CORNER,pojok);
ObjectSet (nama,OBJPROP_XDISTANCE,x);
ObjectSet (nama,OBJPROP_YDISTANCE,y);
ObjectSetText (nama,isi,ukuran,"Tahoma",warna);
}
////////////////////////////////////////////////////*****|||*****\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

