Click here to Login





                                                   AMM script global variables do not appear to be thread safe

  0

0
Dave Walton
2014-08-17 16:01:37


Hi QS, I have several AMM scripts that I use at the same time. One script sets the variable and a different script checks the value of this variable and takes different action based on the state. It appears that the QS implementation of global variables is not thread safe. When I turn on multithreading for higher optimization performance, I get very strange results. After doing some debugging I found that the global variable is getting changed unexpectedly by the AMM script running in another thread (for a different simulation being run in a different thread). Could you look into this and provide a solution? As of now I can run in single threaded mode but the performance is not good as you might imagine.


QuantShare
2014-08-18 05:26:29

  0

Best Answer
Hi Dave,

Global variables are thread safe, however you are running simulation in multi-threading and thus each simulation is run in a separate thread.
Since these variables are shared by all programs, you may easily come into a situation where you update it in the first MM of the first simulation then reads its value from the second MM of the second simulation.

In order to fix this, you must create a different variable for each simulation. Here is how you can do this:
Global.SetVariable("Name_" + Functions.SimulationID, "Value");

"Functions.SimulationID" is available in the "OnStartSimulation" only, so you can store it in a variable in the "Global" event if you want to access it from other events.





Dave Walton
2014-08-18 08:45:09

  0

Thanks QuantShare. I figured there was a way to do it. I didn't know about the SimulationID.


No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Set Global Variable
Minimum Variance Optimization with Solver V1.1- AMM
Global Market Rotation Strategy V1.4
Global Sector Rotation Strategy V1.0
Adaptive Asset Allocation Butler V1.3 AMM

How-to Lessons
How to get stocks for a particular index using the global script
How to run a screen or a watchlist from a script
How to execute a script at regular intervals
How to detect whether price movements are predictable or not
How to plot a time-series that do not update the chart scale

Related Forum Threads
Money Management Script variables and more
Global variables
Equity to Symbol - AMM / Script
Adjust the Entry and exit prices of trades in AMM script
AMM ATS script

Blog Posts
Charting & Scripts - Manage stock charts using the global script
QS Trading Software: Global Script
Programming skills are not that important
How to Detect Potential Issues/Errors in Your Historical Data?
Several money management strategies in a trading system









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



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.