How to make code repeat itself every second (Trading Toolbox)

17 ビュー (過去 30 日間)
Arm Dan
Arm Dan 2018 年 8 月 1 日
編集済み: jonas 2018 年 8 月 1 日
I have a lot of experience in coding and I wanted to create something new which I hadn't done before. So when I came across the Trading Toolbox I was very excited to find out you can do automated trading with it. I read the documentation, which was pretty clear, a couple of functions to connect to a certain broker, some order functions and a disconnect function. What I couldn't find out though is how you can make sure that your code is run constantly, otherwise automated trading isn't possible since trades can only be made or closed once every time you run your code. That shouldn't be the case, the code should be repeated every second or minute for that matter. Does anyone know how this can be achieved?

採用された回答

jonas
jonas 2018 年 8 月 1 日
編集済み: jonas 2018 年 8 月 1 日
while true
%Insert code here
pause(1)
end
Bonus, if your code takes a long time to run and you want the script to start exactly once per minute.
while true
tic
%Insert code here
pause(60-toc)
end
  2 件のコメント
Arm Dan
Arm Dan 2018 年 8 月 1 日
Thank you very much!!! This will just do the trick. One more thing though, for what do you use tic and -toc exactly?
jonas
jonas 2018 年 8 月 1 日
編集済み: jonas 2018 年 8 月 1 日
No problem!
tic starts a timer and toc outputs its elapsed time.
Assume you have a script that takes 10 seconds to run from start to finish. If you type pause(60) at the end, then the entire script will take 70 seconds to run. So, pause(60-toc) subtracts the elapsed time and ensures that the script is executed exactly every 60th second.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTransaction Cost Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by