Why i=0; is not a numeric in afl

MSN1979

Well-Known Member
#1
ok so i need to use if statement and I declare

i=0;

then write

if ( i < 1)
{
do something
{

else
{
}

it gives me error to use boolean or numeric types with IF, what I am doing wrong?

Exact Error
Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] (array subscript operator) to access array elements
 

mohan.sic

Well-Known Member
#2
ok so i need to use if statement and I declare

i=0;

then write

if ( i < 1)
{
do something
{

else
{
}

it gives me error to use boolean or numeric types with IF, what I am doing wrong?

Exact Error
Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] (array subscript operator) to access array elements
I don't know coding but I think problem is not with '0' Because many afl codes use zero line as reference point.
Please check syntax format.
 

MSN1979

Well-Known Member
#3
I some how feel its thinking my i=0 as array, although I have no idea why? Maybe some expert can clarify. Syntax look ok to me
 

asnavale

Well-Known Member
#4
I some how feel its thinking my i=0 as array, although I have no idea why? Maybe some expert can clarify. Syntax look ok to me
In Amibroker any variable you declare is considered an array. Therefore, you are getting the error. However, if you use i=0 in a for loop then it is a number.

-Anant
 

MSN1979

Well-Known Member
#5
thank you anant,

any workaround? If I don't need a loop then?
 
#6
Basic data structure is an array and that is the strength of Amibroker,
once you understand it, coding become very simple

lets look at an e.g.

i = close;

now the question is which close, this bar, previous bar, next bar ???

by default it assigns all the close values . . . (Close itself is an array)
so the variable 'i' is an array indexed with number of bars in your database.

so even if you are using this

i = 0; // Zero,

you get an array of zeros.

Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] (array subscript operator) to access array elements
the solution is given above

i[0] will point to value of i associated with first bar
i[barcount-1] will point to value of i associated with last bar


.
 

MSN1979

Well-Known Member
#7
Basic data structure is an array and that is the strength of Amibroker,
once you understand it, coding become very simple

lets look at an e.g.

i = close;

now the question is which close, this bar, previous bar, next bar ???

by default it assigns all the close values . . . (Close itself is an array)
so the variable 'i' is an array indexed with number of bars in your database.

so even if you are using this

i = 0; // Zero,

you get an array of zeros.



the solution is given above

i[0] will point to value of i associated with first bar
i[barcount-1] will point to value of i associated with last bar


.
Thank you Happy for the detailed explanation. Please look at the code. This is what I have tried so far.

Now I would like to implement a system like ORB in amibroker. For that I am trying to

STEP 1 :Store Open candle High In some variable ( I have already done that)

STEP 2: Compare 2nd candle to first candle ( I have already done that)

STEP 3: Compare subsequent n candles to opening candle high, If breakout happens then I would like to Buy. After breakout the candle comparison should stop. For this i need to use some Kind of If Loop which I am unable to do and keep encountering error's. Shared above

// I am sharing what Steps I have tried and not working.

If ( H[Barcount -1] > firstbarofdayOpen)
{

then do something

Result:// This code returns error and says I must use boolean or integer type
I changed If Statement to High firstbarofdayopen[0] it returns 0 all the time so I am unsure whats wrong
If its an array it should return me high of first bar but it does not

}
// 2nd line of code i have tried and not working
I tried IIF statement that returns 0 or 1 to variable to HOD but when I try to use IF on HOD to execute my Buy it fails again.

I hope I am making sense. I Need Help only with STEP 3

Below is the working code.


//Code to Find out Opening Candle High and Low
newday = Day() != Ref( Day(), -1 );
firstbarOfDayOpen = ValueWhen( newday, Open );
firstbarOfDayHigh = ValueWhen( newday, High );
firstbarOfDayLow = ValueWhen( newday, Low );
firstbarOfDayClose = ValueWhen( newday, Close );
GfxTextOut( "First Bar High Value is " + firstbarofDayHigh, 20, 20 );
GfxTextOut( "First Bar Low Value is " + firstbarofDayLow, 20, 40 );


//Code to compare 2 candles and display on screen which candle is higher
for ( i = 1; i < BarCount; i++ )
{

if (High[i-1] < High[BarCount-1])
{
GfxTextOut( "Higer Bar is Current Bar " + H[BarCount-1], 20, 80 );
}
else
{
GfxTextOut( "Higer Bar is Previous Bar " + H[i-1], 20, 100 );
}
GfxTextOut( "Current bar high is " + High[BarCount-1], 20, 120 );
GfxTextOut( "Previous Bar High is " + High[i-1], 20, 140 );

}
 
#8
Have you looked at the code posted by Augubhai


He has shared the code of his ORB system here, and it's been copy/pasted many places on the net


.
 

MSN1979

Well-Known Member
#9
Have you looked at the code posted by Augubhai


He has shared the code of his ORB system here, and it's been copy/pasted many places on the net


.

no i have not seen code by agubhai, I am not actually trading, I am just trying to learn amibroker afl.
 

Similar threads