Open Forex4you Account

Server รัน EA 1000 / ปี

สั่งชื้อคู่มือการโปรแรกม MQL4

Author Topic: ใครถนัดเขียน indicator มั้งครับ รบกวนขอความรู้หน่อยครับ เรื่องวาดสีลงแท่งเทียน  (Read 50889 times)

pa_don

  • Newbie
  • *
  • Posts: 37
ใครถนัดเขียน indicator มั้งครับ รบกวนขอความรู้หน่อยครับ เรื่องวาดสีลงแท่งเทียน
ผมไม่ถนัดเขียนอินดี้อ่ะครับ
ช่วยผมหน่อยครับ

ราคาเปิด + - ราคาปิดถ้ามาก 10 จุด ให้ใส่สีลงในแท่งเทียน

รบกวนขอรูปแบบโค๊ดของ indicator หรือ คำสั่งในการวาดก็ได้ครับ



ขอบคุณครับ

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
มี code ที่ใช้สร้าง แท่งเทีนยหรือยังครับ ถ้ามีแล้วโพสให้ผมหน่อยครับ

pa_don

  • Newbie
  • *
  • Posts: 37
ผมยังไม่ได้ทำเลยครับ
เอาแบบนี้ก็ได้ครับ   วาด object ชี้ตรงราคาเปิดปิดก็ได้ครับ เด่วผมลองเขียนไปเรื่อยๆก็ได้ครับ

ขอรูปแบบ วาด object ชี้ราคาเปิด และ ราคาปิดครับ

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386

D_Diamond

  • Hero Member
  • *****
  • Posts: 673
    • Expert Forex Trading
ผมมีอินดี้อันนี้ครับ ท่าน pises999 เขียนให้
ใช้ได้  แต่มีบั๊ก 
เวลาเปิดทิ้งไว้นานๆๆๆๆ  มันจะลงสีมั่วครับ  บางทีแท่งสั้นก็ลง  บางทีสียาวกว่าแท่ง
ผมแก้ไม่เป็น  ท่านแอดมินช่วยแก้ให้หน่อยครับ

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386

D_Diamond

  • Hero Member
  • *****
  • Posts: 673
    • Expert Forex Trading
ท่านลองเปิดทิ้งไว้พักใหญ่ๆแล้วจะเห็นครับ มันมีบั๊กตามที่บอกไป ถ้าเปิดไม่นานมันจะปกติดีครับ
ผมดูโค้ดแล้วก็ไม่เข้าใจว่ามันมีบั๊กได้ยังไง

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
ผมติดตั้งแล้ว MT4 มัน remove ออกเองครับ มีอะไรผิดพลาดหรือเปล่าครับ

D_Diamond

  • Hero Member
  • *****
  • Posts: 673
    • Expert Forex Trading
ไม่มีปัญหานะครับผมใช้อยู่ทุกวันทั้งที่บ้านและ vps  เอาไว้ดู m1 เป็นสัญญาณ MDP ครับ

นี้เป็นโค้ด  ดัดแปลงมาจาก Heken Ashi ครับ สงสัยติดอะไรจากโค้ดเดิมอยู่เลยมีบั๊ก

//+------------------------------------------------------------------+
//|                                                  Heiken Ashi.mq4 |
//|                      Copyright c 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
//| For Heiken Ashi we recommend next chart settings ( press F8 or   |
//| select on menu 'Charts'->'Properties...'):                       |
//|  - On 'Color' Tab select 'Black' for 'Line Graph'                |
//|  - On 'Common' Tab disable 'Chart on Foreground' checkbox and    |
//|    select 'Line Chart' radiobutton                               |
//+------------------------------------------------------------------+
#property copyright "Copyright ฉ 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Violet
#property indicator_color2 Violet
#property indicator_color3 Magenta
#property indicator_color4 Magenta
#property indicator_color5 Red
#property indicator_color6 Red


//----
extern color color1 = Violet;
extern int width1 = 1;
extern double lenght1 = 10.0;
extern color color2 = Magenta;
extern int width2 = 1;
extern double lenght2 = 15.0;
extern color color3 = Red;
extern int width3 = 1;
extern double lenght3 = 25.0;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];

//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
 
  if ( Digits == 5 || Digits == 3 ) { lenght1*=10;lenght2*=10;lenght3*=10; }
//---- indicators
/*   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, color1);
   SetIndexBuffer(0, ExtMapBuffer1);
   
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, color2);
   SetIndexBuffer(1, ExtMapBuffer2);
*/
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   SetIndexDrawBegin(2,10);
   SetIndexDrawBegin(3,10);
   SetIndexDrawBegin(4,10);
   SetIndexDrawBegin(5,10);
   

//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexBuffer(5,ExtMapBuffer6);

   SetIndexStyle(0,DRAW_HISTOGRAM, 0, width1, color1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, width1, color1);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, width2, color2);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, width2, color2);
   SetIndexStyle(4,DRAW_HISTOGRAM, 0, width3, color3);
   SetIndexStyle(5,DRAW_HISTOGRAM, 0, width3, color3);

