Hi There
I am trying to create a horizontal trend line indicator based on my forex trading strategy.
The idea is to check on the hourly chart the daily closes back for a year.
1) Loop through daily closes for 1 year.
2) check if they closed within the same area more than 3 times
3)Draw a horizontal line at that point.
I have started the code but not sure if its even possible to do what I want as you can use a daily indicator on a hourly chart.
Thats why I am looping through the Dhigh() Dlow() DClose() functions.
margin = 50
FOR i = 1 TO 365 DO
dayclose = DClose(i)
//dayhigh = DHigh(i)
//daylow = DLow(i)
resareatop = dayclose + margin*pipsize
resareabot = dayclose - margin*pipsize
resistancelines = close > resareabot and close < resareatop
if summation[365](resistancelines) > 3 then
DRAWHLINE(close)coloured(255,0,0)
endif
NEXT
return
I dont think you can use summation as that period will be 365 hourly periods.
I was thinking about using a nested For Loop with a counter if counter is greater than 3 then draw line.
I have attached images of what I am trying to do.I added the lines to daily chart and when you switch to the hourly chart those lines still act as major support and resistance lines.
Any guidance would be greatly appreciated.
Thanks
A nested loop would be the solution, but you may be stuck with the infinite loop bug limit. Repeat after me : ” we NEED arrays !!” 🙂
Getting slightly better but the results are still not ideal. run in hour timeframe
margin = 10
numberofrejections = 4
FOR i = 1 TO 365 DO
rescounter = 0
supcounter = 0
dayhigh = DHigh(i)
daylow = DLow(i)
resareatop = dayhigh + margin*pipsize
resareabot = dayhigh - margin*pipsize
suptop = daylow + margin*pipsize
supbot = daylow - margin*pipsize
FOR i = 2 TO 365 DO
if DHigh(i) > resareabot and DHigh(i) < resareatop then
rescounter = rescounter + 1
endif
if DLow(i) < suptop and DLow(i) > supbot then
supcounter = supcounter + 1
endif
next
if rescounter > numberofrejections then
DRAWHLINE(dayhigh)coloured(255,0,0)
endif
if supcounter > numberofrejections then
DRAWHLINE(daylow)coloured(0, 255, 0)
endif
NEXT
return
Is it possible to create dynamic variables.
IE
for i=1 to 20 do
l(i) = i
next
And Yes Arrays would be fabulous. PLEASE PLEASE PLEASE.
No that’s what are arrays 🙂