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 new to easy language and just trying to code a few basic things for practice. My exercise in this code was to create a range and get the computer to plot a horizontal line framing the range (at the high and the low) from the start time to the end time and then recognize a break to the upside or break to the downside of the range.
Thought Process:
I created a for loop to try and get the computer to recognize the highest high and lowest low across a specified number of bars back.
I then tried to store this value in 2 variables called ONRHigh and ONRLow.
I then wanted to see if I could get text to print on the bars that closed higher or lower than the range for that day to verify that I had wrote the code for the highest high and lowest low of the range correct. I did not get the correct print. It would randomly print maybe one "up" during each day at a location that did not make sense.
I also wanted to see if I could plot the trendlines to see if maybe I could check where it's plotting the lines but when I tried to apply it to the chart I keep getting an error "tried to reference back more bars than allowed by the current maxbarsback". I tried changing this to extremely high numbers and no dice. I know its with the trendline section of the code because when I put the /// to comment it out the error does not happen.
If anyone could please help me or point me in the right direction I would really appreciate it as it's a bit frustrating when I have no idea what I'm doing wrong.
Can you help answer these questions from other members on NexusFi?
you perform most of your code logic on the first bar of the new day only. Unless this bar happens to have the same time as your TimeBegin input, you might not perform the check on every day. Besides that it's not clear why you would use a loop here as the ONRHigh and ONRLow variables would only hold the value for the last loop iteration anyway and highest and lowest functions internally perform a loop already.
This is a good example where commenting the code could be helpful to explain your intentions, as without knowing why you do what you do it is harder to point you in the right direction.
Ok so I had it perform the logic on the last bar because I wanted it to start the look back period at the end of where I wanted the range. So say I wanted the range from 5pm-2am. I had it start the logic at 2am and look back whatever amount of bars from there. In this case 108 bars. I wanted to store the highest high within that range and the lowest low within that range so that after the end time I could assess a break on whatever side of the range. This is why I thought a for loop would be good to store the value of the variables for just the day and restart the next day.
I would suggest using the print reserved word to check when your logic is evaluated and what exactly happens within the code and if it is even executed when you think it is.
Ok I've been stuck on this for a few days and I really don't know what to do or how to go about fixing this. I tried to lookup and implement the print function but it's not sending anything to the print log and the help screen for the print function is confusing. I wrote out my logic line by line so that maybe I could get some insight as to where I'm going wrong with my thinking.
I would try a different approach, if I understand it correctly your basically looking at the ORB Strategy.
I see you do the FOR loop, but you dont have to, the engine goes and checks each bar from back to front,
so its technically doing the for loop for you.
So you are currently
- looping through each bar and then
- doing a second loop at each bar
To get the high and low of each bar during a time you can
---Reset----
If Date <> Date[1] then
Begin
ONRHigh = -999999;
ONRLow = +999999;
end;
---Get the range values---
if Time >= 0900 and Time < 1000
begin
ONRHigh = MaxList( ONRHigh, High );
ONRLow = MinList( ONRLow, Low );
End;
---After closing time---
if Time >= 1000
begin
if High > ONRHigh buy at....
if Low < ONRLow sell at...
end;
This will only get you 1 day's view, i.e. it will work for an algo but not
for an indicator where you try and plot every days range.
* you also need to make sure that the timeframe selected is smaller so it fits in the timerange