纽布在这里。
我下载了这个指标,从MT4客户端提取OHLC
起初看起来很好,但是:
1.它只保存2位小数的数据;
2.它没有为所有仪器保存OHLC。
有人可以帮我一把正确的代码吗?
//+------------------------------------------------------------------+
//| FXPT_ExportHistoryCSV.mq4 |
//| modified by fxprotrader |
//| http://www.fxpro-trader.com" |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, fxprotrader"
#property link "http://www.fxpro-trader.com"
// #property show_inputs
//-------- HISTORY----------------
// v1.0 Initial release(12162012)
//--------------------------------
//----
int handle;
//number of bars to export per Symbol
// int maxBars = 6418;
extern int maxBars = 200;
//test first on several pairs
// string Currencies[] = {"EURUSD","AUDUSD","GBPUSD","EURJPY","GBPJPY","USDCAD"};
string Currencies[] = {"#Corn","#France40","#Germany30","#NaturalGas","#Oil","#UK100","#USA30","#USA500","#USTECH100", "#Wheat", "#XAGUSD", "#XAUUSD", "58.com", "ABENGOA", "ABNAmro", "ADIDAS", "ADIDAS", "AGRICOLE", "AIB", "AIRBUS", "Albemarle", "ALCATEL", "ALCOA", "ALIBABA", "ALLIANZ", "ALPHA", "AlticeUSA", "Aluminium", "AMADEUS", "AMAZON", "AMD", "AMEX", "AMOVIL", "Amsterdam25", "Anglo", "APACHE", "APPLE", "APPLE.", "ARCELOR", "Arconic", "ASTRAZENECA", "ATnT", "AUDBRL", "AUDCAD", "AUDCAD!", "AUDCAD.", "AUDCHF", "AUDCHF!", "AUDCHF.", "AUDCNH", "AUDCZK", "AUDDKK", "AUDHKD", "AUDHRK", "AUDHUF", "AUDILS", "AUDINR", "AUDJPY", "AUDJPY!", "AUDJPY.", "AUDMXN", "AUDNOK", "AUDNZD", "AUDNZD!", "AUDNZD.", "AUDPLN", "AUDPNC", "AUDRON", "AUDRUB", "AUDSEK", "AUDSGD", "AUDTRY", "AUDUSD", "AUDUSD!", "AUDUSD.", "AUDZAR", "Autodesk", "AVAGO", "AVOLON", "BAIDU", "BancoBPM", "BASF", "BAYER", "BBBeyond", "BBVA", "BerkshireB", "BestBuy", "Billiton", "BITCOIN", "BITCOIN-D", "BITCOIN-M", "BITCOIN-W", "BlackBerry", "BMO", "BMPS", "BMPSIENA", "BMW", "BNPEU", "BOA", "BOEING", "BP", "BrentOil", "BRLJPY", "BRLPLN", "BTCUSD", "Burberry", "BUZZI", "CADBRL", "CADCHF", "CADCHF.", "CADCNH", "CADDKK", "CADHKD", "CADHRK", "CADHUF", "CADILS", "CADINR", "CADJPY", "CADJPY.", "CADMXN", "CADNOK", "CADPLN", "CADRON", "CADRUB", "CADSEK", "CADSGD", "CADTRY", "CADZAR", "CAP", "CARREFOUR", "CATERPILLAR", "CEMEX", "CEZ", "CHFJPY", "CHFJPY.", "CHFPLN", "CHFPLN.", "ChildrensPl", "China300ETF", "China50", "ChinaMob", "CISCO", "CitiGroup", "CNHJPY", "COCACOLA", "Cocoa", "Cocoa!", "Cocoa!", "Coffee", "Coffee!", "Coffee!", "Cognex", "COMMERZBANK", "Copper", "CoreCivic", "Corn", "Corn!", "Corn!", "Costco", "Cotton", "Cotton!", "Ctrip.com", "CZKPLN", "DAIMLER", "DanskeBank", "DaveBuster", "Deere", "Denmark20", "DeutschBank", "DeutscheTel", "DeutscheTel", "Diamond", "DIGICEL", "DISNEY", "DKKJPY", "DKKPLN", "DNB", "doBank", "Dollarindex", "easyJet", "EBAY", "EDF", "EEE", "ELECTRICA", "Ellaktor", "ELPE", "EMPRESAS", "ENAGAS", "ENEL", "ENI", "EOAN", "Ericsson", "ERSTE", "ETE", "EURAUD", "EURAUD!", "EURAUD.", "EURBRL", "EURCAD", "EURCAD!", "EURCAD.", "EURCHF", "EURCHF!", "EURCHF.", "EURCNH", "EURCZK", "EURCZK.", "EURDKK", "EURDKK.", "EURGBP", "EURGBP!", "EURGBP.", "EURHKD", "EURHRK", "EURHUF", "EURHUF.", "EURILS", "EURINR", "EURJPY", "EURJPY!", "EURJPY.", "EURMXN", "EURNOK", "EURNOK.", "EURNZD", "EURNZD.", "EUROPCAR", "EUROPCAR", "Europe50", "EURPLN", "EURPLN.", "EURPNC", "EURRON", "EURRON.", "EURRUB", "EURSEK", "EURSEK.", "EURSGD", "EURTRY", "EURTRY.", "EURUSD", "EURUSD!", "EURUSD.", "EURZAR", "Expedia", "ExxonMobil", "Facebook", "FAURECIA", "FCA", "FERRARI", "FIAT", "FirstData", "FITBIT", "FOMENTO", "France40", "FSOLAR", "GAMESA", "GameStop", "Gap", "GAZPROM", "GBPAUD", "GBPAUD!", "GBPAUD.", "GBPCAD", "GBPCAD!", "GBPCAD.", "GBPCHF", "GBPCHF!", "GBPCHF.", "GBPCNH", "GBPCZK", "GBPDKK", "GBPHKD", "GBPHRK", "GBPHUF", "GBPILS", "GBPJPY", "GBPJPY!", "GBPJPY.", "GBPMXN", "GBPNOK", "GBPNZD", "GBPNZD.", "GBPPLN", "GBPRON", "GBPRON.", "GBPRUB", "GBPSEK", "GBPSGD", "GBPSGD.", "GBPTRY", "GBPTRY.", "GBPUSD", "GBPUSD!", "GBPUSD.", "GBPZAR", "GE", "GEMALTO", "GENERALI", "GER10YBond", "germany30", "GILEAD", "Gilt10Y", "GLENCORE", "GM", "GoDaddy", "GolarLNG", "GoldmnSachs", "GOOGLE", "GoPro", "Greece20", "GRIFOLS", "Grivalia", "Groupon", "GRUMA", "Handelsbank", "Harley", "HEINEKEN", "HEINEKEN", "Hermes", "HewlettEnt", "HILTON", "HKDJPY", "HKDPLN", "HongKong45", "HP", "HRKJPY", "HSBC", "HTO", "HUBSPOT", "HUFJPY", "HUFPLN", "IBERDROLA", "IBM", "Ikang", "ILIAD", "ILSBRL", "ILSCNH", "ILSCZK", "ILSDKK", "ILSHKD", "ILSHUF", "ILSINR", "ILSJPY", "ILSMXN", "ILSNOK", "ILSPLN", "ILSPNC", "ILSRON", "ILSRUB", "ILSSEK", "ILSSGD", "ILSTRY", "ILSZAR", "India50", "INDITEX", "INDRA", "INFINEON", "INTEL", "INTESA", "Intuit", "Italy40", "JABIL", "Japan225", "JAZZTEL", "JCPenney", "JCPenney", "JD.com", "JIMMYCHOO", "JPMorgan", "JPN10yBond", "JPYINR", "Jumbo", "K+S", "K+S", "KGHM", "KING", "KirbyCorp", "KOMERCNI", "KRAFT", "LEVTST", "Line", "LineCorp", "LINKEDIN", "LionsGate", "Lloyds", "LockheedM", "LUFTHANSA", "LukoilUSD", "Lululemon", "LVMH", "Macys", "MAGNIT", "MANU", "MARRIOTT", "MARVELL", "Mastercard", "Match", "McDonalds", "MEGAFON", "METRO", "MGM", "MICHELIN", "MICRON", "MICROSOFT", "MOL", "MOMO", "MONDELEZ", "Moneta", "MONSANTO", "MorganStan", "Moscow50", "MotorOil", "MsciMexico", "MSCITaiwan", "MTELEKOM", "MTN", "MXNJPY", "MXNPLN", "Mytilineos", "Mytilineos", "NaturalGas", "NESTLE", "NETFLIX", "NewOriental", "NIKE", "Nintendo", "NintendoJP", "NOBLE", "NOKIA", "NOKJPY", "NOKPLN", "Norway25", "NovoNord", "Novozymes", "NUANCE", "NWR", "NZDCAD", "NZDCAD.", "NZDCHF", "NZDCHF.", "NZDJPY", "NZDJPY.", "NZDUSD", "NZDUSD!", "NZDUSD.", "Oil", "OPAP", "ORACLE", "OrangeFR", "OTP", "Palladium", "PartyCity", "PayPal", "PEKAO", "PepsiCo", "PetroChina", "PetrolBras", "PEUGEOT", "PEUGEOT", "PFIZER", "PGE", "PHILIPS", "PIRELLI", "PKNORLEN", "PKOBP", "Platinum", "Play", "PLNCNH", "PLNHRK", "PLNINR", "PLNJPY", "PNCCAD", "PNCJPY", "PNCPLN", "PNCUSD", "Poland20", "POPOLARE", "POPULARESP", "POSTEITALIA", "POTASH", "PPC", "PRICELINE", "PSBC", "PZU", "Qualcomm", "QUNAR", "RBS", "REE", "RegalBeloit", "Renault", "REPSOL", "Rice", "RioTinto", "ROCKET", "ROLLSROYCE", "ROMGAZ", "RONJPY", "RONPLN", "ROSNEFT", "RUBJPY", "RUBPLN", "RWE", "SABADELL", "SABMiller", "SACYR", "SafeBulkers", "SAfrica40", "SaintGobain", "SALESFORCE", "SAMSUNG", "SANDISK", "SANOFI", "SANTANDER", "SAP", "Sasol", "SBERBANK", "Scorpio", "SEKJPY", "SEKPLN", "Severstal", "SGDJPY", "SGDPLN", "ShakeShack", "SHELL", "SHOPIFY", "SIEMENS", "SINA", "Snap", "SOCIETE", "SOLARCITY", "SONY", "SouFun", "soybeans", "Soybeans!", "Soybeans!", "Soybeans!", "Spain35", "Splunk", "Square", "STARBUCKS", "Statoil", "Sugar", "Sweden30", "Swiss20", "Sydney200", "SYMANTEC", "Synaptics", "Target", "TDBank", "TECK", "TECK.", "TECK.", "TELECOMITAL", "TELEFONESP", "TELEFONICA", "Telenor", "TeliaSonera", "TerraForm", "TESCO", "TESLA", "TEVA", "Tiffany", "TitanCement", "TOTAL", "TOYOTA", "TPSA", "TRIPADVISOR", "TRYJPY", "TRYPLN", "Twilio", "TWITTER", "UBS", "UK100", "Unicredit", "UNISTEEL", "US10YNote", "US30YBond", "USA2000", "USA30", "USA500", "USDBRL", "USDCAD", "USDCAD!", "USDCAD.", "USDCHF", "USDCHF!", "USDCHF.", "USDCNH", "USDCZK", "USDCZK.", "USDDKK", "USDDKK.", "USDHKD", "USDHRK", "USDHUF", "USDHUF.", "USDILS", "USDINR", "USDJPY", "USDJPY!", "USDJPY.", "USDMXN", "USDNOK", "USDNOK.", "USDPLN", "USDPLN!", "USDPLN.", "USDRON", "USDRON.", "USDRUB", "USDSEK", "USDSEK.", "USDSGD", "USDSGD.", "USDTRY", "USDTRY.", "USDZAR", "USFoods", "USTECH100", "VA", "VALE", "VestasWind", "VIG", "VINCI", "Vipshop", "VISA", "VIVENDI", "vixx", "VODAFONE", "VolksWagen", "Volvo", "WALMART", "WEIBO", "WellsFargo", "Wheat", "Wheat!", "Wheat!", "WIZZ", "WOWO", "WPP", "XAGUSD", "XAGUSD.", "XAUUSD", "XAUUSD.", "Xylem", "YAHOO", "YamanaGold", "YANDEX", "Yara", "Yelp", "YYInc", "ZARJPY", "ZARPLN", "Zinc", "ZTO", "ZYNGA",};
string dSymbol;
double Poin;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init(){
if (Point==0.00001) Poin=0.0001;
else {
if (Point==0.001) Poin=0.01;
else Poin=Point;
}
return(0);
}
//+------------------------------------------------------------------+
//| start function |
//+------------------------------------------------------------------+
int start(){
int count = ArraySize(Currencies);
for (int ii=0; ii<count; ii++){
dSymbol = Currencies[ii];
handle = FileOpen("Hist_"+dSymbol+"_"+Period()+".csv", FILE_BIN|FILE_WRITE);
if(handle < 1){
Print("Err ", GetLastError());
return(0);
}
WriteHeader();
for(int i = 0; i < maxBars - 1; i++){
WriteDataRow(i);
}
FileClose(handle);
}
Alert("Done. "+maxBars+" bars generated "+TimeMonth(TimeLocal())+TimeDay(TimeLocal())+TimeYear(TimeLocal()) +"_"+TimeHour(TimeLocal())+TimeMinute(TimeLocal()));
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void WriteData(string txt){
FileWriteString(handle, txt,StringLen(txt));
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void WriteHeader(){
WriteData("Symbol,");
WriteData("Date,");
WriteData("DayOfWeek,");
WriteData("DayOfYear,");
WriteData("Open,");
WriteData("High,");
WriteData("Low,");
WriteData("Close,");
WriteData("RSI5,RSI11,MOM3_c,CCI11_c,");
WriteData("\n");
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void WriteDataRow(int i){
double dSymTime, dSymOpen, dSymHigh, dSymLow, dSymClose, dSymVolume;
int dDayofWk,dDayofYr,iDigits;
dSymTime = (iTime(dSymbol,Period(),i));
dDayofWk = (TimeDayOfWeek(dSymTime));
dDayofYr = TimeDayOfYear(dSymTime);
dSymOpen = (iOpen(dSymbol,Period(),i));
// if(TimeToStr(dSymTime, TIME_DATE)!= "1970."){
if(dSymOpen>0){
WriteData(dSymbol+",");
WriteData(TimeToStr(dSymTime, TIME_DATE|TIME_MINUTES)+",");
iDigits=MarketInfo(Symbol(),MODE_DIGITS);
dSymOpen = (iOpen(dSymbol,Period(),i));
dSymHigh = (iHigh(dSymbol,Period(),i));
dSymLow = (iLow(dSymbol,Period(),i));
dSymClose = (iClose(dSymbol,Period(),i));
dSymVolume = (iVolume(dSymbol,Period(),i));
// int BarsInBox=8;
// double PeriodHighest = High[iHighest(dSymbol,Period(),MODE_HIGH,BarsInBox+1,i)];
// double PeriodLowest = Low[iLowest(dSymbol,Period(),MODE_LOW,BarsInBox+1,i)];
// double PeriodRNG = (PeriodHighest-PeriodLowest)/Poin;
double RSI5_c = iRSI(NULL,0,5,PRICE_CLOSE,i);
double RSI5_p3 = iRSI(NULL,0,5,PRICE_CLOSE,i+3);
double MOM3_c = iMomentum(NULL,0,21,PRICE_CLOSE,i);
double MOM3_p3 = iMomentum(NULL,0,21,PRICE_CLOSE,i+3);
double CCI11_c = iCCI(NULL,0,5,PRICE_CLOSE,i);
double CCI11_p3 = iCCI(NULL,0,5,PRICE_CLOSE,i+3);
WriteData(dDayofWk+","+dDayofYr+",");
WriteData(DoubleToStr(dSymOpen, iDigits)+",");
WriteData(DoubleToStr(dSymHigh, iDigits)+",");
WriteData(DoubleToStr(dSymLow, iDigits)+",");
// WriteData(DoubleToStr(dSymClose, iDigits)+","+PeriodHighest+","+PeriodLowest+","+PeriodRNG);
WriteData(DoubleToStr(dSymClose, iDigits)+","+DoubleToStr(RSI5_c,2)+","+DoubleToStr(RSI5_p3,2)+
","+DoubleToStr(MOM3_c,2)+","+DoubleToStr(MOM3_p3,2)+","+DoubleToStr(CCI11_c,2)+","+DoubleToStr(CCI11_p3,2)+",");
WriteData("\n");
}
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetPeriodName(){
switch(Period()){
case PERIOD_D1: return("Day");
case PERIOD_H4: return("4_Hour");
case PERIOD_H1: return("Hour");
case PERIOD_M1: return("Minute");
case PERIOD_M15: return("15_Minute");
case PERIOD_M30: return("30_Minute");
case PERIOD_M5: return("5_Minute");
case PERIOD_MN1: return("Month");
case PERIOD_W1: return("Week");
}
}
答案 0 :(得分:1)
CustomIndicator
是不好的 CustomIndicator
- 类型的MQL4代码将挂起并等待直到QUOTE消息从Broker端到达(等待第一个FxEvent出现......并且它可能永远不会到达..所以其他一些MQL4代码类型可以提供更好的服务......)
你要求其他人帮助你,但似乎你至少没有试过阅读你的代码,对吗?
您明确将值修剪为不超过2位小数:
WriteData( DoubleToStr( dSymClose, iDigits ) + ","
+ DoubleToStr( RSI5_c, 2 ) + ","
+ DoubleToStr( RSI5_p3, 2 ) + ","
+ DoubleToStr( MOM3_c, 2 ) + ","
+ DoubleToStr( MOM3_p3, 2 ) + ","
+ DoubleToStr( CCI11_c, 2 ) + ","
+ DoubleToStr( CCI11_p3, 2 ) + ","
);
接着,
你的代码&#34;忘记&#34;在没有来自当前图表的继承属性的情况下工作,这会排除您所需的独立性( USDJPY
图表将为所有处理的工具产生3 == MarketInfo( Symbol(), MODE_DIGITS )
,因为您是在 USDJPY
图表上。
iDigits = MarketInfo( Symbol(),MODE_DIGITS );
dSymOpen = ( iOpen( dSymbol, Period(), i ) );
dSymHigh = ( iHigh( dSymbol, Period(), i ) );
dSymLow = ( iLow( dSymbol, Period(), i ) );
dSymClose = ( iClose( dSymbol, Period(), i ) );
dSymVolume = ( iVolume( dSymbol, Period(), i ) );
概念中的类似错误来自于使用所有本地 - 图形绑定&#34;默认&#34;值< - strong> NULL
,其中 dSymbol
应该代替 0
,其中{{1}或者其他明确的TimeFrame应该以足够强大的方式提供...因此需要花费一些精力......
PERIOD_M1
所以,
一个仔细的重新设计已经到位,下载文件并不是一种免费获得结果的安全方法,而且作者+ [ fxprotrader ]的专业交易工具设计水平相当低。< / p>
最好进入 double RSI5_c = iRSI( NULL, 0, 5, PRICE_CLOSE, i );
double RSI5_p3 = iRSI( NULL, 0, 5, PRICE_CLOSE, i+3 );
double MOM3_c = iMomentum( NULL, 0, 21, PRICE_CLOSE, i );
double MOM3_p3 = iMomentum( NULL, 0, 21, PRICE_CLOSE, i+3 );
double CCI11_c = iCCI( NULL, 0, 5, PRICE_CLOSE, i );
double CCI11_p3 = iCCI( NULL, 0, 5, PRICE_CLOSE, i+3 );
类型的代码,并删除local-Graph属性上所有遗忘的依赖项。使用 MQL4-Script
更有效地处理char-IO也会有很大帮助,更不用说预防性检查,如果在本地历史数据库数据库中确实存在命名符号和/或处理符号存在的情况,但没有从Broker预加载数据并为这种情况调解解决方案。
StringFormat( .., ..[, .. ] )