GetHistoryInd

Author:
GetHistoryInd
Price Data Components
Series array that contains open time of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Orders Execution
Checks for the total of open orders
Miscellaneous
Uses files from the file systemIt writes information to file
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 supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---