Click here to Login





                                                   Set Global Variable Between Strategy and AMM

  0

0
swalk10
2014-08-28 19:59:42


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?

Thanks!



QuantShare
2014-08-29 04:51:24

  0

Best Answer
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"



swalk10
2014-08-29 08:29:47

  0

Perfect, thank you very much!


SergejSuperstock
2016-04-28 14:51:52

  0

Strategy:
iRank = comp(dScore, "rank", 1, bFilter);
mySetAmmVariable("giCurrSymbolRank", iRank);

Custom function "mySetAmmVariable" (varName is string parameter, varValue is number parameter):
Global.SetVariable(varName[0], varValue[0]);

AMM OnNewPosition:
int iCurrSybolRank = (int)Global.GetVariable("giCurrSymbolRank");


This does not run. Problem is at calling of "mySetAmmVariable" in Strategy. Can anybody help? Thanks in advance!



QuantShare
2016-04-29 06:37:49

  0

Do you have a custom function called "mySetAmmVariable"?

You need to create one in "Tools -> Create Functions" or you can download this one from the sharing server:
Set Global Variable





Set Global Variable (by QuantShare, uploaded several months ago)
No notes

Rate an item Rate an item Rate an item Rate an item Rate an item Number of downloads Notes Report an item

SergejSuperstock
2016-05-02 14:07:46

  0

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:

Strategy:
iRank = comp(dScore, "rank", 1, bFilter);
temp = mySetAmmVariable("giCurrSymbolRank", iRank);

Custom function "mySetAmmVariable" (varName is string parameter, varValue is number parameter):
Global.SetVariable(varName[0], varValue[0]);

AMM OnNewPosition:
int iCurrSybolRank = (int)Global.GetVariable("giCurrSymbolRank");



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
Global Market Rotation Strategy V1.4
Global Sector Rotation Strategy V1.0
Global Market Rotation Strategy V1.1
Global Market Rotation Strategy V1.0

How-to Lessons
Difference between the watchlist and the screener tools
How to create and trade a Neural Network model
How to get stocks for a particular index using the global script
How to plot support and resistance lines automatically
How to download EOD quotes for active and valid stocks only

Related Forum Threads
Set Global variable and running calculation Functions in MM scrip...
Set Position Size by Ticker Within Main Strategy
AMM script global variables do not appear to be thread safe
Best practices for using a Global Variable
AMM scripting - error and some questions

Blog Posts
Backtesting a Strategy Based on Bond and Stock Index ETFs
Create indicators, composites and trading systems using QL and CS...
Trading System: Moving average crossover and few others buy and s...
How to get buy and sell orders for a portfolio based on a trading...
3 Items To Get and Trade the News In QuantShare Platform









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.