Sponsored Ads

วันอังคารที่ 13 มิถุนายน พ.ศ. 2560

การใช้ Marketinfo กับการส่ง Order

ตัวอย่างการใช้ MatketInfo กับการส่ง Order 

ในบทความนี้เราจะเอาฟังชั่นทั้ง 2 ตัว เอามาเขียนประยุกต์ใช้ด้วยกัน 

โดยเราจะดึงราคา Bid และ Ask รวมถึงค่า Point เพื่อเอาไว้ใช้ในการเปิด Order นั่นเอง 

int start()
{
   double bid = MarketInfo(Symbol(),MODE_BID); 
   double ask = MarketInfo(Symbol(),MODE_ASK);
   double point = MarketInfo(Symbol(),MODE_POINT);
   double SL = MarketInfo(Symbol(),MODE_STOPLEVEL); 
   
   
   OrderSend(Symbol(),OP_BUY,0.01,ask,10,bid-SL*Point,bid+SL*Point); 
   Alert(GetLastError()); 
   
   return; 
   
}   

****  Code นี้ หากเราไปเขียนใน EA มันจะส่งคำสั่งทุกครั้งที่มีการเคลื่อนที่ของราคา ดังนั้นควรเขียนลงใน script น่าจะดีกว่าหากต้องการส่งคำสั่งครั้งเดียว 

มาอธิบายทีละบรรทัดกันครับ

   double bid = MarketInfo(Symbol(),MODE_BID); 

ดึงค่า Bid มาใส่ในตัวแปร bid   (  Ask ก็เหมือนกัน )

   double point = MarketInfo(Symbol(),MODE_POINT);

ดึงค่า Point มาเก็บไว้ในตัวแปร point 


  double SL = MarketInfo(Symbol(),MODE_STOPLEVEL); 

ดึงค่า Stop Level มาเก็บไว้ในตัวแปร SL  เนื่องจากในการส่งคำสั่ง TP หรือ Stop loss มันจะมีระยะต่ำที่สุดที่สามารถให้ใส่ค่าได้ ดังนั้นเราก็ดึงค่านั้นจาก MarketInFo มาใช้นั้นเอง 

   OrderSend(Symbol(),OP_BUY,0.01,ask,10,bid-SL*Point,bid+SL*Point); 


เป็นคำสั่งไว้ส่ง Order ครับ ก็ใส่ค่าตามตัวแปรที่ฟังช์่นต้องการ โดยเอาตัวแปรที่เราดึงค่ามาใส่ในฟังก์ชั่นนั้นเอง 


   Alert(GetLastError()); 


เป็นการแสดงผลค่า Error ที่เกิดขึ้น มันจะแสดงเป็นตัวเลข หากเกิดปัญหาอะไรก็สามารถเช็คได้ที่ 

https://book.mql4.com/appendix/errors


เพื่อนๆสามารถดูคำอธิบายเพิ่มเติมได้ที่ https://book.mql4.com/trading/ordersend 



2 ความคิดเห็น:

  1. Listen...

    This may sound pretty creepy, and maybe even kind of "strange"

    WHAT if you could simply hit "Play" to LISTEN to a short, "musical tone"...

    And suddenly bring MORE MONEY into your LIFE??

    I'm talking about BIG MONEY, even MILLIONS of DOLLARS!!

    Sound too EASY?? Think this couldn't possibly be for REAL??

    Well then, I'll be the one to tell you the news.

    Sometimes the greatest miracles life has to offer are the easiest to GET!!

    Honestly, I will provide you with PROOF by letting you listen to a real-life "miracle money tone" I've synthesized...

    And do it FREE (no strings attached).

    You simply hit "Play" and you will start having more money come into your life... starting almost INSTANTLY...

    CLICK here now to PLAY the mysterious "Miracle Money Tone" - it's my gift to you!!

    ตอบลบ
  2. Alright...

    This may sound a little creepy, and maybe even a little "out there..."

    BUT what if you could just click "Play" and LISTEN to a short, "magical tone"...

    And INSTANTLY bring MORE MONEY into your LIFE??

    And I'm talking about thousands... even MILLIONS of DOLLARS!!!

    Do you think it's too EASY?? Think it couldn't possibly be REAL???

    Well then, Let me tell you the news.

    Sometimes the greatest miracles life has to offer are the easiest to GET!!!

    Honestly, I will PROVE it to you by letting you listen to a REAL "miracle wealth building tone" I developed...

    And TOTALLY FOR FREE

    YOU just press "Play" and watch as your abundance angels fly into your life... starting pretty much right away...

    CLICK here to PLAY the mysterious "Miracle Abundance Sound Frequency" - as my gift to you!!!

    ตอบลบ