Download MetaTrader 5

Anchor indicator ChartEvent

To add comments, please log in or register
Marreta
90
Marreta  

Hi, anyone could help me to find a way to anchor this indicator to the low of the candle, when i click on chart?

Thanks

input string          InpName="ArrowBuy";   // Object name
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Print("The expert with name",MQL5InfoString(MQL5_PROGRAM_NAME),"is running");
//---
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
 void OnChartEvent(const int id, 
                  const long   &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   string comment="Last event: ";
//--- select event on chart
   switch(id)
     {
            
      //--- 1
      case CHARTEVENT_CLICK:
        {
         comment+="6) mouse click on chart";
         //--- object counter 
         static uint sign_obj_cnt;
         string buy_sign_name="buy_sign_"+IntegerToString(sign_obj_cnt+1);
         //--- coordinates 
         int mouse_x=(int)lparam;
         int mouse_y=(int)dparam;
          
         //--- time and price
         datetime obj_time;
         double obj_price;
          
         int sub_window;
         //--- convert the X and Y coordinates to the time and price values
         if(ChartXYToTimePrice(0,mouse_x,mouse_y,sub_window,obj_time,obj_price) )
            {
            //--- create object
            if(!ObjectCreate(0,buy_sign_name,OBJ_ARROW_BUY,0,obj_time,obj_price)) //OBJ_ARROW_BUY
            
              {
               Print("Failed to create buy sign!");
               return;
              }
            
           }
           
        }
     }
//---
   Comment(comment);
          
       }

Alain Verleyen
Moderator
33615
Alain Verleyen  

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Alain Verleyen
Moderator
33615
Alain Verleyen  
Marreta:

Hi, anyone could help me to find a way to anchor this indicator to the low of the candle, when i click on chart?

Thanks


This is not an indicator.
Marreta
90
Marreta  

Hi angevoyageur, I'm new to this forum an to MQL5, sorry for the SRC, i did not know about it.

I know this is not an  indicator, but how should I call it? A tool, script, expert? Is there a better place on this forum to post this topic? 

Thanks 

Alain Verleyen
Moderator
33615
Alain Verleyen  
Marreta:

Hi angevoyageur, I'm new to this forum an to MQL5, sorry for the SRC, i did not know about it.

I know this is not an  indicator, but how should I call it? A tool, script, expert? Is there a better place on this forum to post this topic? 

Thanks 

It's fine to post here, but what you want is not clear.
Marreta
90
Marreta  

Ok let me try to be more clear. The indicator/tool/expert I posted plots an arrowbuy when I click on Chart with the left mouse buttom.

What I want is to have the arrowbuy to be placed below the low of the candle relative to the point that I clicked on the chart, even if the exact point that I clicked is way down below the low of the candle, I want the arrow buy to be anchored to the low of the candle, like some magnet tool.

Thanks again. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events - Reference on algorithmic/automated trading language for MetaTrader 5
Stuart Browne
6686
Stuart Browne  
In your ObjectCreate, why not just use the obj_time from ChartXYToTimePrice and then use the Low of the bar that corresponds to that time?
Marreta
90
Marreta  

Thanks for your help Filter, now I'd like to know if it's possible to have a second object when clicking  on the chart for the second time.

The formula below creates a horizontal line two ticks below the low of the candle when I click on the chart, then if I click again on the chart it removes the line and creates a new line at the new low relative to this new click.

I'd like to keep the first line when clicking for the second time, so I would have two lines , and then if clicking againg on the chart (Third Time) start the process again. 

I just don't have any idea how to achieve that, so I really appreciate if someone could guide me through it. 

Thanks

 

//+------------------------------------------------------------------+
//|                                                           T6.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"//
input string          InpName="HLineLow";   // Object name
//---
MqlRates candle[];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnInit()
  {
//---
   ArraySetAsSeries(candle,true);
   
  }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
 void OnChartEvent(const int id, 
                  const long   &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   //---
   int visibleBars = (int)ChartGetInteger(0,CHART_VISIBLE_BARS,0);
   //---
   CopyRates(_Symbol,_Period,0,visibleBars,candle);
   //---
   double tickSize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
//---   
   string comment="Last event: ";
//--- select event on chart
   switch(id)
     {
            
      //--- 1
      case CHARTEVENT_CLICK:
        {
         comment+="6) mouse click on chart";
         //--- object counter 
         static uint sign_obj_cnt;
         string buy_sign_name="buy_sign_"+IntegerToString(sign_obj_cnt+1);
         //--- coordinates 
         int mouse_x=(int)lparam;
         int mouse_y=(int)dparam;
          
         //--- time and price
         datetime obj_time;
         double obj_price;
          
         int sub_window;
         //--- convert the X and Y coordinates to the time and price values
         if(ChartXYToTimePrice(0,mouse_x,mouse_y,sub_window,obj_time,obj_price) )
            {
            //---
            int barPos = Bars(_Symbol,_Period,obj_time,TimeCurrent());
            //--- create object
            if(!ObjectCreate(0,buy_sign_name, OBJ_HLINE,0,obj_time,candle[barPos].low-(20*tickSize))) //OBJ_HLINE
            
              {
               Print("Failed to create buy sign!");
               return;
              }
            
           }
           
        }
     }
//---
   Comment(comment);
          
       }
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Reference on algorithmic/automated trading language for MetaTrader 5
Alain Verleyen
Moderator
33615
Alain Verleyen  
Marreta:

Thanks for your help Filter, now I'd like to know if it's possible to have a second object when clicking  on the chart for the second time.

The formula below creates a horizontal line two ticks below the low of the candle when I click on the chart, then if I click again on the chart it removes the line and creates a new line at the new low relative to this new click.

I'd like to keep the first line when clicking for the second time, so I would have two lines , and then if clicking againg on the chart (Third Time) start the process again. 

I just don't have any idea how to achieve that, so I really appreciate if someone could guide me through it. 

Thanks

 

Your sign_obj_cnt is never increased.
Marreta
90
Marreta  

Hi angevoyageur, could you give an example how to do it, I tryed to find it on the web but no success.

Thanks and happy new year!

Alain Verleyen
Moderator
33615
Alain Verleyen  
Marreta:

Hi angevoyageur, could you give an example how to do it, I tryed to find it on the web but no success.

Thanks and happy new year!

         string buy_sign_name="buy_sign_"+IntegerToString(sign_obj_cnt++);
12
To add comments, please log in or register