AROON indicator Help

Indicators coded by community members
Message
Author
soheilpro
Posts: 13
Joined: Mon Mar 23, 2009 12:53 pm

AROON indicator Help

#1 Postby soheilpro » Mon Jul 20, 2009 1:35 pm

Hi Everyone,

I have been trying to re-write the Aroon indicator for Forextester, the code compiles OK but when i try to add the indicator to the FX tester app, the application sits there doing nothing and become non responding javascript:emoticon(':(') . Attached is the full code in C++, can anyone check and see what am i doing wrong in this code?
Thanks.


Code: Select all

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "IndicatorInterfaceUnit.h"
#include "TechnicalFunctions.h"


// External variables
int       Aroon_Period= 14;

// Buffers

TIndexBuffer Aroon_Up, Aroon_Dn;

EXPORT void __stdcall Init()
{
  // define properties
  IndicatorShortName("Aroon");
  SetOutputWindow(ow_SeparateWindow);
  AddLevel(30, psDash, 1, clYellow);
  AddLevel(70, psDash, 1, clYellow);
  AddLevel(100, psDash, 1, clYellow);
  // register options

    RegOption("Aroon_Period", ot_Integer, &Aroon_Period);

  // create buffers

  IndicatorBuffers(2);
  Aroon_Up = CreateIndexBuffer();
  Aroon_Dn = CreateIndexBuffer();
 
  //SetFixedMinMaxValues(0, 1.2);
  SetEmptyValue(0.0);
  SetIndexBuffer(0, Aroon_Up);
  SetIndexBuffer(1, Aroon_Dn);

  SetIndexStyle(0, ds_Line, psSolid, 1, clGreen);
  SetIndexStyle(1, ds_Line, psSolid, 1, clRed);

  SetIndexLabel(0, "Aroon_Up");
  SetIndexLabel(1, "Aroon_Dn");


  SetBufferShift(0, 0);
  SetBufferShift(1, 0);


 


}
EXPORT void __stdcall OnParamsChange()
{

}
EXPORT void __stdcall Calculate(int index)
{

int j, K, KLAST, Indx_low, Indx_high, High_Dist, Low_Dist;
double High_val, Low_val, High_tmp, Low_tmp;

if(Bars()>=Aroon_Period)
{
   K=1;  //starting the calculations on the first closed bar.
   KLAST=K+Aroon_Period; //the last price bar that should be included in the calculations
   for(j=KLAST;j>=K;j--)
   {
      High_val=iHigh(Symbol(),PERIOD_D1,j); //get the high value from the last bar in range
      Low_val=iLow(Symbol(),PERIOD_D1,j); // get the low value from the last bar in range
      if (j=KLAST)  //it will fill the variable with the first found high and low and get the respective indexes.
      {
         High_tmp=High_val;
         Low_tmp=Low_val;
         Indx_high=j;
         Indx_low=j;
      }
      if(High_val>=High_tmp) //replace the high with the previous high and update the index value
      {
         High_tmp=High_val;
         Indx_high=j;
      }
      if(Low_val<=Low_tmp) // replace the low with the Prev and update the index
      {
         Low_tmp=Low_val;
         Indx_low=j;
      }

   }
   High_Dist=Indx_high-1; // real distance from the start bar
   Low_Dist=Indx_low-1;
   Aroon_Up[index+1] = ((Aroon_Period-High_Dist)/Aroon_Period)*100; / calculation for the indicator.
       Aroon_Dn[index+1] = ((Aroon_Period-Low_Dist)/Aroon_Period)*100;

}
   
}

User avatar
Tantalus
Posts: 302
Joined: Fri Mar 23, 2007 3:51 pm
Contact:

#2 Postby Tantalus » Mon Jul 20, 2009 2:46 pm

Sorry, I don't program in C++, but The Aroon indicator and also the Aroon Oscillator are available on my website:

www.tantalusonline.com

Come take a look!

Brian-
Tantalus Research - Developing 21st Century Trading Systems.

soheilpro
Posts: 13
Joined: Mon Mar 23, 2009 12:53 pm

#3 Postby soheilpro » Mon Jul 20, 2009 3:06 pm

Thanks Tantalus,
the problem got nothing to do with the language you choose but the way you treat the indexing and calculation (which is common on both Delphi and C) can you take a look and see where i am missing the logic of the index and the way FT treats calculating the history data?

dackjaniels
Posts: 151
Joined: Tue Feb 24, 2009 1:03 pm

#4 Postby dackjaniels » Tue Jul 21, 2009 12:20 pm

soheilpro,

Check my response in your other post first but I can see one obvious problem here...

Code: Select all

if(Bars()>=Aroon_Period)
{
   K=1; // Not good, when calculating historic data the index could be say, 155 yet you are telling it to always calculate from 1. You should use K=index+1;

   KLAST=K+Aroon_Period; // this is fine though be aware that this will calculate a range of bars 1 greater than the Aroon_Period, e.g. if period is set to 10, it will calculate the most recent closed bar plus the previous 10 bars, a total of 11 bars. To caculate only 10 bars use KLAST=(K+Aroon_Period)-1

   for(j=KLAST;j>=K;j--)     // this is fine
   ...


Regards,
Steve

dackjaniels
Posts: 151
Joined: Tue Feb 24, 2009 1:03 pm

#5 Postby dackjaniels » Tue Jul 21, 2009 12:32 pm

Another important point...

Code: Select all

if(Bars()>=Aroon_Period)


The above code is intended to check enough bars exist before going back and doing some calculation using previous bars right?

Problem is, if you drop this indicator onto a chart with say 50 bars, and the aroon period is lower, say 10 it will attempt to run the code from the very first tick because the condition (Bars > Aroon_Period) is always true.

You should replace it with

Code: Select all

if (Bars() - index >= Aroon_Period)


Remember from my other post, bars - index returns the number of the bar being calculated (assuming bars numbered left to right, 1,2,3, etc.)

So in this case if the number of the bar being calculated is greater than the aroon period then the code will be executed.

Hope this helps,
Steve

soheilpro
Posts: 13
Joined: Mon Mar 23, 2009 12:53 pm

#6 Postby soheilpro » Tue Jul 21, 2009 6:18 pm

Thanks So much for your clear description. two final questions.
1- when talking about the index variable, do we need to define it anywhere in the code or it is predefined based on the FT API?

2- is index=0 the current bar (which is not closed yet) or the first Closed bar.

Thanks again for all your support. :D

dackjaniels
Posts: 151
Joined: Tue Feb 24, 2009 1:03 pm

#7 Postby dackjaniels » Tue Jul 21, 2009 8:09 pm

soheilpro wrote:Thanks So much for your clear description. two final questions.
1- when talking about the index variable, do we need to define it anywhere in the code or it is predefined based on the FT API?

Index variable is managed by FT so you don't need to declare it. It is only available to the calculate procedure though you can of course pass its value to other functions/procedures if you wish.

2- is index=0 the current bar (which is not closed yet) or the first Closed bar.

When index is 0 the calculate procedure is being executed on the current bar. To access the previous bar (the most recent full bar) use index+1.

Thanks again for all your support. :D


Return to “Indicators”

Who is online

Users browsing this forum: No registered users and 16 guests