Price Data Components
Orders Execution
Miscellaneous
0
Views
0
Downloads
0
Favorites
GetHistoryInd
//+------------------------------------------------------------------+
//|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);
}
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---