OpenPendingOrderTime

Author: Copyright 2016, Alexey Volchanskiy
Price Data Components
Orders Execution
It automatically opens orders when conditions are reached
Miscellaneous
Uses files from the file systemIt issuies visual alerts to the screenIt writes information to file
0 Views
0 Downloads
0 Favorites
OpenPendingOrderTime
ÿþ//+------------------------------------------------------------------+

//|                                         OpenPendingOrderTime.mq4 |

//|                               Copyright 2016, Alexey Volchanskiy |

//|                                          https://mql.gnomio.com/ |

//+------------------------------------------------------------------+

#property copyright "Copyright 2016, Alexey Volchanskiy"

#property link      "https://mql.gnomio.com/"

#property version   "1.00"

#property strict



#include <stdlib.mqh>

#property show_inputs

#property strict



enum ETypePendingOrder {BuyLimit=2,SellLimit,BuyStop,SellStop};

string PendingOrderNames[]={"","","BuyLimit","SellLimit","BuyStop","SellStop"};



input  ETypePendingOrder TypePending=BuyLimit;

input  double Lot=0.1;

extern int OrdersCount=10;

extern int Pause=2000;

extern int OpenCloseDelay=1000;

extern int Shift=500;



string GetMyLastError2()

  {

   int err=GetLastError();

   string serr=ErrorDescription(err);

   return(serr);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

string OpenClose(int shift)

  {

   string str;

   double realShift;

   if(TypePending== SellLimit|| TypePending == BuyStop)

      realShift = shift * Point();

   else

      realShift= -shift * Point();

   double Price = NormalizeDouble(Bid+realShift,Digits());

   uint PrevTime= GetTickCount();

   int Ticket=OrderSend(Symbol(),TypePending,Lot,Price,0,0,0);

   PrevTime=GetTickCount()-PrevTime;

   if(Ticket==-1)

     {

      Print("Error of open order: ",GetMyLastError2());

      return "";

     }

   Sleep(OpenCloseDelay);

   str=IntegerToString(PrevTime);

   PrevTime = GetTickCount();

   bool res = OrderDelete(Ticket);

   PrevTime = GetTickCount() - PrevTime;

   if(res)

      str=str+"      "+IntegerToString(PrevTime);

   else

      str=str+" Can not delete pending order "+IntegerToString(Ticket);

   return str;

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OnStart()

  {

   string dts= TimeToStr(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS);

   int nchar = StringFind(dts,":");

   string dts1=StringSetChar(dts,nchar,'-');

   nchar=StringFind(dts1,":");

   string dts2=StringSetChar(dts1,nchar,'-');

   string fileName="OpenPendingOrderTime_"+IntegerToString(AccountNumber())+".log";

   Print("fileName = ",fileName);

   int handle=FileOpen(fileName,FILE_READ|FILE_CSV|FILE_WRITE,' ');

   if(handle<1)

     {

      Alert("Can not open log-file "+fileName);

      return;

     }

   FileSeek(handle,0,SEEK_END);

   FileWrite(handle,dts," ",PendingOrderNames[(int)TypePending]);

   FileWrite(handle,"Open,ms Close,ms");



   while(!IsStopped())

     {

      Comment(WindowExpertName()+":  "+IntegerToString(OrdersCount)+" orders in progress");

      FileWrite(handle,OpenClose(Shift));

      OrdersCount--;

      if(OrdersCount<=0)

         break;

      Sleep(Pause);

     }

   FileWrite(handle,"---------------");

   FileWrite(handle,"");

   FileClose(handle);

   Comment("");

  }

//+------------------------------------------------------------------+

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 ---