HLine Greed Percent

Author: Copyright © 2022, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
HLine Greed Percent
ÿþ//+------------------------------------------------------------------+

//|                                          HLine Greed Percent.mq5 |

//|                              Copyright © 2022, Vladimir Karputov |

//|                      https://www.mql5.com/en/users/barabashkakvn |

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

#property copyright "Copyright © 2022, Vladimir Karputov"

#property link      "https://www.mql5.com/en/users/barabashkakvn"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

//--- input parameters

input group             "Main settings"

input double               InpMainPrice            = 250.0;          // Main price

input double               InpStep                 = 10.0;           // Step (%)

input uchar                InpAmountUp             = 9;              // Amount Up

input uchar                InpAmountDown           = 3;              // Amount Down

input group             "Line parameters"

input color                InpUpColor              = clrLimeGreen;   // Up: Line color

input ENUM_LINE_STYLE      InpUpStyle              = STYLE_DOT;      // Up: Line style

input int                  InpUpWidth              = 1;              // Up: Line width

input color                InpMainColor            = clrMediumPurple;// Main: Line color

input ENUM_LINE_STYLE      InpMainStyle            = STYLE_SOLID;    // Main: Line style

input int                  InpMainWidth            = 1;              // Up: Line width

input color                InpDownColor            = clrLimeGreen;   // Down: Line color

input ENUM_LINE_STYLE      InpDownStyle            = STYLE_DOT;      // Down: Line style

input int                  InpDownWidth            = 1;              // Down: Line width

//---

string   m_prefix="HLine Greed Percent ";

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- main

   double price=InpMainPrice;

   string name=DoubleToString(price,Digits());

   HLineCreate(ChartID(),m_prefix+name,0,price,InpMainColor,InpMainStyle,InpMainWidth);

//--- up

   for(int i=1; i<InpAmountUp+1; i++)

     {

      price=InpMainPrice+InpMainPrice*InpStep/100.0*i;

      name=DoubleToString(price,Digits());

      HLineCreate(ChartID(),m_prefix+name,0,price,InpUpColor,InpUpStyle,InpUpWidth);

     }

//--- down

   for(int i=1; i<InpAmountDown+1; i++)

     {

      price=InpMainPrice-InpMainPrice*InpStep/100.0*i;

      name=DoubleToString(price,Digits());

      HLineCreate(ChartID(),m_prefix+name,0,price,InpDownColor,InpDownStyle,InpDownWidth);

     }

//---

   return(INIT_SUCCEEDED);

  }

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

//| Indicator deinitialization function                              |

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

void OnDeinit(const int reason)

  {

//---

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

  }

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

//| 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[])

  {

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

   return(rates_total);

  }

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

//| 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 bool            back=false,        // in the background

                 const bool            selection=true,    // 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);

   return(true);

  }

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

//| Move horizontal line                                             |

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

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

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

               double       price=0)      // line price

  {

//--- if the line price is not set, move it to the current Bid price level

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- reset the error value

   ResetLastError();

//--- move a horizontal line

   if(!ObjectMove(chart_ID,name,0,0,price))

     {

      Print(__FUNCTION__,

            ": failed to move the horizontal line! Error code = ",GetLastError());

      return(false);

     }

//--- successful execution

   return(true);

  }

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

Comments