Anchor indicator ChartEvent - page 2

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

Great man,

The formula below let me draw as many lines as I click on the chart, but I would like to limit to only two lines. Any idea?

//+------------------------------------------------------------------+
//|                                                          T7A.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="ArrowBuy";   // 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++);
         
         //--- 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 LINE 1
            if(!ObjectCreate(0,buy_sign_name, OBJ_HLINE,0,obj_time,candle[barPos].low-(20*tickSize))) //OBJ_ARROW_BUY
             
              {
               Print("Failed to create buy sign!");
               return;
              }
            
           }
           
           
        }
     }
//---
   Comment(comment);
          
       }
Alain Verleyen
39024
Alain Verleyen  
Marreta:

Great man,

The formula below let me draw as many lines as I click on the chart, but I would like to limit to only two lines. Any idea?

         static uint sign_obj_cnt=0;
         if(sign_obj_cnt>=2) return;
         string buy_sign_name="buy_sign_"+IntegerToString(sign_obj_cnt++);
It should be what you want.
Marreta
96
Marreta  

It was exactly what I wanted . Now the formula gives  two lines below the lows of the first two clicks on the chart. Is there any way to have the first line below the low and the second above the high of the candle relative to the second point clicked on the chart? It would have to be separate in the formula ? I tryed calling the " case CHARTEVENT_CLICK:" again and rename everything, but then it shows a message saying "case value already used".

What I'm trying to get and may be usefull to the community is two lines which will give me the entry and stoploss values, by clicking on the chart to set these points (high and low) with offsets (in pips) , to then calculate profit targets. So a tool easy to use for scalping.

 

Thanks for helping me 

Here is the formula until now:

//+------------------------------------------------------------------+
//|                                                          T7B.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="ArrowBuy";   // 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=0;
         
         
         if( sign_obj_cnt>=2) return;
         string buy_sign_name="buy_sign_"+IntegerToString(sign_obj_cnt++);
         
         //--- 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 LINE 1
            if(!ObjectCreate(0,buy_sign_name, OBJ_HLINE,0,obj_time,candle[barPos].low-(20*tickSize))) //OBJ_ARROW_BUY
             
              {
               Print("Failed to create buy sign!");
               return;
              }
            
           }
           
            
        }
               
     }
//---
   Comment(comment);
          
       }
12
To add comments, please log in or register