ClosingLots

Author: © 2018, Alexey Viktorov
0 Views
0 Downloads
0 Favorites
ClosingLots
ÿþ//+------------------------------------------------------------------+

//|                                                  ClosingLots.mq5 |

//|                                          © 2018, Alexey Viktorov |

//|                     https://www.mql5.com/ru/users/alexeyvik/news |

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

#property copyright "© 2018, Alexey Viktorov"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.1"

#property indicator_chart_window

#property indicator_plots 0



#define IMG_WIDTH  150

#define IMG_WIDTH1 90

#define IMG_HEIGHT 200

#define dts(A) DoubleToString(A, 2)



sinput int    font_Size = 12;             //   07<5@ H@8DB0

sinput color  textColor = clrDarkOrchid;  //  &25B B5:AB0

int rowHeight = font_Size+2;

//--- 5@5<5==K5 4;O, B8?0 Canvas

uint extImg[IMG_WIDTH*IMG_HEIGHT];

uint extImg1[IMG_WIDTH1*IMG_HEIGHT];

ENUM_COLOR_FORMAT clr_format = COLOR_FORMAT_ARGB_NORMALIZE;

int strWidth = 20;  //  BABC? >B 25@E0 >:=0

uint colorARGB;     //  5@5<5==0O 4;O F25B0 2 2845 ARGB

uint w, h;          //  5@5<5==K5 4;O ?>;CG5=8O @07<5@>2 B5:AB>2KE AB@>:  



 string ssString[8] = {"A53>4=O "

                     , "?>A;54=85 B@8 4=O "

                     , "B5:CICN =545;N "

                     , "B5:CI89 <5AOF "

                     , "?>A;54=85 3 <5AOF0 "

                     , "?>A;54=85 6 <5AOF52 "

                     , "B5:CI89 3>4 "

                     , "25AL ?5@8>4 "};

 int fontSize;

 double lots[8] = {0};

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   fontSize = font_Size < 8 ? 8 : font_Size > 16 ? 16 : font_Size;

//---

  colorARGB = ColorToARGB(textColor, 250);

  bitmapCreate("aaa", 100);

  bitmapCreate("bbb", 10);

   ArrayFill(extImg, 0, IMG_WIDTH*IMG_HEIGHT, 0);

   textComment("0:@KB> 70 ", IMG_WIDTH, 0, extImg);

   textComment(ssString[0], IMG_WIDTH, 1, extImg);

   textComment(ssString[1], IMG_WIDTH, 2, extImg);

   textComment(ssString[2], IMG_WIDTH, 3, extImg);

   textComment(ssString[3], IMG_WIDTH, 4, extImg);

   textComment(ssString[4], IMG_WIDTH, 5, extImg);

   textComment(ssString[5], IMG_WIDTH, 6, extImg);

   textComment(ssString[6], IMG_WIDTH, 7, extImg);

   textComment(ssString[7], IMG_WIDTH, 8, extImg);

   ResourceCreate("::aaa", extImg, IMG_WIDTH, IMG_HEIGHT, 0, 0, IMG_WIDTH, clr_format);

  //ChartRedraw();

//---

   return(INIT_SUCCEEDED);

  }

void bitmapCreate(string name, long distance_X)

{

  ObjectCreate(0, name, OBJ_BITMAP_LABEL, 0, 0, 0);

  ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_RIGHT_UPPER);

  ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);

  ObjectSetInteger(0, name, OBJPROP_XDISTANCE, distance_X);

  ObjectSetInteger(0, name, OBJPROP_YDISTANCE, strWidth);

  //ObjectSetInteger(0, name, OBJPROP_SELECTABLE, true);

  //ObjectSetInteger(0, name, OBJPROP_SELECTED, true);

  ObjectSetString(0, name, OBJPROP_BMPFILE, "::"+name);

 

}/*******************************************************************/



void textComment(string text, int width, int str, uint &extImg_N[])

{

 TextSetFont("Arial", -fontSize*10, FW_LIGHT|FONT_ITALIC, 0);

 TextGetSize(text, w, h);

 TextOut(text, width, rowHeight+h*str, TA_RIGHT|TA_VCENTER, extImg_N, width, IMG_HEIGHT, colorARGB, clr_format);

}/*******************************************************************/



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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   calculate();

   ArrayFill(extImg1, 0, IMG_WIDTH1*IMG_HEIGHT, 0);

   textComment(dts(lots[0])+" ", IMG_WIDTH1, 1, extImg1);

   textComment(dts(lots[1])+" ", IMG_WIDTH1, 2, extImg1);

   textComment(dts(lots[2])+" ", IMG_WIDTH1, 3, extImg1);

   textComment(dts(lots[3])+" ", IMG_WIDTH1, 4, extImg1);

   textComment(dts(lots[4])+" ", IMG_WIDTH1, 5, extImg1);

   textComment(dts(lots[5])+" ", IMG_WIDTH1, 6, extImg1);

   textComment(dts(lots[6])+" ", IMG_WIDTH1, 7, extImg1);

   textComment(dts(lots[7])+" ", IMG_WIDTH1, 8, extImg1);

   ResourceCreate("::bbb", extImg1, IMG_WIDTH1, IMG_HEIGHT, 0, 0, IMG_WIDTH1, clr_format);

  //ChartRedraw();

