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)
For "strategies", is there a way to run it ONCE & have it turn itself off?
I want to write a strategy to place a simple order (not run a full-blown algo). Here's the order: buy at market and place a limit order -- (the limit order is at a higher price, so it's a profit target). I can do that, but, does it just keep running... placing the same order over and over on every single bar? I want it to run ONCE, and then have it shut itself off (turn it's "status" off). Is there a way to do that from within the code?
(FYI I've never used strategies before, I've always used keyboard-shortcuts/'hotkeys', but I'm trying to learn how to automate orders. BTW I'm using MultiCharts-with-EasyLanguage.)
(BTW, notice how the Title of my thread told you EXACTLY what my thread was about? Whereas most thread Titles are very VAGUE, just saying.)
Can you help answer these questions from other members on NexusFi?
Yes, there are a few ways you can do this. Check out the "Once" reserved word, you can check for real-time processing and if true, use Once. Something like the pseudo code below. Or you can create a switch, also in the pseudo code below. There are other, more sophisticated ways as well. Hopefully this gives you a couple of ideas to work on and test.
Yes, thank you, that makes sense to use a flag variable, I DID think of this already, but the problems with it are:
1) The strategy is technically still running, so it consumes PC resources to keep checking the flag every bar (but I guess that's not really a big deal).
2) As I place new orders, the dead strategies (with status off) build up in the list of strategies, and I'll have to manually delete them at some point.
BUT, yeah, I can do it, I was just wondering if there was a way for the strategy to delete itself since that's the perfect way to deal with simpler orders/strategies. I'm surprised the original EasyLanguage creators didn't think of this (Omega Research back in the 1980's/1990's).
I am assuming here you want the order to persist until canceled or filled. The problem is that for systems, the program assumes you want to cancel the order if not filled in the next bar - fill or kill. That is prevent needing to cancel an order for each adjustment to its stop or limit levels on each bar, and normally save processing power and order traffic for TS. TS could have designed ordered to stand, but need cancelling every bar.
It seems what you might want is a staged order that has your target entered automatically. You can create a custom OSO order that would place your two orders - with the limit target being x% or X points over the entry. Could work for what you are wanting if that is all you want in the system.
An alternative is to have the system continue to run and just replace the limit order at the same level or adjusting the level, or to have a condition after the order entry as some of the other contribuors have suggested, that tells it to back off once an order has been entered. Perhaps you just want the entry signal and level to show up on the trade manager so you can enter manually (or not) in case something crazy is happening - trump making an unexpected corona announcement or whatever. I like doing that (Manual entry, not making corona announcements). On the other hand, my systems tend to look for an hour or five in a trade, so I have time to do that. (I will omit a discussion of why that is OK unless its a volatility breakout type sys that is designed to try and catch outlier/low probability eventsand other provisos).