อันนี้เขียนมา ปรากฏว่ามัน sell อย่างเดียว ใครพอบอกได้ว่า code ผิดจุดไหน
int start()
{
double lotsize = 0.1;
double lastadx = iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,1);
double high = iHighest(NULL,0,MODE_HIGH,19,2);
double low = iLowest(NULL,0,MODE_LOW,19,2);
double lasthigh = iHigh(NULL,0,1);
double lastlow = iLow(NULL,0,1);
double close = iClose(NULL,0,1);
double ma14 = iMA(NULL,0,14,0,MODE_SMA,PRICE_CLOSE,1);
double ma20 = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);
double upperBB = double iBands(NULL,0,14,2,0,PRICE_CLOSE,MODE_UPPER,1);
double lowerBB = double iBands(NULL,0,14,2,0,PRICE_CLOSE,MODE_LOWER,1);
double total = OrdersTotal();
//----
int ticket;
if ((total == 0) && (lastadx > 25))
{
if ((close > high) && (ma14 > ma20))
{
ticket = OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,lowerBB,0,"Buy",0,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
return(0);
}
if ((close < low) && (ma14 < ma20))
{
ticket = OrderSend(Symbol(),OP_SELL,lotsize,Bid,3,upperBB,0,"sell",0,0,Red);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
Print("sell");
return(0);
}
}
//---- close ----
int i,Pos;
bool Result;
//----close all buy
if((total>0) && (close < lowerBB))
{for(i=total-1; i>=0; i--)
{if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
{Pos=OrderType();
if(Pos==OP_BUY || Pos==OP_SELL)
{if(Pos==OP_BUY)
Result=OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
}
}
}
}
//----close all sell
if((total>0) && (close > upperBB))
{for(i=total-1; i>=0; i--)
{if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
{Pos=OrderType();
if(Pos==OP_BUY || Pos==OP_SELL)
{if(Pos==OP_SELL)
Result=OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
}
}
return(0);
}
ขอบคุณครับ