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)
Is There a way to create a flip flop switch with NT?
Well, this time I need some help with a switch device. Let me try to explain (sorry for my bad english):
The system I'm trying to write is not exactly this one, but it uses a similar mechanism.
I use 2 variables.
BuyModeOn and ShortModeOn. When BuyModeOn == 1 and theres a buy signal, I want the system to execute my buy. When BuyModeOn == 0, I want the system to ignore my buy signals. The same with ShortModeOn.
So, lets say BuyModeOn goes 1 when Price moves above an MA. The code I tried is like this:
So, the code works... but only at the EXACTLY time of the cross above or below. It seems like the ModeOn values dont hold for the rest of the bars. Why is that? Do I need to make it inside a loop?
PS: While I was writing the thread, I just had the though that its because the variables are inside the OnBarUpdate(), initially setted to 0... So in every bar it becomes as 0... I'll try it soon, but I'll post it anyway... I may be wrong after all.
Thanks in advance!!
Can you help answer these questions from other members on NexusFi?
Hi @Momozo, it might help you to see things more clearly if you investigate using the 'bool' type for flags and also the built-in CrossAbove and CrossBelow functions. Always keep clear meanings for flags, usually it's a sign of bugs to follow if their meanings and uses starts to merge.
Thanks, Ratfink. I already tried using bool type, using true and false instead of 1 and 0. But it gave me errors. I've spent a lot of time searching for a solution, but with no success.
In Amibroker, there was a function called "flip(condition1, condition2)", that worked for this purpose. When condition 1 gave a true signal, it would remain true until condition 2 became true. Then both conditions became false. Quite handy!
I saw a sample at ninjatrader forum that was exactly like the way i wrote the code, but there was one difference: they used variable0 instead of BuyModeOn (dont know if it influences...).
Well, I'll keep looking. Oh, and I use MRO() for one of the conditions. Do you think it can cause problems?