How do I get the same bar counts of the mouse tracker?

 

Hi!

Mouse tracker

How do I get the exact same value of bars count the tracker provides? Notice that this tracker also gives information about future "invisible" bars:

Tracker 2

 
Martin Bittencourt:

Hi!


How do I get the exact same value of bars count the tracker provides? Notice that this tracker also gives information about future "invisible" bars:


Hello . 
Try this 

bool mouse_scroll_fix=false,dragging=false;
int  origin_x=0,origin_y=0;
int  pre_mcx=0,pre_mcy=0;
string pre_mcc="0";
int origin_sub=0;
datetime origin_time=0;
double origin_price=0;
int origin_bar=0;
int OnInit()
  {
  
  ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); 
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  if(id==CHARTEVENT_MOUSE_MOVE){
  int mcx=(int)lparam;//mouse x
  int mcy=(int)dparam;//mouse y
  string mcc=sparam;//mouse click code
  //if not dragging 
  if(!dragging){
  //mousedown left now but was not pressed before 
    if(mcc=="1"&&pre_mcc=="0"){
    //dragging on 
      dragging=true;
    //do we need to disable mouse scroll ? 
      mouse_scroll_fix=(bool)ChartGetInteger(ChartID(),CHART_MOUSE_SCROLL);
      if(mouse_scroll_fix){ChartSetInteger(ChartID(),CHART_MOUSE_SCROLL,false);}
    //origin of dragging 
      origin_x=mcx;origin_y=mcy;
      ChartXYToTimePrice(ChartID(),origin_x,origin_y,origin_sub,origin_time,origin_price);
      origin_bar=iBarShift(_Symbol,_Period,origin_time,true);
    }//mousedown left now but was not pressed before ends here
  }//if not dragging ends here
  //if dragging
  if(dragging){
  datetime mc_time=0;
  int mc_sub=0;
  double mc_price=0.0;
  ChartXYToTimePrice(ChartID(),mcx,mcy,mc_sub,mc_time,mc_price);
  int mc_bar=find_bar(iTime(_Symbol,_Period,0),mc_time);
  Comment("["+IntegerToString(origin_bar)+"]->["+IntegerToString(mc_bar)+"]");
  //cancel dragging 
  if(mcc!="1"){
  Comment("");
  dragging=false;
  if(mouse_scroll_fix){ChartSetInteger(ChartID(),CHART_MOUSE_SCROLL,true);mouse_scroll_fix=false;}
  }//cancel dragging ends here
  }//if dragging ends here
  pre_mcc=mcc;
  pre_mcx=mcx;
  pre_mcy=mcy;
  } 
  }
//+------------------------------------------------------------------+

int find_bar(datetime recent_bar,datetime mouse_time){
if(mouse_time<=recent_bar){
return(iBarShift(_Symbol,_Period,mouse_time,true));
}else{
int last=((int)mouse_time/PeriodSeconds())-((int)recent_bar/PeriodSeconds());
return((-1)*last);
}
}
 
Lorentzos Roussos #:

Hello . 
Try this 

How can I know when to stop the trade