How do I use last bar's high as stop price in ibc.PlaceOrder?

Hi,
I am learning to use Amibroker to trade in IB. I am trying to place a stop order using last bar's high as stop price, so I coded it like this:

h1 = ref(H, -1);
ibc.PlaceOrder(Name(), "BUY", 10, "STP", h1, 0, "GTC", True );

But the order won't go through. If I change the stop price to a real number, it will go through. So how to use the last bar's high as a stop price?
Thanks,
HWM

@hwm, welcome to the Forum.

If you look carefully at the documentation for the function Ref(), you'll see that it returns an array.

If you need a number, you should use a function that takes an array and return a single value like, for example, LastValue().

IMO, spending time to carefully study the vast documentation of functions is always a useful exercise.

2 Likes

beppe,
Thank you so much for your reply. After reading the description of LastValue(), I can not believe I have not used it before. I will test it next Monday.
Also thank for the advise on studying the function document. I will take your suggestion.
HWM

@hwm, I suggest you also to review this past thread by @Tomasz: When scalar becomes an array, aka. type coercion in AFL

1 Like

beppe, thanks for the link, very helpful. Just read Common Coding Mistakes from the link in Tomasz's post, learned a lot.