เนื่องจากดูตัว lastXbars แล้วพยายามแกะ function เฉพาะจุดเปิด order
ลองแก้แล้วได้แบบนี้ (ที่ compile ได้) ไม่สามารถซื้อขายใน back test ได้จะรบกวนช่วยดูและแก้ครับ
/// code
int start()
{
//----
int lastxbars=32;
int bartf=0;
int ybarsago=21;
int adxtf=6;
int adxperiod=8;
int adxlevel=19;
int exitlastxbars=31;
int exitybarsago=21;
double lots = 0.1;
double takeprofit = 20;
double stoploss = 200;
int signal;
int mode,pos;
{
double high=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,lastxbars,pos+1));
double low=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,lastxbars,pos+1));
if(Close[pos]<low && iHighest(NULL,0,MODE_HIGH,lastxbars,pos+1)>=ybarsago && (iADX(NULL,PERIOD_H4,adxperiod,PRICE_CLOSE,MODE_PLUSDI,pos)>adxlevel))
if(mode==0)
{
signal = 1;
}
if(Close[pos]>high && iLowest(NULL,0,MODE_LOW,lastxbars,pos+1)>=ybarsago && iADX(NULL,PERIOD_H4,adxperiod,PRICE_CLOSE,MODE_PLUSDI,pos)>adxlevel)
if(mode==1)
{
signal = 2;
}
return(0);
}
//// close sig
int exitsignal;
int mode2,pos2;
{
if(Close[pos2]>high && iLowest(NULL,0,MODE_LOW,exitlastxbars,pos+1)>=exitybarsago)
if(mode2==0)
{
exitsignal = 1;
}
if(Close[pos2]<low && iHighest(NULL,0,MODE_HIGH,exitlastxbars,pos+1)>=exitybarsago)
if(mode2==1)
{
exitsignal = 2;
}
return(0);
//// Openbuy
if ((signal == 1) && (exitsignal == 1))
{
OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask - (takeprofit * Point),Ask + (stoploss * Point),"buy",0,0,Green);
signal = 0;
exitsignal = 0;
Sleep(600000);
}
//// Opensell
if ((signal ==2) && (exitsignal == 2))
{
OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid + (takeprofit * Point),Bid - (stoploss * Point),"sell",0,0,Red);
signal = 0;
exitsignal = 0;
Sleep(600000);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+