mouse move

 

hi

I want to knowif there is a way to change the color of the candle that mouse is on it.

some thing like mouse hover.

 
pumper:

hi

I want to knowif there is a way to change the color of the candle that mouse is on it.

some thing like mouse hover.

So there's two things to do,

1. Mouse hover above candle : a little bit difficult : OnChartEvent with CHARTEVENT_MOUSE_MOVE, convert the chart pixels coordinates into time-price coordinates using  ChartXYToTimePrice, and get the candle data using Copy... functions.

2. Candle change color : this is difficult because we change the color of just one single candle :(.  

 

my indicator is something like this with no success:

//+------------------------------------------------------------------+
//|                                                candlecounter.mq5 |
//|                                   Copyright 2012, mohsen khashei |
//|                                              mkhasheiv@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, mohsen khashei"
#property link      "mkhasheiv@yahoo.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots 1                     //Number of graphic plots
#property indicator_type1 DRAW_COLOR_CANDLES    //Drawing style - color candles
#property indicator_color1  clrMediumVioletRed
//--- indicator buffers
double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtCloseBuffer[];
double ExtColorsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicators
   SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
   PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   return(0);
  }
//+------------------------------------------------------------------+
//| 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);
  }
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // Event identifier  
                  const long& lparam,   // Event parameter of long type
                  const double& dparam, // Event parameter of double type
                  const string& sparam  // Event parameter of string type
                  )
 {
//---
datetime md;
double mp;
 MqlRates rates[];
 int window=0;
if(id==CHART_EVENT_MOUSE_MOVE)
{
ChartXYToTimePrice(0,(int)lparam,(int)dparam,window,md,mp);
CopyRates(_Symbol,PERIOD_CURRENT,md,1,rates);
      ExtOpenBuffer[0]=rates[0].open;
      ExtHighBuffer[0]=rates[0].high;
      ExtLowBuffer[0]=rates[0].low;
      ExtCloseBuffer[0]=rates[0].close;
      ExtColorsBuffer[0]=0;
}
 

and another question:

my indicator only draw some objects on chart but when i want to use it multiple times in the second time all the objects of first instance are removed and the third indicator is not added to the chart?

 
pumper:

my indicator is something like this with no success:

Sorry, forgot to tell that you must use ChartSetInteger(), with CHART_EVENT_MOUSE_MOVE set to true. 

I'll answer your other Q later ;D

//+------------------------------------------------------------------+
//|                    find the highest bar since market is open.mq5 |
//|                                  Copyright 28 Jan 2013, phi.nuts |
//|                https://www.mql5.com/en/forum/10305#comment_416233 |
//+------------------------------------------------------------------+
#property copyright "Copyright 28 Jan 2013, phi.nuts "
#property link      "https://www.mql5.com/en/forum/10305#comment_416233"
#property version   "1.00"
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
  ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
  
  datetime time; double price; int win, bar; string txt="";
  MqlRates rates [];
  
  if(id==CHARTEVENT_MOUSE_MOVE)
     {
      txt="";
      txt="\nWhere's my cursor: x = "+lparam+"  y = "+dparam+" status = "+sparam;
      ChartXYToTimePrice(0,lparam,dparam,win,time,price);
      txt=txt+"\nWhere's my cursor: time = "+TimeToString(time,TIME_DATE|TIME_SECONDS)+
              "  price = "+DoubleToString(price,_Digits)+" window = "+win;
              
              
      if ( (bar = CopyRates (_Symbol, _Period, TimeCurrent(), time, rates)) > 0)
        {
        if (/*time == rates[0].time &&*/ price >= rates[0].low && price <= rates[0].high)
          {
          txt = txt+"\nyou are hover on candle "+(bar - 1);
          }
          else
          {
          txt = txt+"\n\nyou are outside the candle";
          }
        }
     }
   Comment(txt);

  }
//+------------------------------------------------------------------+

 

 

hi phi.nuts

I appreciate you but my real problem is how to change color in the event handler.

And please answer my other Q.

 
pumper:

hi phi.nuts

I appreciate you but my real problem is how to change color in the event handler.

And please answer my other Q.

That's what I have no idea, because you want to change a color of just a single candle.



and another question:

my indicator only draw some objects on chart but when i want to use it multiple times in the second time all the objects of first instance are removed and the third indicator is not added to the chart?

I hope I'm not misunderstood the problem.

I don't know why your third indicator is removed.

If you want to draw several objects with Object Functions,  you have to name them differently using some counting or using time. Example of using counting, is like: "my_object_1", "my_object_2", "my_object_3". and example of using time is like this

string name;

name = "my_object_"+ TimeToString (TimeLocal(), TIME_DATE|TIME_SECOND) ;

// or using GetTickCount()

name = "my_object_too_"+ GetTickCount();

Hope I don't misunderstood the problem.

 
thanks thats a good idea and I'll try it
 
phi nuts #:

Sorry, forgot to tell that you must use ChartSetInteger(), with CHART_EVENT_MOUSE_MOVE set to true. 

I'll answer your other Q later ;D

 


Thank You Millon Time 

Reason: