Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
This might seem like a silly and basic question. But
When you write a script to take a position when certain conditions occur,
("if this and this and this then do that") how do you make sure the script does not keep taking new positions?
So for example: if I wrote a script to execute a buy of one ES contract when the macd crosses above the signal line, how would I limit the actual number of trades? That particular event could happen a lot.
Can you help answer these questions from other members on NexusFi?
I can't believe that I have not done this in so long that forgot how to do a while loop.
Which, in the clarity of a nights sleep, I realize is the answer.
If you set EntriesPerDirection to 1, that should stop it.
I believe UniqueEntries does something similar, but I've never used it. I think it stops the entry with the same tag from triggering twice, but I'm not sure...
It's simple. I use a state machine. I have three states: IAmNoPosition, IAmLong, IAmShort. When I have no position, the state is IAmNoPosition. When I enter a long position, the state changes to IAmLong, likewise for short. I can only enter a position when the state is IAmNoPosition, and I can only exit a position from IAmLong or IAmShort. If I exit a position, the state changes to IAmNoPosition.
So in your case, the MACD crossing would change the state from IAmNoPosition to IAmLong (after entering the order, and possibly checking the ack).