[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Problem with an second values array.



PureBytes Links

Trading Reference Links

Hallo,

maybe can you help me to solve the following problem:

For the i day:
- I calculate the High and Low for the last 5 days
- I calculate the difference between this values

As example:
iMax=150
iMin=100
Difference=iMax-iMin=50

What I need is an array[1..50].
All values are initial zero.

For the last 5 days I need to increase for every day the array value with 1, 
if the price are between the High and Low of this day.

As example for Day 1:
High=120, Low=110

For i = 110 to 120 I must increase in the array the value at position i-100 
with 1:
array[110-iMin] = array[110-iMin]+1;
...
array[120-iMin]=array[120-iMin]+1;

The same addition is to calculate for the values between Open and Close.


My AFL code as Formula is:
==========================

/*******************************************************************
gs Market Pivots
10.17.2004
*******************************************************************/

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows);
Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, 
Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | 
ParamStyle("Style", styleCandle, maskPrice ) );
GraphXSpace=1;
_SECTION_END();


/*******************************************************************
Market Pivots
*******************************************************************/
_SECTION_BEGIN("MarketPivots");
nD=5;      // Period
iMult=100; // Multiplier

// 1. Max, Min and Difference for the last nD days 
............................
for (i=nD-1; i<BarCount; i++)
{
  /* Maximum prices for the "i" day */
  iMax[i]=H[i];
  for (j=1; j<nD; j++)
  {
    if ( H[i-j] > iMax[i] )
      iMax[i] = H[i-j];
    else
      MaxOK = True;
  }

  /* Minimum prices for the "i" day */
  iMin[i]=L[i];
  for (j=1; j<nD; j++)
  {
    if ( L[i-j] < iMin[i] )
      iMin[i] = L[i-j];
    else
      MinOK = True;
  }

  /* Difference maximum/minimum price for the "i" Day */
  iDifference[i] = (iMult*(iMax[i] - iMin[i]) + 1);
}
Plot( iMax, "iMax", colorRed, styleNoTitle | styleLine) ;
Plot( iMin, "iMin", colorBlue, styleNoTitle | styleLine);


/* Number of appareances */
function ProfileAppareances(iDiff)
{
  for (i=nD-1; i<BarCount; i++)
  {
    nDiff=iDiff[i];
    for (j=1; j<=nDiff; j++)
    {
      iApp[j]=0;
    }
    // ...
  }
return iApp;
}

// Test plot:
Plot( ProfileAppareances(iDifference), "iDiff", colorYellow, styleNoTitle | 
styleLine) ;
_SECTION_END();

=========================

- Because I become the message:
"Error 7.
Subscript out of range",

I can't continue with the code writing.

Regards
George 



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/