EA Programing > ปัญหาที่พบในการเขียน EA
มีปัญหาอะไรที่เกิดกับ code EA
admin:
มีปัญหาที่เกี่ยวกับ code มาโพสที่นี้นะครับหากผมแก้ไขก็จะช่วยครับหากทำไม่ได้ก็รอผู้อื่นมาช่วยตอบแทนนะครับ
gunlanutt:
ผม ตั้ง trailingstop = 10 ทำไมบางครั้งก็เปลี่ยน บางครั้งก็ไม่เปลียนครับ
ผมใช้ fxopen GBP/USD, EUR/USD, และอื่น ๆ อีกหลายคู่
โค๊ดที่เขียนครับ
if(OrderType() == OP_BUY)
{
if(trailingStop > 0)
{
if(Bid - OrderOpenPrice() > trailingStop*Point)
{
if(OrderStopLoss() < (Bid - trailingStop*Point))
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid - trailingStop*Point, OrderTakeProfit(), 0, Blue);
}
}
}
else
{
if(trailingStop > 0)
{
if(OrderOpenPrice() - Ask > trailingStop*Point)
{
if(OrderStopLoss() == 0 || OrderStopLoss() > Ask + trailingStop*Point)
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + trailingStop*Point, OrderTakeProfit(), 0, Red);
}
}
}
phanom:
ตั้งค่า TrailingStop น้อยไปครับ
เพราะมันพอดีกับค่า minimum ของเค้าพอดีเลย
กว่าอีเอจะส่งคำสั่งไป ถ้าราคามันเปลี่ยน คำสั่งปรับ OrderStoploss ก็โดนยกเลิก
ตั้ง TrailingStop ซัก 20 จุดขึ้นไป น่าแก้ปัญหาได้ ;D
Bauer:
--- Quote from: gunlanutt on สิงหาคม 24, 2009, 01:56:44 pm ---ผม ตั้ง trailingstop = 10 ทำไมบางครั้งก็เปลี่ยน บางครั้งก็ไม่เปลียนครับ
ผมใช้ fxopen GBP/USD, EUR/USD, และอื่น ๆ อีกหลายคู่
โค๊ดที่เขียนครับ
if(OrderType() == OP_BUY)
{
if(trailingStop > 0)
{
if(Bid - OrderOpenPrice() > trailingStop*Point)
{
if(OrderStopLoss() < (Bid - trailingStop*Point))
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid - trailingStop*Point, OrderTakeProfit(), 0, Blue);
}
}
}
else
{
if(trailingStop > 0)
{
if(OrderOpenPrice() - Ask > trailingStop*Point)
{
if(OrderStopLoss() == 0 || OrderStopLoss() > Ask + trailingStop*Point)
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + trailingStop*Point, OrderTakeProfit(), 0, Red);
}
}
}
--- End quote ---
ตอนแรกดูผิด ตัว code ok แล้วครับ แต่ถ้าอยากตั้งน้อยๆ จะมีวิธีแก้คือใช้เก็บค่าในโปรแกรมเลยครับ เวลาถึงค่าค่อยสั่ง close คือจะไม่มีการ modify order ครับ แต่วิธีนี้จะมีความเสี่ยงนิดนึงกรณีเครื่องเราหรือ net มีปัญหา ซึ่งที่ผมเคยใช้วิธีนี้จะใช้การ stop loss ปกติกันไว้ด้วยครับ
gunlanutt:
int counted_bars=IndicatorCounted();
int i,limit15;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit15=Bars-counted_bars;
ผมทดลองใช้คำสั่ง IndicatorCounted() แต่ อีเอไม่ทำงานครับ พอผมใช้คำสั่ง
int counted_bars= Bars-1; ก็ได้ค่าอื่น ๆ ในโปรแกรมไม่เหมือนกันอีก เป็นเพราะอะไรครับ หรือว่า คำสั่ง
IndicatorCounted() ใช้ได้เฉพาะอินดิเคเตอร์เท่านั้น
ถ้าเป็นอย่างนั้นจริง ๆ จะแก้โค๊ดตรงนี้ได้อย่างไรครับ
นำร่อง
[0] ดัชนีข้อความ
[#] หน้าถัดไป
Go to full version