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();
Buy = 1;
if( LastValue( Buy ) )
ibc = GetTradingInterface("IB");
// 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 );
Error("IB Controller Interface is not connected");
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).
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.
// 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));