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 );
}