DLL Exception when set 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 :slight_smile:

3 Likes