ขอคำชี้แนะจากท่านด้วยครับ แก้ไม่ได้จริงๆ ครับ บัญชีไมโคร เปิดด้วยมือ 0.01 เปิดได้แต่พอให้อีเอเปิด ไม่ได้ครับขึ้น error 131
ลองเช็คค่า MODE_MINLOT แล้วก็ได้ 0.01 แก้ไม่ถูกจริง ๆ ครับ ท่านช่วยดูโค๊ดนี้ให้ผมหน่อยนะครับ ขอขอบคุณล่วงหน้ามากมากครับท่าน
//+------------------------------------------------------------------+
//| LD.MQ4 |
//| Copyright 2019 MetaQuotes Software Corp. |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright Gaothun 2019."
extern string EA_Name = "";
extern int MagicNumber = 111;
extern int TakeProfit = 999;
extern int Step_Order = 100;
extern double Lots = 0.01;
extern double Step_Lots = 1.5;
extern bool Enable_TargetDollar = True;
extern double TargetDollar = 1;
extern bool Enable_SL_Dollar = False;
extern int SL_Dollar = 999;
extern int XDISTANCE = 950;
int OpenOrders=0, cnt=0;
int mode=0, myOrderType=0;
int slippage=5, LastType=0;
int Stoploss = 0;
double mylotsi=0;
double sl=0, tp=0;
double BuyPrice=0, SellPrice=0;
double LastPriceBuy, LastPriceSell;
double LastPriceBuyLimit;
double LastPriceSellLimit;
double LastPrice=0;
double LastLots, LastLotsBuy, LastLotsSell;
double Profit, Points;
bool ContinueOpening=True;
double NewPoint=Point();
double B_LotPrice= 0;
double B_Average = 0;
double S_LotPrice= 0;
double S_Average = 0;
double B_Lot, S_Lot;
double TPB, TPS;
int B_bar,Bar ;
int CountB, CountS;
int CountBuyLimit, CountSellLimit;
int result, ticket;
bool res,tic;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//----
//----
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//---------------
//---------------
OpenOrders = 0;
LastType = 0;
LastPriceSell = 0;
LastPriceBuy = 0;
LastLotsBuy = 0;
LastLotsSell = 0;
LastLots = 0;
Profit = 0;
CountB = 0;
CountS = 0;
NewPoint = Point();
B_LotPrice = 0;
B_Average = 0;
S_LotPrice = 0;
S_Average = 0;
B_Lot = 0;
S_Lot = 0;
for(cnt=0;cnt<OrdersTotal();cnt++)
{
result = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
LastPrice=OrderOpenPrice();
LastLots=OrderLots();
OpenOrders++;
Profit += OrderProfit();
if (OrderType()==OP_BUY)
{
LastType=OP_BUY;
CountB++;
LastPriceBuy = OrderOpenPrice();
LastLotsBuy = OrderLots();
B_Lot+=OrderLots();
B_LotPrice+=OrderLots()*OrderOpenPrice();
}
if (OrderType()==OP_SELL)
{
LastType=OP_SELL;
CountS++;
LastPriceSell= OrderOpenPrice();
LastLotsSell = OrderLots();
S_Lot+=OrderLots();
S_LotPrice+=OrderLots()*OrderOpenPrice();
}
}
}
//------------------------------------------------------Start open First order---------------------------------
double MinLots = MarketInfo(Symbol(),MODE_MINLOT);
double MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);
if (Lots<MinLots) {Lots=MinLots;}
if (Lots>MaxLots) {Lots=MaxLots;}
Comment ("Lots : ",Lots, " MinLots : ",MinLots," mylotsi : ",mylotsi);
if(ContinueOpening)
{
//-----------------------------------------------Pending Order SellLimit-----------
if (Bid-LastPriceSell>=Step_Order*Point || CountS<1)
{
SellPrice=Bid;
if (TakeProfit==0) { tp=0; }
else { tp=SellPrice-TakeProfit*Point; }
if (Stoploss==0) { sl=0; }
else { sl=SellPrice+Stoploss*Point; }
mylotsi=Lots;
if (CountS>1)
{
for(cnt=1;cnt<=CountS;cnt++)
{
LastLotsSell=mylotsi;
mylotsi=NormalizeDouble(LastLotsSell*Step_Lots,2);
}
}
ticket = OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,sl,tp,NULL,MagicNumber,0,clrRed);
return(0);
}
//-----------------------------------------------Pending Order BuyLimit-----------
if (LastPriceBuy-Ask>=Step_Order*Point || CountB<1)
{
BuyPrice=Ask;
if (TakeProfit==0) { tp=0; }
else { tp=BuyPrice+TakeProfit*Point; }
if (Stoploss==0) { sl=0; }
else { sl=BuyPrice-Stoploss*Point; }
mylotsi=Lots;
if (CountB>1)
{
for(cnt=1;cnt<=CountB;cnt++)
{
LastLotsBuy=mylotsi;
mylotsi=NormalizeDouble(LastLotsBuy*Step_Lots,2);
}
}
ticket = OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,slippage,sl,tp,NULL,MagicNumber,0,clrBlue);
return(0);
}
}
//-------------------------------------Cut OrderClose-----------------------------
//----------------------------------------------------------
if(OpenOrders!=0 && Profit>=TargetDollar && Enable_TargetDollar)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
result = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode=OrderType();
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if (mode==OP_BUY) {res = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrDarkViolet); }
if (mode==OP_SELL) {res = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrOrangeRed); }
}
}
}
if(OpenOrders!=0 && Profit<=(-SL_Dollar) && Enable_SL_Dollar)
{
for(cnt=0;cnt<OrdersTotal();cnt++)
{
result = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode=OrderType();
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if (mode==OP_BUY) {ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrIndigo); }
if (mode==OP_SELL){ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrCrimson); }
}
}
}
//---------------------------------------------------------------------------------------------
//----------------------
//----
return(0);
}