Stocks and their levels

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Stocks and their levels
ÿþ//+------------------------------------------------------------------+

//|                                      Stocks and their levels.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

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

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.003"

#property script_show_inputs

//--- input parameters

input double   InpPrice = 50.10;    // Price

input double   InpLots  = 20;       // Lots

input double   InpStep  = 0.5;      // Step (in price)

//---

string   m_prefix = "Stocks and their levels ";

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

//| Script program start function                                    |

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

void OnStart()

  {

   ObjectsDeleteAll(ChartID(),m_prefix,0,OBJ_HLINE);

//---

   string symbol_name=Symbol();

   int digits=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);

   double tick_size=SymbolInfoDouble(symbol_name,SYMBOL_TRADE_TICK_SIZE);

   double tick_value_loss=SymbolInfoDouble(symbol_name,SYMBOL_TRADE_TICK_VALUE_LOSS);

//---

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

     {

      double a=(double)(i+1);

      double b=InpStep*a;

      double count_ticks=b/tick_size;

      double money=count_ticks*tick_value_loss*InpLots;

      //--- loss

      double loss_price=InpPrice-b;

      HLineCreate(ChartID(),m_prefix+" loss "+IntegerToString(i+1),0,loss_price,clrRed,STYLE_DASH,1,"- $"+DoubleToString(money,digits));

      //--- profit

      double profit_price=InpPrice+b;

      HLineCreate(ChartID(),m_prefix+" profit "+IntegerToString(i+1),0,profit_price,clrBlue,STYLE_DASH,1,"+ $"+DoubleToString(money,digits));

      int d=0;

     }

  }

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

//| Create the horizontal line                                       |

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

bool HLineCreate(const long            chart_ID=0,          // chart's ID

                 const string          name="HLine",        // line name

                 const int             sub_window=0,        // subwindow index

                 double                price=0,             // line price

                 const color           clr=clrRed,          // line color

                 const ENUM_LINE_STYLE style=STYLE_SOLID,   // line style

                 const int             width=1,             // line width

                 const string          text="",             // text

                 const bool            back=false,          // in the background

                 const bool            selection=false,     // highlight to move

                 const bool            hidden=true,         // hidden in the object list

                 const long            z_order=0)           // priority for mouse click

  {

//--- if the price is not set, set it at the current Bid price level

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- reset the error value

   ResetLastError();

//--- create a horizontal line

   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price))

     {

      Print(__FUNCTION__,

            ": failed to create a horizontal line! Error code = ",GetLastError());

      return(false);

     }

//--- set line color

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- set line display style

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

//--- set line width

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

//--- set the text

   if(text!="")

      ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

//--- display in the foreground (false) or background (true)

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- enable (true) or disable (false) the mode of moving the line by mouse

//--- when creating a graphical object using ObjectCreate function, the object cannot be

//--- highlighted and moved by default. Inside this method, selection parameter

//--- is true by default making it possible to highlight and move the object

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- hide (true) or display (false) graphical object name in the object list

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- set the priority for receiving the event of a mouse click in the chart

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- successful execution

   return(true);

  }

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

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