//--- return value of prev_calculated for next call

   return(rates_total);

}/*******************************************************************/



void profitGetDate(datetime fromDate, datetime toDate, int index, double &temp[])

{

 double summSyze = 0;

 if(!HistorySelect(fromDate, toDate))

  Print(__FUNCTION__, " ********* ", GetLastError());

  int dealsTotal = HistoryDealsTotal();

   for(int i = 0; i < dealsTotal; i++)

   {

    ulong dealTicket = HistoryDealGetTicket(i);

    ENUM_DEAL_ENTRY dealEntry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger(dealTicket, DEAL_ENTRY);

    string _symbol = HistoryDealGetString(dealTicket, DEAL_SYMBOL);

    if(dealEntry == DEAL_ENTRY_OUT)

    {

     summSyze += NormalizeDouble(HistoryDealGetDouble(dealTicket, DEAL_VOLUME), (int)log10(SymbolInfoDouble(_symbol, SYMBOL_VOLUME_STEP)));

    }

   }

  temp[index] = summSyze;

}/*******************************************************************/



void calculate()

{

 ArrayInitialize(lots, 0);

 datetime endTime;

 datetime timeArr[];

  MqlDateTime mqlDateTime = {0}, tempStruct = {0};

  TimeCurrent(mqlDateTime);

//--- 70 A53>4=O

   if(CopyTime(_Symbol, PERIOD_D1, TimeCurrent(), 1, timeArr) <= 0)

    return;

   endTime = timeArr[0]+PeriodSeconds(PERIOD_D1);

   profitGetDate(timeArr[0], endTime, 0, lots);

//--- 70 ?>A;54=85 B@8 4=O

   if(CopyTime(_Symbol, PERIOD_D1, TimeCurrent(), 3, timeArr) <= 0)

    return;

  endTime = timeArr[2]+PeriodSeconds(PERIOD_D1);

   profitGetDate(timeArr[0], endTime, 1, lots);

//--- 70 B5:CICN =545;N

   if(CopyTime(_Symbol, PERIOD_W1, TimeCurrent(), 1, timeArr) <= 0)

    return;

  endTime = timeArr[0]+PeriodSeconds(PERIOD_W1);

   profitGetDate(timeArr[0], endTime, 2, lots);

//--- 70 B5:CI89 <5AOF

   if(CopyTime(_Symbol, PERIOD_MN1, TimeCurrent(), 1, timeArr) <= 0)

    return;

  endTime = timeArr[0]+PeriodSeconds(PERIOD_MN1);

   profitGetDate(timeArr[0], endTime, 3, lots);

//--- 70 ?>A;54=85 3 <5AOF0

   if(CopyTime(_Symbol, PERIOD_MN1, TimeCurrent(), 3, timeArr) <= 0)

    return;

  endTime = timeArr[2]+PeriodSeconds(PERIOD_MN1);

   profitGetDate(timeArr[0], endTime, 4, lots);

//--- 70 ?>A;54=85 6 <5AOF52

   if(CopyTime(_Symbol, PERIOD_MN1, TimeCurrent(), 6, timeArr) <= 0)

    return;

   tempStruct.year = mqlDateTime.year;

  endTime = timeArr[5]+PeriodSeconds(PERIOD_MN1);

   profitGetDate(timeArr[0], endTime, 5, lots);

//--- 70 B5:CI89 3>4

  tempStruct.year = mqlDateTime.year;

   if(CopyTime(_Symbol, PERIOD_MN1, StructToTime(tempStruct), TimeCurrent(), timeArr) <= 0)

    return;

  endTime = timeArr[2]+PeriodSeconds(PERIOD_MN1);

  datetime ds=StructToTime(tempStruct);

  profitGetDate(StructToTime(tempStruct), endTime, 6, lots);

//--- 70 25AL ?5@8>4

   if(CopyTime(_Symbol, PERIOD_D1, TimeCurrent(), 1, timeArr) <= 0)

    return;

   endTime = timeArr[0]+PeriodSeconds(PERIOD_D1);

  profitGetDate(0, endTime, 7, lots);

//--- !!!!

}/*******************************************************************/



void OnDeinit(const int reason)

{

 ObjectsDeleteAll(ChartID(), 0, OBJ_BITMAP_LABEL);

}/*******************************************************************/

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