Help required - convert to Array Code

#1
hi,

I am new to amibroker but know a little bit about C++. I tried coding the following. Amibroker always encourages coding using Arrays and its efficient as well in performance as well as its elegant. I would like to know how to code the following using Arrays and kindly request experienced members to guide me through.

Code:
_SECTION_BEGIN("My-AFL7228");
SetBarsRequired( sbrAll, sbrAll );
TimeFrameSet( inDaily ); // switch to Daily time frame
SetChartOptions(0,chartShowArrows|chartShowDates);
m5   = MACD( 5, 10  );
m10  = MACD( 10,14  );
m14  = MACD( 14,20  );

result=0;

for( bar = 0; bar < BarCount; bar++ ) 
     { 
        if( m5[bar] > m14[bar] )          result[ bar ] = result[ bar ]+2; 
	if( m5[bar] > m10[bar] )          result[ bar ] = result[ bar ]+3;
	if( m5[bar] > 50 )                result[ bar ] = result[ bar ]+5;

	if( m5[bar] < m14[bar] )          result[ bar ] = result[ bar ]-2; 
	if( m5[bar] < m10[bar] )          result[ bar ] = result[ bar ]-3;
	if( m5[bar] < 50 )                result[ bar ] = result[ bar ]-5;
	}

Pdynamic_color = Null;
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} My-AFL-11bc", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Pdynamic_color = TimeFrameExpand(	IIf( result>7, colorGreen, 
				IIf( result>5, colorBrightGreen, 
				IIf( result<-7, colorDarkRed, 
				IIf( result<-5, colorRed, colorWhite)))), inDaily);

TimeFrameRestore(); // restore time frame to original  
Plot( MACD(12,26), "MACD", Pdynamic_color , styleNoTitle | styleHistogram ); 
_SECTION_END();

//
 
#2
Traderji is so vast my post seems to have drowned. :rofl:
I feel many traders like me would benefit much from the knowledge as Arrays is an important aspect of Amibroker. I earnestly ask experienced users to kindly guide us.
 

mastermind007

Well-Known Member
#3
Code:
_SECTION_BEGIN("My-AFL7228");
SetBarsRequired( sbrAll, sbrAll );
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} My-AFL-11bc", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
TimeFrameSet( inDaily ); // switch to Daily time frame
m5   = MACD( 5, 10  );
m10  = MACD( 10,14  );
m14  = MACD( 14,20  );

result =   IIf(m5 > m14, 2, -2) + IIf(m5 > m10, 3, -3) + IIf(m5 > 50 , 5, -5);

P1 = 
IIf(result>7, colorGreen, 
IIf(result>5, colorBrightGreen, 
IIf(result<-7, colorDarkRed, 
IIf(result<-5, colorRed, colorWhite))));
TimeFrameRestore(); // restore time frame to original  

p2 = TimeFrameExpand(p1, inDaily);
Plot(MACD(12,26), "MACD", p2, styleNoTitle | styleHistogram ); 
_SECTION_END();
 

Similar threads