How to change variable size(s) with timers without causing errors?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello -
I am trying to run a simple timer function which runs every 10 seconds to monitor position(s) in the stock market. More specifically, I have created a variable called tradeFlag, which initializes as an empty variable ([]) and takes the value 1 if a trade is executed. What I am trying to do is prevent another trade from being executed by using simple if statements, like below:
tradeFlag = [];
function timer(hObj, eventdata, tradeFlag)
if isempty(tradeFlag) & % a market event happens
% submit order
assignin('base','tradeFlag',1)
end
end
However when I run this function, I either get a "Not enough input arguments error" or or an else block will not be executed. Is there a better way to do this? What am I missing here?
Many thanks!!
3 件のコメント
Guillaume
2019 年 10 月 1 日
In order to understand the not enough input argument error, we would need the full text of the error message and at the very least the code thar creates the timer (and its properties if it's done on several lines).
"or an else block will not be executed" For that we would need to see the full if...else block.
"What I am trying to do is prevent another trade from being executed" What does a trade being executed actually mean in terms of code?
回答 (1 件)
Steven Lord
2019 年 10 月 1 日
It depends on how you set the timer object's TimerFcn property.
Rather than depending on a variable in the base workspace, based on the limited description of what you're trying to do I would probably store the data in the UserData property of the timer object (which is passed into its TimerFcn as the first input.)
2 件のコメント
Guillaume
2019 年 10 月 1 日
The callback that you show above doesn't match at all the function in your question.
参考
カテゴリ
Help Center および File Exchange で Transaction Cost Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!