ผมแบคเทสก็ไม่เปิดออเดอ และ รันฟอเวิดเทสในเดโมก็ไม่เปิดออเดอ ช่วยดูให้ทีครับ
extern int TP = 850;
extern double Lots = 0.4;
extern int SL = 600;
int OpenOrders=0, cnt=0;
int slippage=2;
double sl=0;
double BuyPrice=0, SellPrice=0;
double lotsi=0, mylotsi=0;
int mode=0;
double BBU,BBL;
double M1,M2;
double cci42;
double RSi;
double EMA100,LMA5,LMA50;
double AO;
double AO_1;
double AC;
double AC_1;
double ADX;
double SAR;
double sto1_1,sto1_2,sto2_1,sto2_2,sto3_1,sto3_2,sto4_1,sto4_2;
double PClose,POpen,PHigh,PLow;
int ticket, order_Type;
datetime openTime, closeTime;
double orderSize, openPrice, closePrice, sf, tf, comm, swap, profit;
string order_Symbol, order_TypeToStr;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(MarketInfo("GURUSD",MODE_DIGITS)==5)
{
TP = TP*1;
SL = SL*1;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int handle;
for(int i=0;i<OrdersHistoryTotal();i++)
{
GetHistoryOrder(i,MODE_HISTORY);
if(order_Type==0)
order_TypeToStr="buy";
if(order_Type==1)
order_TypeToStr="sell";
handle=FileOpen("getOrderHistory.csv", FILE_CSV|FILE_READ|FILE_WRITE, ';');
if(handle>0)
{
if(FileSeek(handle,0,SEEK_SET)==true)
FileWrite(handle, "Order","Open Time","Type","Size","Symbol","Open Price","S/L","T/F","Close Time","Close Price","Comission","Swap","Profit");
FileSeek(handle, 0, SEEK_END);
//---- add data to the end of file
FileWrite(handle, ticket,TimeToStr(openTime,TIME_DATE|TIME_SECONDS),order_TypeToStr, orderSize, order_Symbol, openPrice, sf, tf, TimeToStr(closeTime,TIME_DATE|TIME_SECONDS), comm, swap, profit);
FileClose(handle);
handle=0;
}
}
OpenOrders=0;
for(cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol())
{
OpenOrders++;
}
}
M1 = iMACD(NULL,PERIOD_H1,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
M2 = iMACD(NULL,PERIOD_H1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
sto1_1 = iStochastic(NULL, PERIOD_H1, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
sto1_2 = iStochastic(NULL, PERIOD_H1, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
sto2_1 = iStochastic(NULL, PERIOD_M30, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
sto2_2 = iStochastic(NULL, PERIOD_M30, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
sto3_1 = iStochastic(NULL, PERIOD_M15, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
sto3_1 = iStochastic(NULL, PERIOD_M15, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
sto4_1 = iStochastic(NULL, PERIOD_M5, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
sto4_2 = iStochastic(NULL, PERIOD_M5, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
/*
cci42 = iCCI(NULL,0,35,PRICE_CLOSE,0);
RSi = iRSI(NULL,0,14,PRICE_CLOSE,0);
AO = iAO(NULL,30,0);
AO_1 = iAO(NULL,30,1);
AC = iAC(NULL,30,0);
AC_1 = iAC(NULL,30,1);
ADX = iCustom(NULL,0,"Advanced_ADX",0,0);
SAR = iSAR(NULL, 0, 0.02, 0.2, 0);
BBL = iBands(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 0);
BBU = iBands(NULL, 0, 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 0);
*/
PHigh = iHigh(NULL,0,0);
PLow = iLow(NULL,0,0);
PClose = iClose(NULL,0,1);
POpen = OrderOpenPrice();
/*
Comment (
"\nLots = ",Lots,
"\norderSize = ",orderSize,
"\nprofit = ",profit);
*/
if (OpenOrders<1)
{
{
if (AccountBalance()>=5000) Lots=0.5;
if (AccountBalance()>=10000) Lots=1;
if (AccountBalance()>=20000) Lots=2;
if (AccountBalance()>=30000) Lots=3;
if (AccountBalance()>=40000) Lots=4;
if (AccountBalance()>=50000) Lots=5;
}
if ((M1<M2)&&(sto1_1<sto1_2)&&(sto2_1<sto2_2)&&(sto3_1<sto3_2))
{
SellPrice=Bid;
if (SL==0) { sl=0; }
else { sl=SellPrice+SL*Point; }
if (profit>=0) {mylotsi = Lots;}
else {mylotsi = NormalizeDouble(orderSize*2,1);}
OrderSend(Symbol(),OP_SELLLIMIT,mylotsi,SellPrice,slippage,sl,0,NULL,0,0,Red);
return(0);
}
if ((M1>M2)&&(sto1_1>sto1_2)&&(sto2_1>sto2_2)&&(sto3_1>sto3_2))
{
BuyPrice=Ask;
if (SL==0) { sl=0; }
else { sl=BuyPrice-SL*Point; }
if (profit>=0) {mylotsi = Lots;}
else {mylotsi = NormalizeDouble(orderSize*2,1);}
OrderSend(Symbol(),OP_BUYLIMIT,mylotsi,BuyPrice,slippage,sl,0,NULL,0,0,Blue);
return(0);
}
}
//-------------------------------------Cut OrderClose-----------------------------
if(OpenOrders!=0 && PHigh-POpen>=TP*Point)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode=OrderType();
if (OrderSymbol()==Symbol())
{
if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Blue); }
}
}
}
if(OpenOrders!=0 && POpen-PLow>=TP*Point)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode=OrderType();
if (OrderSymbol()==Symbol())
{
if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red); }
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
void GetHistoryOrder(int count,int mode)
{
if(OrderSelect(count, SELECT_BY_POS, mode)==true)
{
ticket=OrderTicket();
order_Type=OrderType();
openTime=OrderOpenTime();
closeTime=OrderCloseTime();
orderSize=OrderLots();
openPrice=OrderOpenPrice();
closePrice=OrderClosePrice();
sf=OrderStopLoss();
tf=OrderTakeProfit();
comm=OrderCommission();
swap=OrderSwap();
profit=OrderProfit();
order_Symbol=OrderSymbol();
}
else
Print("OrderSelect returned the error of ",GetLastError());
}