Adding arrows to high and low of set period...

 

I want indicator to display buy and sell arrows at high and low point of given period (m15). It seems to work when I use OBJ_HLINE but when I use arrows as graphical it runs with no errors but I get nothing showing up on chart. Sorry if there is a simple explanation - I am very new to coding!

 (I tried with arrow_up and arrow_down also)

Thanks!

//|                                            objectcreatetrial.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "http://www.mql4.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int start(){

  
   double price1=iHigh(Symbol(),PERIOD_H1,0);
   ObjectCreate("arrowdown",OBJ_ARROW_SELL,0,0,price1);
  
   double price2=iLow(Symbol(),PERIOD_H1,0);
   ObjectCreate("arrowup",OBJ_ARROW_BUY,0,0,price2);
  
   return(0);
}  


 

 

First problem: you cannot have more than 1 object with the same name.

Your code will try to create "arrowdown" and "arrowup" each tick.

It will probably succeed on the first attempt (but you should check the return value of ObjectCreate to be sure) but then fail from that point onwards.

You probably didn't notice this behaviour with OBJ_HLINE because a horizontal line spans all times. 

Second problem: you are drawing your arrows at the start of time (01 January 1970 as far as MQL4 is concerned)

Again, you probably didn't notice this behaviour with OBJ_HLINE because a horizontal line spans all times.  

 
honest_knave:

First problem: you cannot have more than 1 object with the same name.

Your code will try to create "arrowdown" and "arrowup" each tick.

It will probably succeed on the first attempt (but you should check the return value of ObjectCreate to be sure) but then fail from that point onwards.

You probably didn't notice this behaviour with OBJ_HLINE because a horizontal line spans all times. 

Second problem: you are drawing your arrows at the start of time (01 January 1970 as far as MQL4 is concerned)

Again, you probably didn't notice this behaviour with OBJ_HLINE because a horizontal line spans all times.  

thanks for help knave! few questions tho...

What do you mean the same name, one is titled 'arrowup' and the other 'arrowdown' and the are both different objects...?  

Also, how do I make sure it is the latest 15min period only, as OBJ_HLINE uses latest period and I am changing nothing but the object type...?

Reason: