Array always return 0

I want to allocate different fund to stock by different indicator like ATR , so I write this.

for(i=0;i<BarCount;i++)
{
	atrv=ATR(10);
	if(atrv[i]==0)
	weight[i]=100;
	else
	weight[i]=300;
}

	
if( Status("action")== actionPortfolio)
	{
		// retrieve the interface to portfolio backtester 
		bo = GetBacktesterObject(); 
		bo.PreProcess();
		CurrentOpenqty=0;

			for ( bar = 0; bar < BarCount; bar++ )
			{
				CurrentPortfolioEquity = bo.Cash;
				CurrentOpenqty=bo.GetOpenPosQty();
				
				for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) )
				{	
					{
						if( CurrentOpenqty < (posqty) )
						{								
							sig.PosSize = -(weight[bar]/posqty);
						}
					}
				}
				bo.ProcessTradeSignals( bar );
			}
		bo.PostProcess();
	}
}

but the value what I get is always (atrv[i]=0) weight=100, and actually it’s not zero.
How can I modify it to let it work correctly?

@Hsieh I think that you need to review the basics of how AmibBroker works.

Understanding how AFL works

More info and ideas here.

Try to see, what happens when you write some code WITHOUT using the loop over the bars.

/* Original code commented out
for(i=0;i<BarCount;i++)
{
	atrv=ATR(10);
	if(atrv[i]==0)
	weight[i]=100;
	else
	weight[i]=300;
} */

// Amibroker uses a lot of ARRAYS operations

atrv = ATR( 10 );
weight = iif( atrv == 0, 100, 300 );
Filter = 1;
AddColumn(C, "Close", 1.2);
AddColumn(atrv, "ATRV", 1.2);
AddColumn(weight, "Weight", 1.2);

Apply the exploration to a watchlist with many symbols and 1 recent day:

When do you expect to get an ATR(10) == 0? ATR Average True Range

Learn to use the explorations as a debugging tool before attempting to write more complex formulas (I too still do a lot of mistakes, be patient… it takes time!)