MATLAB Answers

How to change variable size(s) with timers without causing errors?

1 view (last 30 days)
BuMatlab
BuMatlab on 1 Oct 2019
Commented: Guillaume on 1 Oct 2019
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 Comments
Guillaume
Guillaume on 1 Oct 2019
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?

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 1 Oct 2019
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 Comments
Guillaume
Guillaume on 1 Oct 2019
The callback that you show above doesn't match at all the function in your question.

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!