I would like to calculate and set a variable in the strategy section of a trading system; for example Risk On (1 or 2). I would then like to pass and access the value of this global variable result as a vector in AMM.
Can that be done, and could you kindly point me to some syntax example?
You can do this by creating a global variable then referencing that variable in the MM script.
Here is how:
QS language:
You must first create a custom function "Ex: SetGlobalVar" that creates a global variable using "Global.SetVariable". After that in your system's formula, type:
SetGlobalVar("myvar_".GetSimSetting(_SimulationID));
MM Script:
double a = (double)Global.GetVariable("myvar_" + Functions.SimulationID);
You can access "Functions.SimulationID" only in the "OnStartSimulation" event. If you want to use it in other events, then create a variable in the "Global" event and fill it with the value retured by "Global.GetVariable"
Thanks for your reply! Yes I have a cf, see above at "Custom function". But I found the error, comparing to your suggested function: When calling my custom function in the strategy window, I need to assign the return value to a variable, temp in this case. So the correct code is:
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.