EA Programing => ปัญหาที่พบในการเขียน EA => Topic started by: BenooB on กรกฎาคม 27, 2011, 12:28:08 am
-
จากที่อ่านมา ไม่สามารถเขียน EA ที่เป็นระบบ divergence ได้เลยครับ ใครมี ขอทีครับจะเอามาศึกษา
จากที่อ่านไฟล์เก่า ม๊าก เจอที่ท่าน admin ตอบ TVT เรื่อง การลงจุดค่า zigzag
static double high ;
static double low ;
static int direct=0;
int start()
{
double ticket, total, pc;
pc=iClose(NULL,0,1);
total=OrdersTotal();
int amount=0;
double temp[3];
double tem;
for(int i=0 ;i<5000;i++)
{
tem=iCustom(NULL, 0, "ZigZag",13,0,i);
if(tem>0)
{
temp[amount]=tem;
amount++;
if(amount>1)
{
i=5001;
}
}
}
if(temp[0]>temp[1])
{
high=temp[0];
low=temp[1];
direct=1;
}
if(temp[0]<temp[1])
{
high=temp[1];
low=temp[0];
direct=2;
}
if(direct==1)
{
if((total>0) && (pc<low ))
{
OrderClose(OrderTicket(),OrderLots(),Bid,1,Red);
Print("sale");
return(0);
}
if((total==0)&&(pc>high))
{
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,1,0,0,"buy",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("buy");
}
}
Print("Pc ",pc);
Print("high ",high);
Print("Low ",low);
return(0);
}
อยากทราบว่าถ้าต้องการค่า RSI ที่จุดยอด/ก้น ต่างๆ จะต้องใช้ คำสั่งใดดึงค่า RSI ณ จุดนั้นๆครับ (ขอตัวอย่างประกอบจะดีมากครับ)
-
คำสั่งหาค่า RSI มีครับ double iRSI( string symbol, int timeframe, int period, int applied_price, int shift)
แต่ของคุณต้องการค่า RSI ที่จุดยอด/ก้น ตรงนี้หละครับที่จะยาก เนื่อง rsi ต่างจาก zigzag ตรงที่มันเป็นชุดของ ข้อมูลที่เรียงต่อออกกันมาทุกแท่งเทียนของกราฟ แต่ zigzag จะมีแค่ 2 ค่า คือค่าแทงชึ้นแทงลง คุณต้องหาวิธีการทำให้มันรู้จุดใดคือจุดสูงสุดหรือจุดใดคือจุดต่ำสุด ด้วยการเปรียบเทียบค่ากับข้อมูลทั้งหมดที่คุณมี เพื่อหาค่า max และ min ของค่า RSI ที่คุณมีครับ เพราะเข้าใจไหมครับ
-
ดัดแปลงแบบนี้พอได้ไหมครับ (สีแดงคือที่เพิ่ม)
static double high ;
static double low ;
static int direct=0;
static double rsi0;
static double rsi1;
static double rsi2;
static double rsi3;
int start()
{
double ticket, total, pc;
pc=iClose(NULL,0,1);
rsi0 = iRSI(NULL,0,14,PRICE_CLOSE,0);
total=OrdersTotal();
int amount=0;
double temp[3];
double tem;
double rsi;
for(int i=0 ;i<5000;i++)
{
tem=iCustom(NULL, 0, "ZigZag",13,0,i);
rsi = iRSI(NULL,0,14,PRICE_CLOSE,i);
if(tem>0)
{
temp[amount]=tem;
amount++;
if(amount>1)
{
i=5001;
}
}
}
if(temp[0]>temp[1])
{
high=temp[0];
low=temp[1];
direct=1;
ตอนนี้นึกได้แค่นี้อะครับ admin พอจะมีอะไรแนะนำไหมครับ ถึงดึงค่า rsi1 ที่ temp[1] , rsi2 ที่ temp[2] ได้ (ถ้าเด๋วเปิดเจอจะลองอีกที)
}
if(temp[0]<temp[1])
{
high=temp[1];
low=temp[0];
direct=2;
}
if(direct==1)
{
if((total>0) && (pc<low ))
{
OrderClose(OrderTicket(),OrderLots(),Bid,1,Red);
Print("sale");
return(0);
}
if((total==0)&&(pc>high))
{
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,1,0,0,"buy",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("buy");
}
}
Print("Pc ",pc);
Print("high ",high);
Print("Low ",low);
return(0);
}
-
ที่ถามว่า ถึงดึงค่า rsi1 ที่ temp[1] , rsi2 ที่ temp[2] ได้
ผมงงอ่ะครับ คือ ค่า rsi ตรงไหนหรอครับลองขยายความให้ผมเข้าใจหน่อยครับ
-
คือ high = ตำแหน่งที่ เป็นยอดของ zigzag อันนั้นใช่ไหมครับ
ทีนี้ผมต้องการค่า rsi ที่แต่ละจุดที่เป็นยอด zigzag เพื่อมาคำนวนหา divergence และ convergence ครับ ,
ส่วนถ้าไล่ไป temp[2] , temp[3] , 4 .... ก็คือจุดที่ zigzag ส่งค่าออกมา ต้องการ rsi จุดนั้นครับ
-
ถ้าจำไม่ผิด code ตัวที่หาค่า zigzag ที่ผมเขียนให้คุณ TVT มันจะหาค่าได้ตำแหน่งเดียว ถ้าต้องการได้หลายค่า ก็ต้องสร้างตัวแปร array มารับค่าเพิ่มครับ แล้วก็ต้องแก้ในส่วนนี้
amount++;
if(amount>1)
{
i=5001;
}
ไม่ให้มันจบ loop จนกว่าจะวนเสร็จ ค่า i ที่ได้คือค่าของ แท่งเทียนที่เกิด zigzag ครับ ถ้าอยากได้ค่า rsi ของตำแหน่งนั่นก็เอาไปเข้าสูตร rsi = iRSI(NULL,0,14,PRICE_CLOSE,ตำแหน่งที่ i เก็บอยู่);
-
ถ้าจำไม่ผิด code ตัวที่หาค่า zigzag ที่ผมเขียนให้คุณ TVT มันจะหาค่าได้ตำแหน่งเดียว ถ้าต้องการได้หลายค่า ก็ต้องสร้างตัวแปร array มารับค่าเพิ่มครับ แล้วก็ต้องแก้ในส่วนนี้
amount++;
if(amount>1)
{
i=5001;
}
ไม่ให้มันจบ loop จนกว่าจะวนเสร็จ ค่า i ที่ได้คือค่าของ แท่งเทียนที่เกิด zigzag ครับ ถ้าอยากได้ค่า rsi ของตำแหน่งนั่นก็เอาไปเข้าสูตร rsi = iRSI(NULL,0,14,PRICE_CLOSE,ตำแหน่งที่ i เก็บอยู่);
รบกวน admin ช่วยแจก code ตัวอย่างได้ไหมครับ ขอวิธีเขียนสักตัว คิดว่าถ้ารู้วิธีแยก RSI1 rsi2 ได้ก็น่าจะไปได้(ขอโทษด้วยไม่ค่อยเข้าใจ mq4)
-
เดียวผมว่างจะทำตัวอย่างให้ดูครับ
-
โทษที่ครับช่วงนี้ผมต้องไปเฝ้าปู่ที่โรงบาลครับ ไม่ทราบว่าได้พัฒนาต่อหรือยังครับ
-
ยังรอตัอย่าง code ครับ ขอ code หา rsi ที่ตำแหน่งยอดสักอันที
ยังไงถ้าว่าแล้วเขียนตัวอย่างทีครับ แก้จากcode อันบนก็ได้ครับ
-
ตัวอย่างให้มันแสดงค่า zigzag กับ rsi ใน 5 ตำแหน่งโดยนับย้อนจากแท่งปัจจุบันนะครับ ให้ดูเรื่องการ set พารามิเตอร์ของ อินดี้ด้วยนะครับ ว่ามันตรงกับที่คุณต้องการเปล่า
int start()
{
int amount=0;
double temp[5];
double rtemp[5];
double tem;
double rsi;
for(int i=0 ;i<5000;i++)
{
tem=iCustom(NULL, 0, "ZigZag",13,0,i);
rsi = iRSI(NULL,0,14,PRICE_CLOSE,i);
if(tem>0)
{
temp[amount]=tem;
rtemp[amount]=rsi;
amount++;
if(amount>4)
{
i=5001;
}
}
}
Print("zigzag 0 :",temp[0]);
Print("rsi 0 :",rtemp[0]);
Print("zigzag 1 :",temp[1]);
Print("rsi 1 :",rtemp[1]);
Print("zigzag 2 :",temp[2]);
Print("rsi 2 :",rtemp[2]);
Print("zigzag 3 :",temp[3]);
Print("rsi 3 :",rtemp[3]);
Print("zigzag 4 :",temp[4]);
Print("rsi 4 :",rtemp[4]);
return(0);
}
-
ขอบคุณครับ ขอลองเอาไปทำดู