int Slippage=3;
int Retries=10;
bool AutoTrade=true;
bool ecnBroker=false;
//bool errororder = true;
input int MagicID=12345786;
input double LOTS=0.01;
input int risk=0;//risk: 0-->fixed lots
input double SL=500;
input double TP=50;
extern bool Trailing = true;
extern double TrailingStop =10.0;
extern double TrailingStep =10.0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
union Price
{
uchar buffer[8];
double close;
};
double data[][2];
int BytesToRead;
string datapath;
string result;
Price m_price;
double g_Point;
int ticket=0;
string account_server;
double Buy, lotbuy, lotsbuy, Sell, lotsell, lotssell, SUM, SWAP,
profitbuy, profitsell, OP, dg,
sumbuy, sumsell, bepbuy, bepsell, lowlotbuy, lowlotsell, hisell,
lobuy;
//datetime expDate=D'2029.10.12 02:00';//yyyy.mm.dd
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(!IsDllsAllowed())
{
Alert("Make Sure DLL Import is Allowed");
ExpertRemove();
return(INIT_FAILED);
}
//------------------------------------------------------
//---
{
g_Point=Point;
if(Digits==5 || Digits==3)
{
g_Point *= 10;
Slippage*=10;
TrailingStop *=10;
TrailingStep *=10;
}
else
if(Digits==4)
{
g_Point *= 100;
Slippage*=100;
}
ChartSetInteger(0,17,0,0);
ChartSetInteger(0,0,1);
account_server=AccountInfoString(3);
if(account_server=="")
{
account_server="default";
}
/*datapath=TerminalInfoString(3)+"\\history\\"
+account_server+"\\"+Symbol()+"240"+".hst";
ReadFileHst(datapath);*/
//---
return(INIT_SUCCEEDED);
}
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll();
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Minute() == 0)
{
datapath=TerminalInfoString(3)+"\\history\\"
+account_server+"\\"+Symbol()+"240"+".hst";
ReadFileHst(datapath);
}
//----------------------------Tampilan EA-----------------------------------------------//
ObjectCreate(0,"MENU",OBJ_RECTANGLE_LABEL,0,0,0);
ObjectSetInteger(0,"MENU",OBJPROP_XSIZE,275);
ObjectSetInteger(0,"MENU",OBJPROP_YSIZE,325);
ObjectSetInteger(0,"MENU",OBJPROP_COLOR,Silver);
ObjectSetInteger(0,"MENU",OBJPROP_XDISTANCE,100);
ObjectSetInteger(0,"MENU",OBJPROP_YDISTANCE,10);
ObjectSetInteger(0,"MENU",OBJPROP_BGCOLOR,C'40,40,40');
ObjectSetInteger(0,"MENU",OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,"MENU",OBJPROP_WIDTH, 1);
ObjectSetInteger(0,"MENU",OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0,"MENU",OBJPROP_BACK, False);
// Close All
ObjectCreate(0,"CL",OBJ_BUTTON,0,0,0);
ObjectSetInteger(0,"CL",OBJPROP_XSIZE,225);
ObjectSetInteger(0,"CL",OBJPROP_YSIZE,25);
ObjectSetInteger(0,"CL",OBJPROP_BORDER_COLOR,Silver);
ObjectSetInteger(0,"CL",OBJPROP_XDISTANCE,123);
ObjectSetInteger(0,"CL",OBJPROP_YDISTANCE,300);
ObjectSetString(0,"CL",OBJPROP_TEXT,"Close ALL");
ObjectSetInteger(0,"CL",OBJPROP_BGCOLOR,Blue);
ObjectSetString(0,"CL",OBJPROP_FONT,"Arial Black");
ObjectSetInteger(0,"CL",OBJPROP_FONTSIZE,9);
ObjectSetInteger(0,"CL",OBJPROP_COLOR,White);
Display_Info();
double SetPoint=g_Point;
static datetime previousBar;
if(previousBar!=Time[0])
{
previousBar=Time[0];
ChartRedraw();
}
else
{
return;
}
if(iVolume(Symbol(),PERIOD_H4,0)>iVolume(Symbol(),PERIOD_H4,1))
return;
//**********************************
if(!BytesToRead>0)
return;
int pos = -1 ;
for(int i = 0 ; i < BytesToRead - 1 ; i++)
{
if(!(data[i][0]<Time[0]))
break;
pos = i + 1;
}
//********************************
HideTestIndicators(True);
double wpr= iWPR(Symbol(),0,4,0);
double ao = iAO(Symbol(),0,0);
HideTestIndicators(false);
double level=NormalizeDouble(data[pos][1],Digits);
ObjectDelete("level");
MakeLine(level);
if(data[pos][1]>Open[0])
Comment("BUY - ", data[pos][1]);
if(data[pos][1]<Open[0])
Comment("SELL - ", data[pos][1]);
if(MarketInfo(Symbol(),MODE_SPREAD)>40)
return;
if(pos>0)
{
if(CheckMarketBuyOrders()<70 && CheckMarketSellOrders()<70)
{
if(data[pos][1]>Open[0])
if(IsBuyPinbar())
{
//if(wpr<-80)
//if(ao<0)
double BuySL=NormalizeDouble(Ask - SL*g_Point,Digits);
double BuyTP=NormalizeDouble(Ask + TP*g_Point,Digits);
if(AccountFreeMarginCheck(Symbol(),OP_BUY,GetLots())>0)
{
ticket=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,Slippage,BuySL,BuyTP,"",MagicID,0,clrGreen);
{
ModifyTP(0,rata_price(0)+TP*g_Point);
}
CloseSell();
}
}
if(data[pos][1]<Open[0])
if(IsSellPinbar())
{
//if(wpr>-20)
//if(ao>0)
double SellSL=NormalizeDouble(Bid + SL*g_Point,Digits);
double SellTP=NormalizeDouble(Bid - TP*g_Point,Digits);
if(AccountFreeMarginCheck(Symbol(),OP_SELL,GetLots())>0)
{
ticket=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,Slippage,SellSL,SellTP,"",MagicID,0,clrGreen);
{
ModifyTP(1,rata_price(1)-TP*g_Point);
}
CloseBuy();
}
}
Trailing();
}
}
return;
}
//==============================
void Trailing()
{
for(int i=OrdersTotal() -1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicID)
{
if(OrderType() == OP_BUY)
{
if(Bid - OrderOpenPrice() > TrailingStop * Point || OrderStopLoss() == 0)
{
if(OrderStopLoss() < Bid-(TrailingStop + TrailingStep) * Point || OrderStopLoss() == 0)
{
if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop * Point, Digits),0,0))
Print("Ошибка модификации ордера на покупку");
}
}
}
if(OrderType() == OP_SELL)
{
if(OrderOpenPrice() - Ask > TrailingStop * Point || OrderStopLoss() == 0)
{
if(OrderStopLoss() > Ask + (TrailingStep + TrailingStop) * Point || OrderStopLoss() == 0)
{
if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStop * Point, Digits),0,0))
Print("Ошибка модификации ордера на продажу");
}
}
}
}
}
}
}