I'm still very much experimenting and trying to learn how to use the programme properly.
I am going wrong with this script though. I am trying to learn how to write a script that opens the IB controller if 'something happens' (as specified elsewhere in the script) and then take an order from an array. A variation on this would be to take the value of the order from a user variable (In real life, I probably wouldn't do it exactly that way, but I'm tying to play with user specified parameters so that I could have that usability as I think that would be beneficial in the future when I start to involve my partner in the trading.
I'm new to afl and pretty new to coding.
Here's my try;
// Define the boolean user input variable.
launchIB = ParamToggle(" Launch IB Controller? ","No|Yes",0);
// Define ibc array as a function
ibc=GetTradingInterface("IB");
NaN = 0;
// Function to Launch IB controller if user selects yes
IIf(launchIB == 1, ibc, NaN);
//Allow the user to specify if they would like to set an order
setorder = ParamToggle(" Set an order? ","No|Yes",0);
//Define price array to use in the order
price = Param("Price to Buy",100, 0,500,1);
order = ibc.PlaceOrder("MSFT","Buy",101,"LMT",price,0,"GTD 20220916, 19:00:00 GMT", True); //define what order is
IIf(setorder =="Yes",order,NaN);// Trigger 'order' if boolean 'setorder' is true and therefore ==Yes
When I execute this code, the trading interface is launched and an order is sent to TWS, which is very exciting, because I made it do something, but very frustrating, because it is not doing the thing I want it to.
I have read the reference and my understanding is that the resulting value from both 'launchIB' and 'setorder' should be arrays?
I'm getting;
Error 1. Operation not allowed. operator/operand type mismatch
and
Error 5. 2nd argument of the IIf() call has incorrect type. The function expected a number here but found a string.
So, I'm a little lost. I know what a string is (so here I am guessing it is picking up "MSFT","Buy"... etc) but if I have set an array (e.g
ibc=GetTradingInterface("IB");
and
order = ibc.PlaceOrder("MSFT","Buy",101,"LMT",price,0,"GTD 20220916, 19:00:00 GMT", True);
then my thinking is that AmiBroker would return the array 'order' and that would launch IB controller and place an order if those arrays are returned.
Any advice on what I might not be understanding and how to achieve what I am trying to achieve?
Thanks