If you are calling GetVariable, you can't ASSUME that it is array. It can be scalar and if it is, you are accessing array that does not exist and creating access violation. sigBuy in your AFL is exactly that - SCALAR value, not array.
No, you don't understand at all.
In your C code you have to programmatically check for type array of variable so that you do not ever get exception in case variable is not type array.
You make explicit SCALAR assignment in your AFL formula
sigBuy = 0; // 0 IS A SCALAR !!!
You must NEVER use AmiVar .array field UNLESS you verify if .type is VAR_ARRAY
In your plugin you are doing this:
AmiVar sigBuy = gSite.GetVariable("sigBuy");
And sigBuy is a SCALAR value and you can ONLY access .val field, not .array.
Only if you assigned ARRAY to sigBuy, like this:
sigBuy = Cross( C, MA( C, 10 ) ); // sigBuy is truly an array
you would have type == VAR_ARRAY and you could access .array
Really writing PLUGINS IS HIGHLY DISCOURAGED because 99.9% of people "don't get it right"
AFL is whole lot easier since it does automatic type coercion hiding all details and problems, see: When scalar becomes an array, aka. type coercion in AFL but in C/C++ you are in unknown dangerous waters and no one is protecting you from evil
You are getting exception because you are doing BAD things, namely accessing NON-existing variable. Local variable does NOT have global name and if you attempt to access it via GetVariable you would get nothing. You are NOT doing necessary checks in your code and make ASSUMPTIONS (really bad thing). You should NEVER assume that any variable exists and you should ALWAYS check what you are getting from GetVariable.
GetVariable by design accesses GLOBAL variables because it operates in global namespace. If you want to access local values, PASS THEM as arguments to the function exposed by DLL.
Again, writing plugins is DISCOURAGED because most people don't do it right. This thread illustrates this.
Specifically using GetVariable is BAD PRACTICE. You should be passing values AS ARGUMENTS to DLL exposed function. Why it is bad practice ? Because it produces hidden relationships between plugin and AFL code instead of clearly defined API by means of arguments passed to the function.