# Set Limit price ibc.PlaceOrder

Hi,

I would like to ask why I can ´t use to set LMT price Close - 3 (forexample) but just LastValue(C) in row ibc.PlaceOrder. I need count LMT price from more variables.

Forexample in code below I used variable LimitPrice

``````LimitPrice = Close - ATR(5);

Symbol = Name();

if( LastValue( Buy ) )
{

// check if we are connected OK
if( ibc.IsConnected() )
{
// check if we do not have already open position on this stock
if( ibc.GetPositionSize( Name() ) == 0 )
{
// transmit order
ibc.PlaceOrder( Name(), "Buy", 5, "LMT", LimitPrice, 0, "Day", True );
}
}
}
else {
Error("IB Controller Interface is not connected");
}
``````

Thanks Jan

Because Close is an array variable but PlaceOrder's fifth argument expects number so you have to get element of array since elements of an array of numbers are type number.

Please try to understand the difference between array and number/array element.
https://www.amibroker.com/guide/h_understandafl.html

As mentioned above... Since Close is an array it means that it consists of N-elements of values ranging from bar index 0 to Barcount-1 of Close. So Close is not a single number but as amibroker.com article explains you have to think of it like an Excel row or column filled with multiple values. So speaking with Excel terms... for PlaceOrder's fifth argument you would have to pick single cell value of such Excel row named Close... e.g. LastValue(Close) would be the value of last cell of that range of values of row. In same way LastValue(LimitPrice) would be last "cell value" of your LimitPrice array variable (in Excel terms your "LimitPrice" variable would be a separate row somewhere above or below of "Close" row. So just like "Close" it is a list of numbers but not single number).

2 Likes

Thank you fxshrat.
So if i need
LimitPrice = Ref(C, -1) - 0.7 * ATR(5)
so is not possible ?

Jan

C'mon...
Please read carefully what has been written before...
As mentioned you just have to pick a number or an element of array for PlaceOrder's fitfth argument.
So if you want to get element of the bar prior to last bar then again use LastValue().

``````my_array = C - 0.7 * ATR(5); // this is ARRAY!
my_previous_array = Ref(my_array, -1); // this is ARRAY holding values of n-bars before!
//
LimitPrice = my_previous_array; // this is ARRAY being equal to my_previous_array variable!
//
Last_LMT = LastValue(LimitPrice);	// this is ELEMENT of array!
// And it holds previous bar's value
// one bar before last bar of array.
// Why?
// Because of Ref(..., -1)
``````

BTW if you do not know type of a variable then you may use typeof() orerator:

``````printf( "Type of LimitPrice: %s, Type of Last_LMT: %s", typeof(LimitPrice), typeof(Last_LMT));
``````
5 Likes

Thank you very much and thank you for your patience with me..

It works now…

Jan