ช่วยชื้อแนะให้หน่อยครับผมต้องการฝึกเขียนอีเอเทรดหลายคู่เงิน แต่ชี้เป้าไปแต่ละคู่เงินไม่ถูกครับ ไม่ทราบว่าต้องวนลูปอย่างไรบ้างครับ
เบื้องต้นให้มัน print ค่าราคาเปิดของวันนั้น ในแต่ละคู่เงินออกมาก่อนก็พอครับ เดี๋ยวผมค่อยต่อยอดเองครับ (Priceline คือ ราคาเปิดของแท่งเทียน Day)
#property copyright "Copyright ฉ 2005, Alejandro Galindo"
#property link "
http://elcactus.com"
int Magic = 0;
int cnt=0;
int slippage=0;
int mode=0, myOrderType=0;
double BuyPrice=0, SellPrice=0;
double sl=0, tp=0;
double mylotsi;
bool ContinueOpening=True;
int ticket, result, ticketS;
bool tic, res;
double profitS, DD;
double ProfitToday, ProfitThisWeek;
double EquityL=9999999;
double netprofit = 0;
int OpenOrders[30];
int CountB[30], CountS[30];
int OrderBuyStop[30], OrderSellStop[30];
double Profit[30];
double LastLotsBuyStop[30];
double LastLotsSellStop[30];
double LastPriceBuyStop[30];
double LastPriceSellStop[30];
double PriceLine[30], OpenDay[30];
double SwapLong[30], SwapShort[30];
double Spread[30];
string Currency_;
string Suffix;
string SymbolCur_;
string Currency[30]=
{
"GOLD","GBPJPY","AUDJPY","EURJPY","USDJPY","CHFJPY","NZDJPY","CADJPY","GBPUSD",
"GBPNZD","GBPCHF","GBPAUD","GBPCAD","EURUSD","EURAUD","EURNZD","EURCAD","EURCHF","EURGBP",
"AUDUSD","AUDCAD","AUDNZD","AUDCHF","USDCHF","USDCAD","CADCHF","NZDUSD","NZDCHF","NZDCAD","BTCUSD",
};
bool Trade_Currency[30];
//Macd_Valuer_Upper_Change-Macd_Valuer_Lower_Change
string ______Currency_Settings________="------------Currency Settings------------";
bool _BTCUSD_ = False;
bool _XAUUSD_ = False;
bool _GBPJPY_ = False;
bool _AUDJPY_ = False;
bool _EURJPY_ = False;
bool _USDJPY_ = False;
bool _CHFJPY_ = False;
bool _NZDJPY_ = False;
bool _CADJPY_ = False;
bool _GBPUSD_ = True;
bool _GBPNZD_ = False;
bool _GBPCHF_ = False;
bool _GBPAUD_ = False;
bool _GBPCAD_ = False;
bool _EURUSD_ = False;
bool _EURAUD_ = False;
bool _EURNZD_ = False;
bool _EURCAD_ = False;
bool _EURCHF_ = False;
bool _EURGBP_ = False;
bool _AUDUSD_ = False;
bool _AUDCAD_ = False;
bool _AUDNZD_ = False;
bool _AUDCHF_ = False;
bool _USDCHF_ = False;
bool _USDCAD_ = False;
bool _CADCHF_ = False;
bool _NZDUSD_ = False;
bool _NZDCHF_ = False;
bool _NZDCAD_ = False;
//+-----------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//-------------------------------------------------------------------------------
Trade_Currency[0] = _BTCUSD_ ;
Trade_Currency[1] = _XAUUSD_ ;
Trade_Currency[2] = _GBPJPY_ ;
Trade_Currency[3] = _AUDJPY_ ;
Trade_Currency[4] = _EURJPY_ ;
Trade_Currency[5] = _USDJPY_ ;
Trade_Currency[6] = _CHFJPY_ ;
Trade_Currency[7] = _NZDJPY_ ;
Trade_Currency[8] = _CADJPY_ ;
Trade_Currency[9] = _GBPUSD_ ;
Trade_Currency[10] = _GBPNZD_ ;
Trade_Currency[11] = _GBPCHF_ ;
Trade_Currency[12] = _GBPAUD_ ;
Trade_Currency[13] = _GBPCAD_ ;
Trade_Currency[14] = _EURUSD_ ;
Trade_Currency[15] = _EURAUD_ ;
Trade_Currency[16] = _EURNZD_ ;
Trade_Currency[17] = _EURCAD_ ;
Trade_Currency[18] = _EURCHF_ ;
Trade_Currency[19] = _EURGBP_ ;
Trade_Currency[20] = _AUDUSD_ ;
Trade_Currency[21] = _AUDCAD_ ;
Trade_Currency[22] = _AUDNZD_ ;
Trade_Currency[23] = _AUDCHF_ ;
Trade_Currency[24] = _USDCHF_ ;
Trade_Currency[25] = _USDCAD_ ;
Trade_Currency[26] = _CADCHF_ ;
Trade_Currency[27] = _NZDUSD_ ;
Trade_Currency[28] = _NZDCHF_ ;
Trade_Currency[29] = _NZDCAD_ ;
//-------------------------------------------------------------------------------
SymbolCur_=ChartSymbol();
if(StringLen(Symbol())>6)
{
Suffix = StringSubstr(Symbol(),6);
}
else{Suffix="";}
for(cnt=0;cnt<ArraySize(Currency);cnt++)
{
OpenOrders[cnt] = 0;
Profit[cnt] = 0;
LastPriceBuyStop[cnt] = 0;
OrderBuyStop[cnt] = 0;
LastLotsBuyStop[cnt] = 0;
LastPriceBuyStop[cnt] = 0;
LastLotsSellStop[cnt] = 0;
OrderSellStop[cnt] = 0;
LastPriceSellStop[cnt] = 0;
CountB[cnt] = 0;
CountS[cnt] = 0;
}
for(cnt=0;cnt<ArraySize(Currency);cnt++)
{
Currency_=Currency[cnt]+Suffix;
for(int k=0;k<OrdersTotal();k++)
{
result = OrderSelect(k,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Currency_ && OrderMagicNumber()==Magic)
{
OpenOrders[cnt]++;
Profit[cnt] = Profit[cnt]+OrderProfit()+OrderSwap()+OrderCommission();
if (OrderType()==OP_SELL)
{
CountS[cnt]++;
}
if (OrderType()==OP_BUY)
{
CountB[cnt]++;
}
if(OrderType() == OP_BUYSTOP)
{
LastPriceBuyStop[cnt] = OrderOpenPrice();
LastLotsBuyStop[cnt] = OrderLots();
OrderBuyStop[cnt]++;
}
if(OrderType() == OP_SELLSTOP)
{
LastPriceSellStop[cnt] = OrderOpenPrice();
LastLotsSellStop[cnt] = OrderLots();
OrderSellStop[cnt]++;
}
}
}
}
netprofit = 0;
datetime starttime = iTime(Symbol(), PERIOD_W1, 0);
//for(int i=OrdersHistoryTotal()-1;i>=0;i--)
for(cnt=0; cnt<OrdersHistoryTotal(); cnt++)
{
result = OrderSelect(cnt,SELECT_BY_POS, MODE_HISTORY);
if(OrderCloseTime() >= starttime && OrderMagicNumber()==Magic )
{
netprofit += OrderProfit();
}
}
//Comment(" ProfitThisWeek : ",netprofit," $");
//-----------------------------------------------------------------
for(cnt=0;cnt<ArraySize(Trade_Currency);cnt++)
{
PriceLine[cnt] = NormalizeDouble(iOpen(NULL,1440,0),Digit);
Spread[cnt] = MarketInfo(Symbol(), MODE_SPREAD);
SwapLong[cnt] = MarketInfo(Symbol(),MODE_SWAPLONG);
SwapShort[cnt] = MarketInfo(Symbol(),MODE_SWAPSHORT);
if(DayOfWeek()==1){ Magic = MagicNumber+1;}// ContinueOpening = True;}
if(DayOfWeek()==2){ Magic = MagicNumber+2;}
if(DayOfWeek()==3){ Magic = MagicNumber+3;}
if(DayOfWeek()==4){ Magic = MagicNumber+4;}
if(DayOfWeek()==5){ Magic = MagicNumber+5;}
if(OpenDay[cnt] != PriceLine[cnt]) {ContinueOpening = True;}
Print("Price line : ",PriceLine[cnt]);
}
return(0);
}