EA Programing => ปัญหาที่พบในการเขียน EA => Topic started by: jack on กุมภาพันธ์ 28, 2018, 06:11:33 am
-
รบกวนช่วยดู code หน่อย ว่าผมทำผิดตรงไหนครับ คือ ผมเขียน ea แล้วใส่ matingel เข้าไป ผลที่ได้คือ ถ้าราคาผิดทางจะเปิดไม้แก้ให้ จากนั้นถ้า กำไร กลับมาเป็นบวก จะสั่งปิด order แต่กลายเป็นว่า มันปิด order ของทุกคู่เลยครับ อยากให้ปิดแค่คู่เดียว คือเวลาเล่นจะเปิดกราฟหลายคู่ครับ
//+------------------------------------------------------------------+
//--Martingale
//+------------------------------------------------------------------+
void Martin()
{
if(Martingale)
{
if(CountBuy ()>0 && PriceAsk-Ask > Distance*Point && CountBuy() < Maxorder) OpenBuy();
if(CountSell()>0 && Bid-PriceBid > Distance*Point && CountSell() < Maxorder) OpenSell();
}
}
//+------------------------------------------------------------------+
int CountBuy()
{
int Count=0;
for(int i =OrdersTotal()-1;i>=0;i--)
{
bool res = OrderSelect(i,SELECT_BY_POS);
if(OrderType()==OP_BUY)
{
Count++;
}
}
return Count;
}
//+------------------------------------------------------------------+
int CountSell()
{
int Count=0;
for(int i =OrdersTotal()-1;i>=0;i--)
{
bool res = OrderSelect(i,SELECT_BY_POS);
if(OrderType()==OP_SELL)
{
Count++;
}
}
return Count;
}
//+------------------------------------------------------------------+
double NewLots()
{
double NewLots=Lotsize;
for(int i = OrdersTotal()-1;i>=0;i--)
{
bool res = OrderSelect(i,SELECT_BY_POS);
NewLots=NewLots*Multiple;
}
return NewLots;
}
//+------------------------------------------------------------------+
void CloseByProfit()
{
int ticket;
if(AccountProfit() >= profit)
{
for(int i = OrdersTotal()-1;i>=0;i--)
{
bool res = OrderSelect(i,SELECT_BY_POS);
ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),50,clrBlack);
}
}
}
-
ถ้าทำได้แล้วช่วยแชร์หน่อยได้ไหมครับ อยากรู้ด้วยครับ
-
ก็ต้องกำหนดให้มันสนใจแค่คู่เดียวที่อยู่บนกราฟครับ
OrderSymbol() == Symbol()
-
ขอบคุณสำหรับแนวทางครับ