While Loop Freezing?

Joined
Feb 19, 2021
Messages
2
Reaction score
0
Hey guys, I'm a newb. I'm trying to get this software to run on my computer but I seem to keep getting stuck in my while loop.

This is for trading, I am returning a set of information (variable?) to unrealizedPnL in my function pnl.

It updates every second.

[python]def pnl(self, reqId, dailyPnL, unrealizedPnL, realizedPnL):
print("UnrealizedPnL:", round(unrealizedPnL))
if unrealizedPnL < -100:
print("Step 1", unrealizedPnL)
while unrealizedPnL < -50:
time.sleep(1)
print("Step 1.5", unrealizedPnL)
else:
print("Step 2, Worked", unrealizedPnL)[/python]

The numbers in step 1 (line 3), -100 and the -50 in step 2 (line 5) are just because its almost impossible to make a profit for the test every time. So I just open a trading position, let it lose money then adjust the numbers to run the test. I'm just trying to get the steps to work.

Once my account goes past -100, we goto step 1.5, the while loop. And it just loops infinitly (I know it does that) BUT.. if I close out my positions and my unrealizedPnL goes back to 0, or even moves around to any number, the while loop stays LOCKED on what ever number initiated it. It doesnt keep updating.

I've got time.sleep(1) in (line 6) while I try and figure this out and I'm not 100000x spammed by the while loop. Atleast I'm 5000x spammed hahah **biggrin**

The end goal logically is, if I make over $100, we trigger a new set of conditions, if we stay above $50, all good. If we drop under $50, execute a command.

Let me know what you guys think!! Where am I messing up with this logical flow?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top