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'm trying to write a strategy that looks at the first hour of trading and then buys or sells short based on the price after that hour. if the price moves under the low of the hour I want to sellshort, and vice versa for the high. intrabar order generation is true as I want to enter the trade as soon as the price crosses one of the thresholds.
My code looks something like
Value1 = lowd(0)
Value2 = highd(0)
If time>1030 and close>value2 then buy next bar at market
else
if time <1030 and close<value1 then sellshort next bar at market
End;
For some reason this isn't working as looking back over years of data generates 0 trades.
Appreciate anyone who can help!
Thanks
Can you help answer these questions from other members on NexusFi?
Your variables Value1 and Value2 keep getting updated with every new bar. They will always hold the current high and low of the day and therefore your condition basically states close > highd(0) and close < lowd(0) which will never evaluate to true.
You can for example only update variable values until a certain time using conditional branching i.e. "if Time <= 1030 then begin...".
Apart from that I would suggest using meaningful variable names instead of the generic ones as this will help you in creating code that is easier to read and understand and in turn might say for sometime the future.
These are instructions are for Strategy Analyzer....or a programmer
both comparisons for High and Low breakouts should be greater than or equal to 1030....your current low is checking for less than 1030????...when looking for your breakout both times should be greater than or equal to 1030....
so you can start by setting your high value and low value on your first tab...and only execute that once...set a switch to never execute it again....
and on tab2 check every subsequent bar check to see if the high is greater than the high value and time is less than 1030 then if so update the high value...do the same for the low value...if the low is less than low value and time is less than 1030 update the low value.....
next tab ...if time is equal to or greater than 1030 and high is greater than high value...go long...set variable1 =1....same for low if time is greater than or equal to 1030 and low is less than low value ...go short...set variable2 =1. set a switch so this only executes once otherwise you will be going long/short on every bar....by using two variables you can satisfy both long and short...happening at different times...so you may go long at one time and short at another
setting a switch would be like variable0 equal 1.....so when you want to execute something only once...your first stmt would be if variable0 not equal 1...execute the tab....and then set variable0 = 1 the tab will only execute when variable0 not equal 1.....
so when you find your breakout....just use variable1 as a switch for high value and variable2 for low....anytime you turn off your switch....you can check for high or low again...
Something to think about......why use any times at all.....as the market goes higher you go long....if it goes lower...you go short....follow it up or follow it down.....Hmmmmm….as you go long you continue to update your high value....as well as doing the same for low...
I'm very new to this so is there any sort of example somewhere of that sort of setup or something similar I can work through? I've been trying to teach myself easylanguage but I wouldn't say i'm proficient enough to take create what you mentionedso easily.
are you using NT7 or NT8......the Strategy Analyzer in NT7 is very easy to use.....and learn you could be writing strategies in no time....with no programming...
I also don't understand the part of your post about using times at all? I pretty much want the dust to settle and use the hour bar range as the breakout decision maker.
set your breakout time to be a variable....and you can look at 5 min, or 10 min or 15 mins or an hour....anytime..... you may be pleasantly surprised....
by not setting any time variable....you are always looking for the next breakout....and once you go long or short you keep updating you high value or low value...…...then when I breaks it again... you go long or short again...basically following the market down or up....
I know this is probably very simple but I don't think im following. is there any sort of preexisting code that creates the breakout into a variable and then maybe from that I can understand the second part as well. I learn better that way.
still very new so apologies for not understanding everything.
Thanks