//+------------------------------------------------------------------+ //|GetHistoryInd.mq4 - For creating file of closed and open/pending positions //|Updated 4/30/07 - Added Collect Price Action - collect M1 data while position open //+------------------------------------------------------------------+ #property copyright "" #property link "" #property indicator_chart_window extern string OpenOrderComment; extern bool CollectPriceAction=true; static int mPrev; int m; //+------------------------------------------------------------------+ int init() { mPrev=Minute(); return(0); } //+------------------------------------------------------------------+ int start() { int i,handle,hstTotal=HistoryTotal(); m=Minute(); if(m!=mPrev) //Get updates every minute { mPrev=m; GetClosedPositionData(); if(CollectPriceAction) GetPriceAction(); } return(0); } //+------------------------------------------------------------------+ void GetClosedPositionData() { int i, handle; handle=FileOpen("ClosedPositions.csv",FILE_WRITE|FILE_CSV,","); if(handle<0) return(0); for(i=0;i<HistoryTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) { FileWrite(handle,OrderTicket(),TimeToStr(OrderOpenTime(),TIME_DATE|TIME_MINUTES),OrderType(),OrderLots(),OrderSymbol(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit(),TimeToStr(OrderCloseTime(),TIME_DATE|TIME_MINUTES),OrderClosePrice(),OrderProfit(),OrderComment()); } } FileClose(handle); } void GetPriceAction() { int i,iOrderTicket; string sSymbol; double dHigh,dLow; for (i = 0; i <= OrdersTotal(); i++) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); iOrderTicket=OrderTicket(); sSymbol=OrderSymbol(); dHigh=iHigh(sSymbol,PERIOD_M1,1); dLow=iLow(sSymbol,PERIOD_M1,1); WriteLog(sSymbol+iOrderTicket,DoubleToStr(dHigh,4)+","+DoubleToStr(dLow,4)); } return(0); } void WriteLog(string FileName,string sLine) { int handle=FileOpen(FileName+".csv",FILE_CSV|FILE_WRITE|FILE_READ,","); string DateStamp=TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES); if(handle>0) { FileSeek(handle,0,SEEK_END); FileWrite(handle,DateStamp+","+sLine); FileClose(handle); } }
Sample
Analysis
Market Information Used:
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
Other Features:
Uses files from the file system
It writes information to file