Flow to send top N exploration results to IBcontroller for Auto-trading

Hello guys,

I'm missing a bit to connect the dots in my workflow... hopefully someone will have an opinion on an efficient way to do this.

My AFL contains both backtesting and the exploration part in an "if ( Status( "action" ) == actionExplore )" block.

Backtest and exploration rely on "trying" to buy the top X ranked stocks using a limit order.

So it's using a low-level CBT for the limit order and StaticVarGenerateRanks to filter the top X ranked stocks for the last bar.

	rank = StaticVarGet( "rankvalues_" + symbol );
	Filter = Buy AND rank <= MaxPositions;

Now the exploration give me the top X stocks for which I should send a buy limit order to IB for the last bar.

I have tried to call the ibc.PlaceOrder function ONLY for the top X ranked stocks but I keep getting the message : Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here

	if( ibc.IsConnected() AND LastValue(Buy) AND LastValue(rank) <= MaxPositions) // check if connection to IB was successfull
	{
		ibc.PlaceOrder(Name(), "BUY", 100, "MKT", 0, 0, "DAY", False ); // place order but do not transmit yet
	}

I don't understand why I get this message since LastValue(Buy) and LastValue(rank) <= MaxPositions are both equal to 1.

Is it just a dumb programming error on my part or should I code the sending to IBcontroller elsewhere ?

Thanks a lot,

There is no message without reason.
What is type of MaxPositions?

_TraceF("Type of Max. Pos: %s", typeof(MaxPositions));

If it is type number...
Are you sure error message is related to that if statement? Check line number.

Thanks a lot...

Dumb me, it's a dummy programming error, I missed one "LastValue" to transform the array of MaxPosition into a single numeric.

Solved with :slight_smile:

	if( ibc.IsConnected() AND LastValue(Buy) AND LastValue(rank) <= LastValue(MaxPositions)) // check if connection to IB was successfull
	{
		ibc.PlaceOrder(Name(), "BUY", 100, "MKT", 0, 0, "DAY", False ); // place order but do not transmit yet
	}

-> Simply use single one

LastValue(Buy AND rank <= MaxPositions)

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.