กองทุน SPDR GOLD SHARES
ถือทองก่อนหน้า
ถือทองล่าสุด
0.00
*หน่วยตัน / ราคาอ้างอิงล่าสุดจากสมาคมค้าทองคำ
สถิติกองทุน SPDR
ราคาทองคำแท่ง 96.5%
ราคาอ้างอิงล่าสุดจากสมาคมค้าทองคำ
ครั้งที่
ราคาก่อนหน้า
ราคาล่าสุด
0
(หน่วย บาท*) / อัปเดตล่าสุดเมื่อวันที่ 13 ก.ค. 2566 เวลา 13:04 น.
สถิติราคาทองคำ ไทย

ขอ code แบ่ง order 128 lot ออกเป็น 3 ส่วนหน่อยครับ (50+50+28)

  • 0 replies
  • 1,197 views

รบกวนขอ code แบ่ง order ใหญ่ๆ ออกมาเป็น lot เล็กๆ ด้วยครับ
อยากได้ code แบบ A และ B
A แบบแบ่งออกตาม max order และเศษที่เหลือ
B ซอยเป็น order ย่อยๆ  เอาไว้สำหรับปิด order จะได้ง่ายๆ เพราะ LOT ใหญ่ๆ จะปิด order ยาก และโดน slippage เยอะมากๆๆ คิดวากซอย order ออกเป็นหลายๆ order เวลาปิดจะได้ปิดง่ายๆ ได้ทันทีเลย น่าจะดีกว่าการแบ่งปิด order ออกมาทีละ 1 lot (ใช้ฟีเจอร์แบ่งปิด order ทีละนิด)

เช่นโบรก xm จำกัดที่ 50 lot ต่อ 1 order ถ้าออก order 128 lot ก็ต้องแบ่งเป็น 50+50+28

กับที่อยากได้อีกอันคือ ออก order  1 lot x 128 order ก็ไม่ได้เพราะเกิน max 100 order ต้องเป็น 10 lot x 12 order + 8 lot

ผมหา code ได้แค่นี้ แต่ว่าเอามาลองใช้แล้วไม่ได้ ดูเหมือนจะให้ code มาไม่ครบ มันไม่ส่วนอื่นๆ อีก

โค๊ด [Select]


double  LotStep = MarketInfo(Symbol(), MODE_LOTSTEP),   // IBFX= 0.01
        maxLot  = MarketInfo(Symbol(), MODE_MAXLOT );   // IBFX=50.00
// If a trade size is bigger than maxlot, it must be split into several.
for (int split=MathCeil(lotsNew/maxLot); split>0; split--){
    // 50.00+49.99=99.99    25.01+25.00+25.00+25.00=100.01
    if (split == 1) double size = lotsNew;
    else {  size=MathCeil(lotsNew/split/LotStep)*LotStep; lotsNew -= size; }
    /* Put the magic number in the "Comment" field so you can see it on
     * the Metatrader terminal. This way you can figure out what is what
     * as magic numbers are not available in the user-interface.
     * --LibOrderReliable */
    cmnt = StringConcatenate(    WindowExpertName(),         " ",
            Symbol(),   ",",    Period.text,    ", ",           op.text,
            " ",        size,   " (",           magic.number,   ")");

    #define NO_SL       0   // Yet
    #define NO_TP       0
    oo.ticket = OrderSend(  Symbol(),       op.code,        size,
                            now.open,       Slippage.Pips*pips2points,
                            NO_SL,          NO_TP,          cmnt,
                            magic.number,   NO_EXPIRATION,  op.color);
    if (oo.ticket < 0){     Alert("OrderSend(type=",    op.code,
            " (",   op.text,    "), lots=", size,
            ", price=", DoubleToStr( now.open,              Digits     ),
                " (",   DoubleToStr((now.open-Bid)/pips2dbl,Digits.pips),
            "), SL=0, TP=0, '", no.open, "', ...) failed: ",GetLastError());
        no.open = "|OrderSend Failed";              // GetLastError first.
        break;
    }
    ModifyStops();                              // Set TP/SL ASAP
    if (split>1)    Refresh(); // RefreshRates()
}   // for(split)


https://www.mql5.com/en/forum/127620