Download MetaTrader 5

How to Draw a Reference Lines Every 10 Pips

To add comments, please log in or register
MisterDog
383
MisterDog  

Here's a handy script I use all the time. It draws reference lines every 10 pips to help me gauge movement in the market. I was really frustrated trying to figure this out by looking at the prices on the right-hand side of the screen so I created a script. The script could be a good for beginners to practice drawing objects.

int start()
{  
    int nLines = 40;                                   // Number of total line to draw
    double lineInterval = 0.0010;                      // Interval between lines
    ObjectsDeleteAll(0,OBJ_HLINE);                     // Clear all the lines from the window - CAREFUL!
    double normPrice = NormalizeDouble(Close[1],3);    // Current price is rounded to nearest "10"
    for (int ix = 0; ix < nLines; ix++)                // Loop span number of times
        {
            ObjectCreate("tensLines"+ix, OBJ_HLINE, 0, 0, normPrice+((ix-(nLines/2))*lineInterval));    // Place half above and half below the current price
            ObjectSet("tensLines"+ix,OBJPROP_COLOR,DarkSlateGray);      // Make the lines look better
        }
    return(0); //All done
}
onewithzachy
2269
onewithzachy  
MisterDog:

Here's a handy script I use all the time. It draws reference lines every 10 pips to help me gauge movement in the market. I was really frustrated trying to figure this out by looking at the prices on the right-hand side of the screen so I created a script. The script could be a good for beginners to practice drawing objects.

Make it an CI not script, calculate from 0 not from close price, draw only on visible part of the chart (WinPriceMax() and its sister), update it when price moves beyond the limit (in your case, line interval = 10 pips), use OBJ_RECTANGLE instead of OBJ_HLINE.

It will synchronize on all opened charts.

:D

Simon Gniadkowski
Moderator
18036
Simon Gniadkowski  

Or . . . make it into an Indicator . . needs a bit more code so it is refreshed only at the start of a new bar . . .

int deinit()
   {
   for (int ix = 0; ix < nLines; ix++) // delete my horizontal lines
      {
      ObjectDelete("tensLines"+ix);
      }
   return(0);
   }


int start()
   {  
   int nLines = 40;                                   // Number of total line to draw
   double lineInterval = 0.0010;                      // Interval between lines
   double normPrice = NormalizeDouble(Close[1],3);    // Current price is rounded to nearest "10"

   for (int ix = 0; ix < nLines; ix++)                // Loop span number of times
      {
      if(ObjectFind("tensLines"+ix) < 0) 
         ObjectCreate("tensLines"+ix, OBJ_HLINE, 0, 0, normPrice+((ix-(nLines/2))*lineInterval));    // Place half above and half below the current price

      else ObjectSet("tensLines"+ix, OBJPROP_PRICE1, normPrice+((ix-(nLines/2))*lineInterval));
      ObjectSet("tensLines"+ix,OBJPROP_COLOR,DarkSlateGray);      // Make the lines look better
      }
   return(0); //All done
   }
MisterDog
383
MisterDog  
onewithzachy:

Make it an CI not script, calculate from 0 not from close price, draw only on visible part of the chart (WinPriceMax() and its sister), update it when price moves beyond the limit (in your case, line interval = 10 pips), use OBJ_RECTANGLE instead of OBJ_HLINE.

It will synchronize on all opened charts.

:D


This all makes sense except for the part "OBJ_RECTANGLE instead of OBJ_HLINE". Why rectangles?
MisterDog
383
MisterDog  
RaptorUK:

Or . . . make it into an Indicator . . needs a bit more code so it is refreshed only at the start of a new bar . . .


Yes of course -- much better. Tell me, is there way to use some sort of a "wildcard" for things like the ObjectDelete? I would like to do something like this, ObjectDelete("tensLines"*); in other words, delete anything that starts with "tensLines".
onewithzachy
2269
onewithzachy  
MisterDog:

This all makes sense except for the part "OBJ_RECTANGLE instead of OBJ_HLINE". Why rectangles?

I have that gridy thing for years, I never see prices on right side anyway, probably you don't like rectangle though, use WindowsBarsPerChart() and maybe WindowsFirstVisibleBar().

See at right bottom of the chart, it's 25/341. It mean that grid is 25 pips and the height of the chart is 341 pips.

:D

MisterDog
383
MisterDog  
onewithzachy:

I have that gridy thing for years, I never see prices on right side anyway, probably you don't like rectangle though, use WindowsBarsPerChart() and maybe WindowsFirstVisibleBar().

See at right bottom of the chart, it's 25/341. It mean that grid is 25 pips and the height of the chart is 341 pips.

:D

I actually like the way you have this laid out with the bars. It's easy on the eyes. You say, "you never see prices on the right side anyway". I've often wondered why with just two choices, buy or sell, I have a 50-50 chance but I'm wrong 80% of the time. ;-)
onewithzachy
2269
onewithzachy  
MisterDog:
I actually like the way you have this laid out with the bars. It's easy on the eyes. You say, "you never see prices on the right side anyway". I've often wondered why with just two choices, buy or sell, I have a 50-50 chance but I'm wrong 80% of the time. ;-)

Same here ...

:D

Simon Gniadkowski
Moderator
18036
Simon Gniadkowski  
MisterDog:
I actually like the way you have this laid out with the bars. It's easy on the eyes. You say, "you never see prices on the right side anyway". I've often wondered why with just two choices, buy or sell, I have a 50-50 chance but I'm wrong 80% of the time. ;-)

That's very easy to answer . . . assuming what I have seen testing EAs holds true. It's down to your risk:reward, if you have a risk of 20 and a reward of 80 (or similar ratio) I can see how you can have a win rate of 20% . . . it's not quite that simple though because you have to factor in the Spread if you are taking small trades . . .
MisterDog
383
MisterDog  
onewithzachy, I am just getting around to setting up your OBJ_RECTANGLE style chart. You mentioned " WindowsBarsPerChart() and maybe WindowsFirstVisibleBar()". I'm still having a hard time figuring out how to get the bars to run from the left-hand side of the screen to the right. But I do like the layout! Any clues on how to do this?
onewithzachy
2269
onewithzachy  
MisterDog:
onewithzachy, I am just getting around to setting up your OBJ_RECTANGLE style chart. You mentioned " WindowsBarsPerChart() and maybe WindowsFirstVisibleBar()". I'm still having a hard time figuring out how to get the bars to run from the left-hand side of the screen to the right. But I do like the layout! Any clues on how to do this?

Hi MisterDog,

Simple.

1. Get the time distance between one bar to another. We can get this by subtracting current bar time with previous bar time or multiplying period with 60 second, choose the latter one, coz there's time gap on Monday.

datetime Bar_Time_Gap; // or integer type

Bar_Time_Gap = Time [0] - Time [1]; // or Time [7] - Time [8] or whatever
Bar_Time_Gap = Period()*60;

2. WindowsFirstVisibleBar() is the very left bar. Start drawing from that bar, or better yet start drawing from n left of that bar, say 5 bars to the left. Say the return of WindowsFirstVisibleBar() is 20. That means the very left bar is bar [20], start drawing from bar [25] then. I actually draw from [Bars - 1].

datetime Start;

Start = Time [WindowFirstVisibleBar() + 5];                  //which is the same ...
Start = Time [WindowFirstVisibleBar()] - 5 * Bar_Time_Gap;   //... with this one

3. WindowsBarsPerChart() is the number of bars on chart. Say the return of WindowsBarsPerChart() is 35 and WindowsFirstVisibleBar() is 20. So starting from bar [0] there is about 15 bars empty space on the right side. Draw the end of that rectangle to that very right bar of that empty space, or better yet start drawing from n right of that bar say 5 bars to the right.

datetime End;
int Right_Bar = WindowBarsPerChart() - WindowFirstVisibleBar() + 5;

End = Time[0] + Right_Bar * Bar_Time_Gap;

When new bar coming, this right bar will be moving to the left, so the end of the rectangle will be visible, and we have to draw that again.

I hope I'm not making mistake here, coz I wrote this fast.

:D

To add comments, please log in or register