//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double  haHigh, haLow;
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted

   if (ExtCountedBars>0) ExtCountedBars--;
   
   

   
   int pos=Bars-ExtCountedBars-1;
   while(pos>=0)
     {
      haHigh=High[pos];
      haLow=Low[pos];

       ExtMapBuffer1[pos]=haLow;


       double lenght=High[pos]- Low[pos];

            if ( lenght >= lenght3 * Point)
            {
            ExtMapBuffer5[pos]=haLow;
            ExtMapBuffer6[pos]=haHigh; 
            ExtMapBuffer1[pos]=EMPTY; 
            ExtMapBuffer2[pos]=EMPTY;
            ExtMapBuffer3[pos]=EMPTY; 
            ExtMapBuffer4[pos]=EMPTY; 
            }
            else
            {
               if ( lenght >= lenght2 * Point  )
               {
               ExtMapBuffer3[pos]=haLow;
               ExtMapBuffer4[pos]=haHigh; 
               ExtMapBuffer1[pos]=EMPTY; 
               ExtMapBuffer2[pos]=EMPTY;
               ExtMapBuffer5[pos]=EMPTY; 
               ExtMapBuffer6[pos]=EMPTY; 
               }
               else
                   if ( lenght >= lenght1 * Point  )
                  {
                  ExtMapBuffer1[pos]=haLow;
                  ExtMapBuffer2[pos]=haHigh; 
                  ExtMapBuffer3[pos]=EMPTY;
                  ExtMapBuffer4[pos]=EMPTY;
                  ExtMapBuffer5[pos]=EMPTY;
                  ExtMapBuffer6[pos]=EMPTY;
                  }

            }

         
       SetIndexBuffer(1, ExtMapBuffer2);

       pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
อินดี้คืออันที่เป็นเส้นสี ม่วงใช่ไหมครับ


admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
มัน วาด Histogram ลงบน กราฟ เวลาปล่อยไวนานหรือข้ามวันมันจะแสดงผล เบอลได้ครับ เหมือนอินดี้พวกที่แสดงขอบบนขอบล่าง เวลา ข้ามวันแล้วเกิดราคาเปิดของวันใหม่กระโดนก็จะแสดงผลบนหน้าจอเพี้ยนได้เหมือนกัน ครับลองเอา init() ที่ผมเพิ่ม WindowRedraw( ) ; ไปใส่ดูครับให้มันวาด windows ใหม่ทุกครั้งเลยน่าจะหาย ถ้าไม่หายคงต้องเปลี่ยนจาก Histogram เป้น อย่างอื่นครับ
int init()
  {
 
  if ( Digits == 5 || Digits == 3 ) { lenght1*=10;lenght2*=10;lenght3*=10; }
//---- indicators
/*   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, color1);
   SetIndexBuffer(0, ExtMapBuffer1);
   
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, color2);
   SetIndexBuffer(1, ExtMapBuffer2);
*/
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   SetIndexDrawBegin(2,10);
   SetIndexDrawBegin(3,10);
   SetIndexDrawBegin(4,10);
   SetIndexDrawBegin(5,10);
   

//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexBuffer(5,ExtMapBuffer6);

   SetIndexStyle(0,DRAW_HISTOGRAM, 0, width1, color1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, width1, color1);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, width2, color2);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, width2, color2);
   SetIndexStyle(4,DRAW_HISTOGRAM, 0, width3, color3);
   SetIndexStyle(5,DRAW_HISTOGRAM, 0, width3, color3);
 WindowRedraw( ) ;
//---- initialization done
   return(0);
  }

D_Diamond

  • Hero Member
  • *****
  • Posts: 673
    • Expert Forex Trading
ใช่ครับ มีสีม่วง ชมพู แดง 3ระดับตามความยาวแท่งกราฟ

 WindowRedraw( ) ;  อันนี้ใส่ใน init ไม่ต้องใส่ใน start เหรอครับ

แล้วถ้ามันต้องวาดใหม่ตลอดมันจะมีปัญหาอะไรหรือเปล่าครับ

แต่ Hiken Ashi ตัวเดิมมันทำไมไม่มีบั๊กเลย มันก็ไม่ได้ใช้ WindowRedraw( ) เหมือนกันครับ

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
ใช่ครับ มีสีม่วง ชมพู แดง 3ระดับตามความยาวแท่งกราฟ

 WindowRedraw( ) ;  อันนี้ใส่ใน init ไม่ต้องใส่ใน start เหรอครับ

แล้วถ้ามันต้องวาดใหม่ตลอดมันจะมีปัญหาอะไรหรือเปล่าครับ

แต่ Hiken Ashi ตัวเดิมมันทำไมไม่มีบั๊กเลย มันก็ไม่ได้ใช้ WindowRedraw( ) เหมือนกันครับ
ครับใส่ ใน init() ได้เลยครับ ไม่มีปัญหาครับเพราะอินดี้เองมันก้คำนวณค่าใหม่ตลอดเวลาครับ ตัวเก่า ความยาวมันสั้นกว่าครับ มันเลยไม่มีปัญหาครับ เท่าที่ผมเคยเจอ อิดี้ที่ลากเส้น ยาวๆๆแทบทุกตัวเปิดไวนานๆหรือข้ามวัน มันจะแสดงผล error ครับ  หรือถ้าไม่อยากใส่ก็ต้องปรับความยาวลงมาพอๆๆกับตัวต้นแบบครับ

D_Diamond

  • Hero Member
  • *****
  • Posts: 673
    • Expert Forex Trading
เอาภาพเก่ามาให้ดูครับ  นี้คือตอนที่มันทำงานได้ปกติ  ลงสีถูกต้อง  ไม่มีบั๊ก 
พอปล่อยไว้นานๆ บางทีก็ไม่กี่นาที  มันก็จะเพี้ยน ลงสีมั่ว ตามภาพของท่านแอดมินครับ

เดี๋ยวจะลองดูอันใหม่ซักระยะ  หายไม่หายจะมารายงาน  ขอบคุณครับ

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
ลืมถามไปครับ มั่วแต่วุ่นเรื่องแสดงผล แล้วเรื่องค่าที่อินดี้ส่งออกมาถูกต้องตลอดหรือเปล่าครับ เพราะถ้าค่ามี error โอกาสแสดงผลก็มีผิดครับ