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)
I am trying to get this code to work using 5 minute bars:
If Low Crosses below Value1 and High Crosses above Value 2 then
Buy Next Bar at stop;
My problem is that the Low cross and the High cross do not occur at the same time
What I do not know how to do is to say is is the high crosses Value 2 , lets say at 10:55 then sell next bar if Low crosses below Value 1. So , let's say Value 2 occurs at 10:55 and value 1 occurs at 11:45; how is this coded ?
The key is that Value 2 must occur before value 1 is activated.
Thankyou
Can you help answer these questions from other members on NexusFi?
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,058 since Dec 2013
Thanks Given: 4,409
Thanks Received: 10,226
Calculations are performed every bar, so if the two conditions don't occur on the same bar they will never trigger. So you need to keep a track of this occurring on previous bars. There's many different ways you can do this depending upon how recently/close together you want the two conditions to happen. One way would be to use the mro function for example
You can create a variable, Keep2, to store a value. Clear it before 1055, then set it at 1055 if your condition occurs. At 1145, you will know if the condition occurred at 1055. Perhaps this could be done with less lines of code, but it will work.
as the other posts indicate you will likely have to split your condition into separate checks. One idea could be to store the value of CurrentBar each time the High crosses Value2. At the moment the low crosses Value1 you can check the value of CurrentBar agains the value stored in that variable and allow the entry if the cross occurred within X bars ago.