Page 1 of 1

Trick in finding Support/Resistance point

Posted: Sat Jan 20, 2007 10:51 am
by ratio
In designing a long term trading system, I was looking for a way to identifie the Support price point once I was in the trade.

I had decide that a resistance point could be identifie when a number (n) of Bar in both side of a past bar had a Higher Low. So if I am looking for a support with 4 bar on both side, I would then have a loop that look in the last 500 bar for the first point in time where I had a bar with 4 higher low on each side. This would then constitute my support point.

This involve 2 imbricate loop, one that go back in time, up to 500 bar or until I found my support.

And another one that every day check 4 bar on each side, to test for the Highest Low.

this code basically do that.
//////////////////////////////////////////////////////////////
'
' Find the Low Turning point
'

StillTrue = TRUE
MaxLookBack = 500
Looker = -1
LowTurningPointPrice1 = 0
LowTurningPointPrice2 = 0

DO
StillTrue = TRUE
Looker = Looker + 1
BackOffset = SwingLen + Looker
FOR i = 0 to SwingLen
IF StillTrue = TRUE THEN
IF instrument.Low[BackOffSet] > instrument.Low[BackOffSet-i] OR _
instrument.Low[BAckOffSet] > instrument.Low[BackOffSet+i] THEN
StillTrue = FALSE
ENDIF
ENDIF
NEXT

IF StillTrue = TRUE THEN
LowTurningPointPrice1 = instrument.Low[BackOffset]
LowTurningPointDate1 = datetojulian(instrument.Date[BackOffset])
LowTurningPointBar1 = instrument.Bar[BackOffset]

ENDIF

LOOP UNTIL Looker > MaxLookBack OR LowTurningPointPrice1 <> 0

//////////////////////////////////////////////////////////////////////
You may have a fast CPU this take a lot of time to compute.

------

I then had this dream that this could be resolve like this. You create an IPV Series where you just do the following.

You create an IPV Series variable and on you Entry Order you assign its previous day value and you check against the Lowest low of double the period you are looking.

Ex: I want the latest price where I had 4 day with highest Low on each side. So: Dip = 4


LastLowDipPrice = LastLowDipPrice[1] ' My IPV Series variables
'
' Now find the latest Dip Point
'

if instrument.Lowest("Low",Dip*2+1) = instrument.Low[Dip+1] THEN
LastLowDipPRice = instrument.Low[Dip+1]
endif

///////////////////////////

Voila!! You have an IPV Series that carry your latest support price.


If you want to search for a Support where you had 6 day on the left and 3 on the right. Market start to bounce from a retracement type.

You would nead 2 variables MaxDipLength and DipPOint
LeftDipLength=6
RightDipLength = 3

if instrument.Lowest("Low",LeftDipLength+RightDipLength+1) = instrument.Low[RightDipPoint+1] THEN
LastLowDipPRice = instrument.Low[RightDipPoint+1]
endif

////////////////////////

This will compute probably 50 times faster. and obviously you can reverse that to find the resistance point.

//////////////

Here is sample output of the IPV Series with a 5 day Dip point

Posted: Sat Jan 20, 2007 2:55 pm
by sluggo
If you have access to Tradestation, you could copy the source code of the Tradestation User Functions called SwingHigh and SwingLow, as they do exactly what you want.

Code: Select all

Function:
SwingHigh(OCCUR, PRICE, STRENGTH, LENGTH)

Parameters:
OCCUR      which occurrence (i.e. 1=most recent, 2=2nd most recent, and so on)
PRICE      specifies which prce is to be used (High, Low, Close, etc)
STRENGTH   specifies required number of bars on either side of swing bar
LENGTH     specifies the number of trailing bars to consider
Thus SwingHigh(1, High, 3, 500) would look back at most 500 bars (Length=500) and find the most recent occurrence (Occur=1) of a bar whose High (Price=High) is greater than the highs 3 bars before and 3 bars afterwards (Strength=3).

Also SwingLow(2, Close, 4, 200) would look back 200 bars and find the second most recent occurence of a bar whose Close is less than the closes 4 bars before and 4 bars afterwards.

The concept of User Functions has two big advantages. First, you can create a user function yourself (hence the name User Function). You don't have to beg the software developer to custom program it for you and put it into a future release of the program, then hope and pray that your request is granted and granted soon. Second, the code resides in exactly one place: the User Function Library. You don't have to copy-and-paste N lines of code into every system that uses your Function; you just call it as a subroutine. If you want to upgrade the function (killing a bug, adding a feature, speeding up the runtime, etc.) you don't have to go searching all over everywhere to find all the copies and change them all. There's just one place to look (the User Function Library), you change it there, and presto, the change automatically propagates to all systems that call that User Function.

Posted: Sat Jan 20, 2007 3:31 pm
by ratio
I know I have the same Swing function in Genesis FT

But I was looking for the best way to do this faster

Posted: Mon Jan 22, 2007 5:07 pm
by danZman
sluggo wrote:If you have access to Tradestation, you could copy the source code of the Tradestation User Functions called SwingHigh and SwingLow, as they do exactly what you want.

Code: Select all

Function:
SwingHigh(OCCUR, PRICE, STRENGTH, LENGTH)

Parameters:
OCCUR      which occurrence (i.e. 1=most recent, 2=2nd most recent, and so on)
PRICE      specifies which prce is to be used (High, Low, Close, etc)
STRENGTH   specifies required number of bars on either side of swing bar
LENGTH     specifies the number of trailing bars to consider
Thus SwingHigh(1, High, 3, 500) would look back at most 500 bars (Length=500) and find the most recent occurrence (Occur=1) of a bar whose High (Price=High) is greater than the highs 3 bars before and 3 bars afterwards (Strength=3).

Also SwingLow(2, Close, 4, 200) would look back 200 bars and find the second most recent occurence of a bar whose Close is less than the closes 4 bars before and 4 bars afterwards.

The concept of User Functions has two big advantages. First, you can create a user function yourself (hence the name User Function). You don't have to beg the software developer to custom program it for you and put it into a future release of the program, then hope and pray that your request is granted and granted soon. Second, the code resides in exactly one place: the User Function Library. You don't have to copy-and-paste N lines of code into every system that uses your Function; you just call it as a subroutine. If you want to upgrade the function (killing a bug, adding a feature, speeding up the runtime, etc.) you don't have to go searching all over everywhere to find all the copies and change them all. There's just one place to look (the User Function Library), you change it there, and presto, the change automatically propagates to all systems that call that User Function.
I agree with Sluggo. Being able to make custom functions is very important to me. Seems like a natural progression for TB.

D