NexusFi: Find Your Edge


Home Menu

 





Range Break Help


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ummmx2 with 3 posts (0 thanks)
    2. looks_two ABCTG with 2 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 bchip with 1 posts (1 thanks)
    1. trending_up 1,662 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

Range Break Help

  #1 (permalink)
ummmx2
Miami Florida/Dade
 
Posts: 7 since Oct 2016
Thanks Given: 2
Thanks Received: 0

Hello,

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.

 
Code
Inputs:
NumBarsBack (108),
TimeBegin (1805),
TimeEnd(0200);

Variables:
BarBackNo (0),
ONRHigh (0),
ONRLow (0),
ONRHighLine (ONRHigh);

ONRHigh = -99;
ONRLow = -99;

If Date <> Date[1] then Begin
	If Time =  TimeEnd then Begin	
		For BarBackNo = 0 to NumBarsBack
		Begin 
			ONRHigh = Highest(H, NumBarsBack);
			ONRLow = Lowest (L, NumBarsBack);
			End;
	End;
	If Close > ONRHigh then Value1 = text_new (D, T, H, "Up");
	If Close < ONRLow then Value2 = text_new (D, T, L, "Down");	
End;

ONRHighLine = TL_New (Date, Time[TimeBegin], ONRHigh, Date[1], Time[TimeEnd], ONRHigh);
TL_SetExtRight(ONRHighLine, True);
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.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Are there any eval firms that allow you to sink to your …
Traders Hideout
Futures True Range Report
The Elite Circle
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
Battlestations: Show us your trading desks!
18 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623


ummmx2,

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.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #4 (permalink)
ummmx2
Miami Florida/Dade
 
Posts: 7 since Oct 2016
Thanks Given: 2
Thanks Received: 0

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.

Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

ummmx2,

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.

Regards,

ABCTG


ummmx2 View Post
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.


Follow me on Twitter Reply With Quote
  #6 (permalink)
ummmx2
Miami Florida/Dade
 
Posts: 7 since Oct 2016
Thanks Given: 2
Thanks Received: 0

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.

 
Code
Inputs:
NumBarsBack (108),
TimeBegin (1805),
TimeEnd(0200);

Variables:
BarBackNo (0),
ONRHigh (0),
ONRLow (0),
ONRHighLine (ONRHigh);

ONRHigh = -99 //this is an attempt to reset the variables after each day but I suppose ONR high variable reset should be put at a positive 9999?
ONRLow = -99 

If Date <> Date[1] then Begin //Using this to reset the code every day
	If Time =  TimeEnd then Begin //This line is to start executing the code when the range is over	
		For BarBackNo = 0 to NumBarsBack //This section is to look back (at the range indicated from this bar back to wherever number bars back I specify)
		Begin 
			ONRHigh = Highest(H, NumBarsBack); //these are to get the high and low within that range and to store in a variable
			ONRLow = Lowest (L, NumBarsBack);
			End;
	End;
	If Close > ONRHigh then Value1 = text_new (D, T, H, "Up"); //we are now attempting to use the stored variables as the high/low of the range and assessing a break above/below
	If Close < ONRLow then Value2 = text_new (D, T, L, "Down");	//I wanted text new as a way to check to make sure the breaks were happening in the right place
	Print(ELDateToString(date), Time, Time:0:0, ONRHigh, ONRLow); //this is a sad attempt to print something to the printlog because I have no idea what I'm doing here
End;

//ONRHighLine = TL_New (Date, Time[TimeBegin], ONRHigh, Date[1], Time[TimeEnd], ONRHigh);

Reply With Quote
  #7 (permalink)
 bchip 
Torino, Italy
 
Experience: Advanced
Platform: TradeStation
Trading: ES,YM,CL,GC
Posts: 132 since Sep 2017
Thanks Given: 160
Thanks Received: 116


ummmx2 View Post
Hello,

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.

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

Hope that helps.

Reply With Quote
Thanked by:




Last Updated on March 23, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts