//+------------------------------------------------------------------+
//| "PROJEK CUBA NAK JADI KAYA CEPAT" |
//| kopi rait hak ciplak terhuru-hara © 2010, ANAKANTU PISANG |
//+------------------------------------------------------------------+
//------------------
#property copyright "anakantu pisang"
#property link "musangpulutt"
//---- input parameters
extern double Lots = 0.50;
extern int SL = 40;
extern int TP = 60;
extern bool Sell = true;
extern bool Buy = true;
extern bool UseSound = True;
extern string NameFileSound = "rugi.wav";
extern bool ProfitTrailing = True;
extern int TrailingStop = 10;
extern int TrailingStep = 10;
int Slippage = 5;
// globals
string mySymbol, postfix;
// trade management
double ask, bid, point, SLBuy=0, SLSell=0, TPBuy=0, TPSell=0;
string TradeComment="Dah Langgaq Dah";
int MagicNumber = 123456781;
// used for verbose error logging
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() { return(0); }
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(ProfitTrailing)TrailingPositions();
Print("Init happened ",Hour()+":"+Minute());
Comment("Kais Pagi Makan Pagi!");
postfix = StringSubstr(Symbol(),6,1);
double CSopen = iOpen(NULL,0,0);
double CSclose = iClose(NULL,0,0);
double TL = NormalizeDouble(ObjectGetValueByShift("bawah",0) ,Digits);
if (ObjectFind ("bawah")==0)
{
if ( (CSopen>TL && TL>CSclose) || (CSopen<TL && TL<CSclose) )
{
ObjectDelete("atas");
ObjectDelete("bawah");
if (Sell==true)
{
TradeComment="Bawah - Sell";
PlaySound(NameFileSound);
Print("Init happened ",Hour()+":"+Minute());
Comment("Mari Sell EURO!");
mySymbol=Symbol()+postfix; OpenPos("Sell");
mySymbol=Symbol()+postfix; OpenPos("Sell");
}
}
}
{
postfix = StringSubstr(Symbol(),6,1);
double CSopen1 = iOpen(NULL,0,0);
double CSclose1 = iClose(NULL,0,0);
double TL1 = NormalizeDouble(ObjectGetValueByShift("atas",0) ,Digits);
{
if (ObjectFind ("atas")==0)
{
if ( (CSopen1>TL1 && TL1>CSclose1) || (CSopen1<TL1 && TL1<CSclose1) )
{
ObjectDelete("bawah");
ObjectDelete("atas");
if (Buy==true)
{
TradeComment="Atas - Buy";
PlaySound(NameFileSound);
Print("Init happened ",Hour()+":"+Minute());
Comment("Mari Buy EURO!");
mySymbol=Symbol()+postfix; OpenPos("Buy");
mySymbol=Symbol()+postfix; OpenPos("Buy");
}
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//ENTRY LONG (buy, Ask)
void OpenPos(string Trade)
{
int gle=0;
int ticket=0;
int loopcount;
loopcount=0;
while(true)
{
bid = MarketInfo(mySymbol,MODE_BID);
ask = MarketInfo(mySymbol,MODE_ASK);
point = MarketInfo(mySymbol,MODE_POINT);
if (SL>0) { SLBuy=bid-(SL*point); SLSell=ask+(SL*point); }
if (TP>0) { TPBuy=bid+(TP*point); TPSell=ask-(TP*point); }
// place order
if (Trade=="Buy") ticket=OrderSend(mySymbol,OP_BUY,Lots,ask,Slippage ,SLBuy,TPBuy,TradeComment,MagicNumber,White);
if (Trade=="Sell") ticket=OrderSend(mySymbol,OP_SELL,Lots,bid,Slippage,SLSell,TPSell,TradeComment,MagicNumber,Red);
gle=GetLastError();
if (gle==0)
{
if (Trade=="Buy") Print("BUY PLACED Ticket="+ticket+" Ask="+ask+" Lots="+Lots);
if (Trade=="Sell") Print("SELL PLACED Ticket="+ticket+" Bid="+bid+" Lots="+Lots);
break;
}
else
{
if (Trade=="Buy") Print("-----ERROR----- Placing BUY order: Lots="+Lots+" SL="+SL+" TP="+TP+" Bid="+bid+" Ask="+ask+" ticket="+ticket+" Err="+gle+" "+ErrorDescription(gle));
if (Trade=="Sell") Print("-----ERROR----- placing SELL order: Lots="+Lots+" SL="+SL+" TP="+TP+" Bid="+bid+" Ask="+ask+" ticket="+ticket+" Err="+gle+" "+ErrorDescription(gle));
RefreshRates();
Sleep(500);
// give up after 10 tries (~5 seconds)
loopcount++;
if (loopcount>10)
{
if (Trade=="Buy") Print("-----ERROR----- Giving up on placing BUY order");
if (Trade=="Sell") Print("-----ERROR----- Giving up on placing SELL order");
return (gle);
}
}
}
}
void TrailingPositions() {
double pBid, pAsk, pp;
pp = MarketInfo(OrderSymbol(), MODE_POINT);
if (OrderType()==OP_BUY) {
pBid = MarketInfo(OrderSymbol(), MODE_BID);
if (!ProfitTrailing || (pBid-OrderOpenPrice())>TrailingStop*pp) {
if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {
ModifyStopLoss(pBid-TrailingStop*pp);
return;
}
}
}
if (OrderType()==OP_SELL) {
pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
if (!ProfitTrailing || (OrderOpenPrice()-pAsk)>TrailingStop*pp) {
if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp) {
ModifyStopLoss(pAsk+TrailingStop*pp);
return;
}
}
}
}
void ModifyStopLoss(double ldStopLoss) {
bool fm;
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
}