//+------------------------------------------------------------------+
//| EA belajar.mq4 |
//| Mastemon |
//| facebook.com/zahrul.falah |
//+------------------------------------------------------------------+
#property copyright "Mastemon"
#property link "facebook.com/zahrul.falah"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| External Parameter |
//+------------------------------------------------------------------+
extern double Lots =0.01;
extern int TakeProfit =30;
extern int StopLoss =30;
extern int MagicNumber =5394;
//+------------------------------------------------------------------+
//| Internal Parameter |
//+------------------------------------------------------------------+
double lot =2;
string Comment ="Testing";
double slb,tpb,sls,tps,pt;
int res,dpo;
int ticket;
double bs1,bs2,ss1,ss2;
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
//Cek Digit Broker
int init()
{
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
return(0);
}
// fungsi order
// op buy
void Buy()
{
ticket=OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb,tpb,Comment,MagicNumber,0,Blue);
}
// po buystop
void bs1()
{ticket=OrderSend(Symbol(),OP_BUYSTOP,NR(Lots)*1,OrderOpenPrice()+7*pt,3,StopLoss==0,TakeProfit==0,Comment,MagicNumber,0,Blue);}
void bs2()
{ticket=OrderSend(Symbol(),OP_BUYSTOP,NR(Lots)*2,OrderOpenPrice()+20*pt,3,StopLoss==0,TakeProfit==0,Comment,MagicNumber,0,Blue);}
void BuyStop()
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,xlot(),OrderOpenPrice()+20*pt,3,StopLoss==0,TakeProfit==0,Comment,MagicNumber,0,Blue);
}
// op sell
void Sell()
{
ticket=OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls,tps,Comment,MagicNumber,0,Red);
}
// po sell stop
void ss1()
{ticket=OrderSend(Symbol(),OP_SELLSTOP,NR(Lots)*1,OrderOpenPrice()-10*pt,3,StopLoss==0,TakeProfit==0,Comment,MagicNumber,0,Red);}
void ss2()
{ticket=OrderSend(Symbol(),OP_SELLSTOP,NR(Lots)*2,OrderOpenPrice()-23*pt,3,StopLoss==0,TakeProfit==0,Comment,MagicNumber,0,Red);}
void SellStop()
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,xlot(),OrderOpenPrice()-23*pt,3,StopLoss==0,TakeProfit==0,Comment,MagicNumber,0,Red);
}
//Oeder Filter
int jumlahorder( int tipe)
{
int total=0;
for(int i=0;i<OrdersTotal();i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))continue;
if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber||OrderType()!=tipe) continue;
total++;
}
return(total);
}
//Lots Filter
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep*NormalizeDouble(thelot/lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
//double lots
double xlot()
{
double ylot,dlot;
for (int i=0;i<OrdersHistoryTotal();i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
if(OrderSymbol()!=Symbol() || OrderComment()!=Comment)continue;
}
dlot=OrderLots();
ylot=NR(dlot*lot);
return(ylot);
}
//delete po
void del()
{for(int i=OrdersTotal()-1;i>=0;i--)
{if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol()) continue;
if(OrderType()>1){res=OrderDelete(OrderTicket());}
}
}