indicator position against right price axis only - page 2

 

OK,  I think I have something like you described . . .

 

 

 

 
RaptorUK:

OK,  I think I have something like you described . . .

 

 

 

 


Raptor, can't thank you enough. Very much appreciate the time and effort you take to help us.

I have got the indicator to work and yes similar to the one you have pictured.

I have to admit I am still struggling to understand why the labels are defined in this manner, I could not replicate the way I coded the lines which seemed to make sense (still this works)

//+------------------------------------------------------------------+
   //|                                                                  |
   //|                 Copyright © 1999-2008, MetaQuotes Software Corp. |
   //|                                         http://www.metaquotes.ru |
   //+------------------------------------------------------------------+
   //---- indicator settings
   #property       indicator_chart_window
   #property       indicator_buffers 0
   //----
   //---- indicator parameters
   extern int      timeframe         = 30;
   extern int      bars_forward      = 5;         //5 bars is 300 seconds
   extern int      font_size         = 9;
   extern int      LevelLine_length  = 5; //  times 60 seconds times Period()
   // exported variables
   extern string   note1 = "----timeframe----";
   extern string   help1 = "set to true to add this line to chart";
   extern bool     TF1_HIGH    = true;   // set true to display this level line
   extern bool     TF1_LOW     = true;   // set true to display this level line
   //---- indicator buffers
   //+------------------------------------------------------------------+
   //| Custom indicator initialization function                         |
   //+------------------------------------------------------------------+
   int init()
     {
     IndicatorShortName("HTF-levels");
   //---- initialization done
      return(0);
     }
   //+------------------------------------------------------------------+
   //| Custom indicator deinitialization function                       |
   //+------------------------------------------------------------------+
   int deinit()
  {
    ObjectDelete("TF1_HIGH");
    ObjectDelete("TF1_HIGH__label");
    ObjectDelete("TF1_LOW");
    ObjectDelete("TF1_LOW_LABEL");
    return(0);
  }
   //+------------------------------------------------------------------+
   //| Other timeframe line levels                                           |
   //+------------------------------------------------------------------+
   int start()
     {
      int nLimit, i;
      int nCountedBars;
      int ShiftDif;
      nCountedBars=IndicatorCounted();
   //---- check for possible errors
      if(nCountedBars<0)
         return(-1);
   //---- last counted bar will be recounted
      if(nCountedBars>0)
         nCountedBars--;
      nLimit=Bars-nCountedBars;
      //---- main loop
      for(i=0; i<nLimit; i++)        
   //---- Higher Time Frame (TF1) LEVEL LINES
    if (TF1_HIGH) // draw if true
    {
    if (ObjectFind("TF1_HIGH")== -1)   //  if Object doesn't exist create it
    ObjectCreate  ("TF1_HIGH", OBJ_TREND, 0, 0, 0, 0, 0);
    ObjectSet     ("TF1_HIGH", OBJPROP_RAY, false);
    ObjectSet     ("TF1_HIGH", OBJPROP_PRICE1, iHigh(NULL,timeframe,0));
    ObjectSet     ("TF1_HIGH", OBJPROP_PRICE2, iHigh(NULL,timeframe,0));
    ObjectSet     ("TF1_HIGH", OBJPROP_TIME1, (Time[0]+bars_forward*60*Period()));
    ObjectSet     ("TF1_HIGH", OBJPROP_TIME2, (Time[0]+bars_forward*60*Period()+LevelLine_length*60*Period()));
    ObjectSet     ("TF1_HIGH", OBJPROP_COLOR, Lime);
    ObjectSet     ("TF1_HIGH", OBJPROP_WIDTH,3);
    }
    {
    if (ObjectFind("TF1_HIGH_label") != -1)        ObjectDelete("TF1_HIGH_label"); // Delete old labels if present and draw new one 
    ObjectCreate  ("TF1_HIGH_label", OBJ_TEXT, 0, (Time[0]+bars_forward*60*Period()), iHigh(NULL, timeframe,0));
    ObjectSet     ("TF1_HIGH_label", OBJPROP_TIME1, (Time[0]+bars_forward*60*Period()));
    ObjectSet     ("TF1_HIGH_label", OBJPROP_COLOR, Lime);
    ObjectSetText ("TF1_HIGH_label", "TF1 HIGH", font_size, "Arial", Lime);  
    }
    if (TF1_LOW) // draw if true
    {
    if (ObjectFind("TF1_LOW")== -1)   //  if Object doesn't exist create it
    ObjectCreate  ("TF1_LOW", OBJ_TREND, 0, 0, 0, 0, 0);
    ObjectSet     ("TF1_LOW", OBJPROP_RAY, false);
    ObjectSet     ("TF1_LOW", OBJPROP_PRICE1, iLow(NULL,timeframe,0));
    ObjectSet     ("TF1_LOW", OBJPROP_PRICE2, iLow(NULL,timeframe,0));
    ObjectSet     ("TF1_Low", OBJPROP_TIME1, (Time[0]+bars_forward*60*Period())  );
    ObjectSet     ("TF1_Low", OBJPROP_TIME2, (Time[0]+bars_forward*60*Period()+LevelLine_length*60*Period() ));
    ObjectSet     ("TF1_Low", OBJPROP_COLOR, Lime);
    ObjectSet     ("TF1_Low", OBJPROP_WIDTH,3);
    }
    {
    if (ObjectFind("TF1_LOW_label") != -1)    ObjectDelete("TF1_LOW_label"); // Delete old labels if present and draw new one     
    ObjectCreate  ("TF1_LOW_label", OBJ_TEXT, 0, (Time[0]+bars_forward*60*Period()), iLow(NULL, timeframe,0));
    ObjectSet     ("TF1_LOW_label", OBJPROP_TIME1, (Time[0]+bars_forward*60*Period()));
    ObjectSet     ("TF1_LOW_label", OBJPROP_COLOR, Lime);
    ObjectSetText ("TF1_LOW_label", "TF1 LOW", font_size, "Arial", Lime);  
    }
    //----
      return(0);
    }
//+------------------------------------------------------------------+

But your suggestion of using Period() instead of timeframe works BRILLIANTLY!

cheers

Dave (code and indic attached, thanks again)

 
pullend:

Raptor, can't thank you enough. Very much appreciate the time and effort you take to help us.

I have got the indicator to work and yes similar to the one you have pictured.

I have to admit I am still struggling to understand why the labels are defined in this manner, I could not replicate the way I coded the lines which seemed to make sense (still this works)

But your suggestion of using Period() instead of timeframe works BRILLIANTLY!

cheers

Dave (code and indic attached, thanks again)

Well done for keeping at it . . .  :-)

This line is wrong,  if you take the Indicator off your chart you will see it leaves a label behind. 

ObjectDelete("TF1_HIGH__label");
 

My version of your code . . . .

Files:
Reason: