Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Round numbers indicator
 Post subject: Round numbers indicator Post rating: 0   New post Posted: Mon 05 Dec, 2011, 13:43 
User avatar

User rating: 0
Joined: Mon 05 Dec, 2011, 13:18
Posts: 1
Location: United Kingdom, London
Basically I would like to have an indicator/strategy which could draw horizontal lines on the chart at round numbers.

The basic way to calculate these round numbers is to get a chart's minimum and maximum value, normalize the values to two decimals for 4 decimals pairs and 0 decimals for 2 decimals pairs, and starting from the bottom keep working your way up adding x pips on each step.

For example, let's say EURUSD's minimum value on the current historical chart is 1.0256. We normalize this value to 2 decimals and get 1.02. We draw a horizontal line at this level and then we move up 100 pips on each step. So we draw lines at 1.03, 1.04, 1.05, 1.06 and so on. We stop when we reach the maximum value of the chart. There is no need to draw lines beyond the minimum and maximum values.

Let's take another example, on the EURJPY. Let's say the chart minimum is 99,52. We normalize the value to 99 and starting from this level we begin drawing horizontal lines up. We draw lines at 99, 100, 101, 102, 103, 104 an so on.

Ideally the 100 pips variable which I've used in my example should be changeable so that we can perhaps have horizontal levels drawn every 25 or 50 pips instead of 100.

I've created this indicator in mql4 but I have no clue as to how should I proceed to create this indicator in jforex. I can't find my way around the documentation, there is no IntelliSense, and I have very limited experience regarding java. Any help would be appreciated, and if any of you finds some free time on his hands and decides to create this indicator for fun I would be immensley grateful.

My mql4 code:

extern color Color = DarkSlateBlue;
double ThePoint; // This is to replace mq4's "Point"
int CharacterCount; // To count string character
int k;
extern int xPips = 100;

int init()
  {
//---- indicators
   if (Point == 0.00001) ThePoint = 0.0001; //6 digits   
   else if (Point == 0.001) ThePoint = 0.01; //3 digits (for Yen based pairs)   
   else ThePoint = Point; //Normal
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   double maxim=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,Bars,0)); // get the maximum value of the current chart
   double minim=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,Bars,0)); // get the minimum value of the current chart
   
   if(ThePoint==0.01) // if the pair is a two decimals one (such as EURJPY)
         k=0;         // we normalize the value to 0 decimals
       else k=2;      // else we normalize it to 2 decimals (on pairs such as the EURUSD)
       
   maxim=NormalizeDouble(maxim,k);
   minim=NormalizeDouble(minim,k);

   while(maxim>minim) // starting from the top we go down and delete every line we have drawn
   {
   string named="Hline"+DoubleToStr(maxim,4);
   ObjectDelete(named);
   maxim-=xPips*ThePoint;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   double maxim=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,Bars,0)); // get the maximum value of the current chart
   double minim=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,Bars,0)); // get the minimum value of the current chart
     
      if(ThePoint==0.01) // if the pair is a two decimals one (such as EURJPY)
         k=0;            // we normalize the value to 0 decimals
       else k=2;         // else we normalize it to 2 decimals (on pairs such as the EURUSD)
         
   maxim=NormalizeDouble(maxim,k);
   minim=NormalizeDouble(minim,k);

   while(minim<=maxim) // we begin from the minimum and we keep drawing lines every xPips until we reach the maximum
   {
      string name="Hline"+DoubleToStr(minim,4); // hline name
      ObjectCreate(name, OBJ_HLINE, 0,Time[0],minim); // draw line
      ObjectSet(name,6,Color); // set color
      ObjectSet(name,7,STYLE_DOT); // set style
     
      minim+=xPips*ThePoint; // add 100 pips and move up with the drawing
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+


 
 Post subject: Re: Round numbers indicator Post rating: 0   New post Posted: Tue 06 Dec, 2011, 13:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
It is possible to configure chart grid to draw lines at rounded pip vales:


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com