Please help me retrieve last time price was same as current Bid

 

Tried using iClose, however it is only good for "candle close price", I want whenever it actually happened so as to be more precise.

So I went the HLINE route, and cant find a way to just give me the last time the current HLINE touched the same bid price. Thought about drawing another VLINE on the price, only to find out I need to input an actual time.

So what route would be the best? IClose, HLINE and retrieve the first time in which it touched the line, or cross the HLINE with the VLINE at the correct time that the Bid last happened? Seems its IClose, however how do I code it to keep going back in time until it finds it?

if  iClose(Symbol(), PERIOD_M1,1) != Bid;

then keep searching backwards until you find the same price. How to do this? Figured it has to be something similar to the for loop used to count orders:

   for(int a=OrdersTotal()-1;a>=0;a--)
     {

However I'm not that good at this and its taking me forever, its super late with a super headache, can anyone please point me out here? How'd you retrieve the last time the price was the same as the current Bid price?

 

Closest I could find is a script from https://www.forexfactory.com/showthread.php?t=283210:

//+------------------------------------------------------------------+
//|                                              Visual MP count.mq4 |
//+------------------------------------------------------------------+

#property show_inputs

#include <WinUser32.mqh>

extern int        LookbackCandles      = 2000;
//extern double     StartingPrice        = Bid;
extern color      LineColor            = Purple;

double MathModCorrect;

string     ccy, sym, IndiName, objname;
int        dig, tf, tmf, cnt;
double     spr, pnt, tickval, bidp, askp, minlot, lswap, sswap, y0, y1;
datetime   x0, x1, px0=0, px1=0;
double     py0=0, py1=0;

//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+

  ccy     = Symbol();
  tmf     = Period();
  bidp    = MarketInfo(ccy,MODE_BID);
  askp    = MarketInfo(ccy,MODE_ASK);
  pnt     = MarketInfo(ccy,MODE_POINT);
  dig     = MarketInfo(ccy,MODE_DIGITS);
  spr     = MarketInfo(ccy,MODE_SPREAD);
  tickval = MarketInfo(ccy,MODE_TICKVALUE);
  minlot  = MarketInfo(ccy,MODE_MINLOT);
  lswap   = MarketInfo(ccy,MODE_SWAPLONG);
  sswap   = MarketInfo(ccy,MODE_SWAPSHORT);
  if (dig == 3 || dig == 5) {
    pnt     *= 10;
    spr     /= 10;
    tickval *= 10;
  }  

  objname = "CountLine";

  if (ObjectFind(objname) >= 0)   ObjectDelete(objname);
  x0 = Time[LookbackCandles];
  x1 = Time[0];
  y0 = (WindowPriceMax()+WindowPriceMin())/2;
  if (Bid > 0)   y0 = Bid;
  y1 = y0;
  ObjectCreate(objname,OBJ_TREND,0,x0,y0,x1,y1);
  ObjectSet(objname,OBJPROP_COLOR,LineColor);
  ObjectSet(objname,OBJPROP_RAY,false);
  WindowRedraw();

  return(0);
}

//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  if (ObjectFind(objname) >= 0)   ObjectDelete(objname);
  WindowRedraw();
  return(0);
}

//+------------------------------------------------------------------+
int start()  {
//+------------------------------------------------------------------+
  while (!IsStopped())   {
    x0 = ObjectGet(objname,OBJPROP_TIME1);
    x1 = ObjectGet(objname,OBJPROP_TIME2);
    y0 = ObjectGet(objname,OBJPROP_PRICE1);
    y1 = ObjectGet(objname,OBJPROP_PRICE2);
    if (x1<x0)   break;
    if (x0 != px0 || x1 != px1 || y0 != py0 || y1 != py1)   {
      WindowRedraw();
      cnt=0;
      int i0 = iBarShift(ccy,tmf,x0,false);
      int i1 = iBarShift(ccy,tmf,x1,false);
      for (int i=i0; i>=i1; i--)   {
        double prc = ObjectGetValueByShift(objname,i); 
        if (prc <= High[i] && prc >= Low[i])   cnt++;
      }
     //'string objdesc = NumberToStr(NumberToStr(cnt,"'Count = 'T6") + NumberToStr(i0-i1+1,"' of 'T6") 
     //               + NumberToStr(y0,"'   ('T5."+NumberToStr(dig,"T2")+"', '") + NumberToStr(y1,"T5."+NumberToStr(dig,"T2")+"')'");
     
     string objdesc = StringConcatenate("COUNT ", (cnt) , "  of total ",(i0-i1+1) , " line_level ", (y0) ," price 2 ", (y1));
      bool b = false;
      while (!b)                     
        b = ObjectSetText(objname,objdesc,12,"Arial",White);
      WindowRedraw();
      px0=x0;  px1=x1;   py0=y0;   py1=y1;
    }     
  }
  return(0);
}

However I cant effectively extrapolate the actual logic involved . Any experience coders can point out whats that script doing that actually keeps counting back in time or any other way help me out finding the last time price was the same as current bid?

Really appreciate your time reading . Thanks.

 
My HLINE attempt:
ObjectCreate(ChartID(),"objname",OBJ_HLINE,0, TimeCurrent() ,Bid);
ObjectSet("objname",OBJPROP_COLOR,Purple);
ObjectMove(ChartID(), "objname",0,TimeCurrent(),Bid);
WindowRedraw();
How do I get this to print out the last time the price was same as current bid which would be the last time the drawn line touched the line graph? This wouldve been what I thought the most logical approach.
 
nadiawicket:

Tried using iClose, however it is only good for "candle close price", I want whenever it actually happened so as to be more precise.

So I went the HLINE route, and cant find a way to just give me the last time the current HLINE touched the same bid price.

Since neither store ticks, you can't know the actual time, only which candle and that candle's start time.
int iLastTouched(int iBeg=1){
   while(iBeg < Bars) if(High[iBeg] >= Bid && Bid >= Low[iBeg]) break;
   return iBeg;
}