dtyanmm
Active Member
- 233
- 95
tình hình là em đang mất ngủ vì con EA , mò mãi hk ra , ace cho hỏi làm cách nào để EA gặp trường hợp 1 Buy nó Buy , sau đó khi chưa thanh khoản được trường hợp 1 mà tiếp tục gặp trường hợp 2 là Sell thì nó Sell , em BackTest toàn xổ ra 1 tràn BUY ko thấy cái nào Sell , nhưng khi /*BUY*/ thì nó mới Sell ~.~! và em chắc chắn là Buy với Sell ko bị trùng bar hay thời gian gì cả ... code em viết theo barem của forexeadvisor.com ... đại loại như cái đống code này
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
int A,B,C,D,E,F;
A=1;
B=2:
C=3:
D=4;
E=5;
double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()>=0 )
{
int result=0;
if((A>C&&B<C) || (C>E&&D<E))
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(true);
}
if((A>B&&B<C) || (C>D&&D<E))
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(true);
}
}
return(0);
}
int TotalOrdersCount()
{
int result=0;
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (AllPositions || OrderSymbol()==Symbol())
{
TrailingPositions();
if (OrderMagicNumber()==MagicNumber) result++;
{
return (result);
}
}
}
}
return(0);
}
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 || OrderStopLoss()==0)
{
ModifyStopLoss(pAsk+TrailingStop*pp);
return;
}
}
}
}
void ModifyStopLoss(double ldStopLoss)
{
bool fm;
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
}
//<---- Check for new candle, returns true
bool NewBar()
{
static datetime OldTime = 0;
if(OldTime < Time[0])
{
OldTime = Time[0];
return(true);
}
else
{
return(false);
}
}
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
int A,B,C,D,E,F;
A=1;
B=2:
C=3:
D=4;
E=5;
double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()>=0 )
{
int result=0;
if((A>C&&B<C) || (C>E&&D<E))
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(true);
}
if((A>B&&B<C) || (C>D&&D<E))
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(true);
}
}
return(0);
}
int TotalOrdersCount()
{
int result=0;
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (AllPositions || OrderSymbol()==Symbol())
{
TrailingPositions();
if (OrderMagicNumber()==MagicNumber) result++;
{
return (result);
}
}
}
}
return(0);
}
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 || OrderStopLoss()==0)
{
ModifyStopLoss(pAsk+TrailingStop*pp);
return;
}
}
}
}
void ModifyStopLoss(double ldStopLoss)
{
bool fm;
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
}
//<---- Check for new candle, returns true
bool NewBar()
{
static datetime OldTime = 0;
if(OldTime < Time[0])
{
OldTime = Time[0];
return(true);
}
else
{
return(false);
}
}
Giới thiệu sách Trading hay
Đánh Bại Thị Trường Forex - Tư duy khác biệt và các kỹ thuật giao dịch của chuyên gia quản lý quỹ triệu đô
Sách chia sẻ kiến thức và kinh nghiệm trading từ một chuyên gia quản lý quỹ, cùng các kỹ thuật giao dịch giúp quỹ này đứng trong top nhiều năm
Bài viết liên quan