Creating Arrows Displays Differently On Multiple Timeframes

 

Hello there,

The title pretty much says it all. I have the following code (I use similar code to add other things to the chart):-

void CArrow::_createArrow(datetime time1,double price1)
  {

   if(_arrowUp)
     {
      price1-=(_config.ArrowUpOffset*Point());
     }
   else
     {
      price1+=(_config.ArrowDownOffset*Point());
     }

   _created=ObjectCreate(0,_name,OBJ_ARROW,0,time1,price1);

   if(!_created)
     {

#ifdef LoggingOn
      Print("Error: unable to create arrow! Error code #",GetLastError());
#endif

     }

  }

I have a user-definable offset for up/down arrows and it seems to work well enough. However, if I get this distance right on, say, the 5-minute time-frame and then switch to weekly (or some other higher time-frame), the arrows render over the bar instead of above (or below) it. When I look at the values that the arrows render at, they seem to report as expected, but, they are just in the wrong position.

I'm likely to be doing something wrong or misunderstanding some aspect of the chart. If anyone could point me in the right direction I'd appreciate it.

Many thanks.

 
Geester:

Hello there,

The title pretty much says it all. I have the following code (I use similar code to add other things to the chart):-

I have a user-definable offset for up/down arrows and it seems to work well enough. However, if I get this distance right on, say, the 5-minute time-frame and then switch to weekly (or some other higher time-frame), the arrows render over the bar instead of above (or below) it. When I look at the values that the arrows render at, they seem to report as expected, but, they are just in the wrong position.

I'm likely to be doing something wrong or misunderstanding some aspect of the chart. If anyone could point me in the right direction I'd appreciate it.

Many thanks.

Using fixed offset (like in your case) is almost always producing such results

The usual way to avoid that is to use atr (10 period atr is quite OK) instead of using fixed offset

 
Mladen Rakic:

Using fixed offset (like in your case) is almost always producing such results

The usual way to avoid that is to use atr (10 period atr is quite OK) instead of using fixed offset


@Mladen Rakic - Hey Mladen, thanks very much for the heads-up and suggestion to use ATR! :)

Cheers,

--G



 
I calculate the scale this way.
double  gChartScale=0;
void OnTimer(void){
        double  CSprev  = gChartScale;
        gChartScale     = ( ChartGetDouble(0, CHART_PRICE_MAX)
                          - ChartGetDouble(0, CHART_PRICE_MIN)
                          ) / ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS);
        if(gChartScale != CSprev){      
         static int  NAspread[];    static long NAvolume[];
         /*(void)*/OnCalculate(Bars,         // rates_total,
                               0,                               // prev_calculated,
                               Time, Open, High, Low, Close,
                               NAvolume,     // NU tick_volume[],
                               NAvolume,     // NU volume[],
                               NAspread);    // NU spread[]
        }
}       // OnTimer
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(...){
   :
         bBuy[iBar]  = Heiken_Ashi(HA_BOTTOM, iBar) + 4 * gChartScale;
   :
         bSell[iBar] = Heiken_Ashi(HA_TOP,    iBar) - 6 * gChartScale;

Places the arrow stem right on the top/bottom of the bar.


I use the timer, because no ticks when market closed. (Think chart minimized vs not.)

 
whroeder1:
I calculate the scale this way.

Places the arrow stem right on the top/bottom of the bar.


I use the timer, because no ticks when market closed. (Think chart minimized vs not.)


Hey @whroeder1 - thanks also for another great way to accomplish this. I was clearly way too simplistic in my original approach! I appreciate the sample code.

Cheers

--G




Reason: