Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

for loop - Python break or continue for a simple logic

Python novice here. I have the following simple logic to be implemented in python. I have made basic progress but cannot get into the logic to stop the execution when certain actions are performed. I am summarizing the logic in simple english, if there's anything thats not clear, please let me know. I kinda know that this can be achieved by a 'break' or 'continue' logic, but cannot seem to figure out and have been struggling since couple of days. Condition 5 and 6 are the pain points :-(


In a loop or in while GET below values from XLS Qty : Values 0, 1 or -1 Signal : Values Buy, Sell, Hold Trade Profit : 10 Daily Profit : 50

Condition 1

If Signal = Buy and Qty = 0 then Buy 1 stock; #Open a long position. This will be a new trade

Condition 2

If Signal = Sell and Qty = 1 then Sell 1 stock; #Close the long position from above. Closing the trade above

Condition 3

If Signal = Sell and Qty = 0 then Sell 1 stock; #Open a short position. This will be a new trade

Condition 4

If Signal = Sell and Qty = -1 then Buy 1 stock; #Close the short position from above. Closing the trade above

Condition 5

If Trade Profit is met do not take any new trades until the Signal changes (from Hold to Buy or from Hold to Sell) (Qty = 1 or Qty = -1, Signal value will be HOLD)

Condition 6

If Daily Profit is met do not do anything


Any help or guidance will be much appreciated. Thanks Stock

question from:https://stackoverflow.com/questions/65860446/python-break-or-continue-for-a-simple-logic

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...