Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

New Code Request Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
danielbender
Posted : Wednesday, February 27, 2019 1:40:08 AM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce

Would you please code the following algorithm.

Thank you ... Dan

++++++++++++++

BarCount = number of 1 minute bars beginning at start of trading day
Set Plot(1)=0 for 1st 1 minute bar
If plot(currentbar-1) <> 0, Plot(barcount) = Plot(Barcount -1) (ie, freeze all future plot values at 1st non-zero value)
a) If 2nd one minute bar is engulfing candle of 1st one minute bar & any one of 15 subsequent bars breaks the top of the 2nd one minute bar, then set Plot = 1 + Barcount/100. 
b) If 2nd one minute bar is engulfing candle of 1st one minute bar & any one of 15 subsequent bars breaks the bottom of the 2nd one minute bar, then set plot= -1 - Barcount/100.
c) Otherwise Plot = 0. 
d) If barcount > 15, stop algorithm (do not analyze or waste CPU Power), set Plot=Plot(15)

+++++++++++

Bruce_L
Posted : Wednesday, February 27, 2019 3:33:11 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I am not quite sure I am properly following the logic of the described indicator, but maybe something similar to the following?

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:New Code
'|******************************************************************
Static BarCount As Single
Static Bar2High As Single
Static Bar2Low As Single
Static Output As Single
If isFirstBar Then
	BarCount = Single.NaN
	Bar2High = Single.NaN
	Bar2Low = Single.NaN
	Output = Single.NaN
Else If Price.DateValue.Day <> Price.DateValue(1).Day Then
	BarCount = 1
	Bar2High = Single.NaN
	Bar2Low = Single.NaN
	Output = 0
Else
	BarCount += 1
End If
If BarCount = 2 Then
	If Price.High > Price.High(1) AndAlso _
		Price.Low < Price.Low(1) Then
		Bar2High = Price.High
		Bar2Low = Price.Low
	End If
End If
If BarCount <= 15 Then
	If Price.High > Bar2High Then
		Output = 1 + BarCount / 100
		Bar2High = Single.NaN
		Bar2Low = Single.NaN
	Else If Price.Low < Bar2Low Then
		Output = 1 - BarCount / 100
		Bar2High = Single.NaN
		Bar2Low = Single.NaN
	End If
	If BarCount = 15 Then
		Output = 15
		Bar2High = Single.NaN
		Bar2Low = Single.NaN
	End If
End If
Plot = Output


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Wednesday, February 27, 2019 4:47:14 PM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce

Thanks for your rapid response.  I see I need to modify the algorithm.

a) 1st minute bar is a gap up or gap down from yesterday's close AND

b) 2nd 1 minute bar is engulfing candle of 1st one minute bar, ie, high(2) > high(1) AND low(2) < low(2) < low(1) AND

c) IF a AND b are true, analyze 3rd through 15th bar

           IF High(n) > High(2) AND 1st bar was gap up, THEN PLOT = 1+bar/100 else

           IF Low(n) < Low(2) and 1st bar was gap down, THEN PLOT = -1-bar/100

d) If a AND b AND c not true, PLOT=0.

e) After bar 15, Freeze PLOT at value of 1st bar when a AND b AND c are true, otherwise PLOT = 0.

Thanks again for your patience.  Dan

danielbender
Posted : Wednesday, February 27, 2019 4:49:25 PM
Registered User
Joined: 1/14/2006
Posts: 436

Sorry

line b should read

b) 2nd 1 minute bar is engulfing candle of 1st one minute bar, ie, high(2) > high(1) AND low(2) < low(1) AND

Bruce_L
Posted : Thursday, February 28, 2019 1:07:50 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Does the low need to be above the close for the gap up or the high below the close for the gap down or do you need to have the open not equal to the close?



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Thursday, February 28, 2019 3:24:10 PM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce

On the first bar, I just need to know if the gap is up or down compared to yesterdays close, there has to be a gap between yesterdays close and the low on gap up (or high on gap down) of the first bar. 

On the second bar, it has to be an engulfing candle.

On subsequent bars, the high (or low) is ONLY compared to the second bar high (or low). 

Thanks.. Dan

Bruce_L
Posted : Thursday, February 28, 2019 4:06:45 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Please try the following RealCode Condition.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:New Code
'|******************************************************************
Static BarCount As Single
Static Bar2High As Single
Static Bar2Low As Single
Static Output As Single
BarCount += 1
If isFirstBar Then
	BarCount = Single.NaN
	Bar2High = Single.NaN
	Bar2Low = Single.NaN
	Output = Single.NaN
Else If Price.DateValue.Day <> Price.DateValue(1).Day Then
	If (Price.Low > Price.Close(1) OrElse _
		Price.High < Price.Close(1)) Then
		BarCount = 1
	Else
		BarCount = Single.NaN
	End If
	Bar2High = Single.NaN
	Bar2Low = Single.NaN		
	Output = 0
Else If BarCount = 2 Then
		If Price.High > Price.High(1) AndAlso _
			Price.Low < Price.Low(1) Then
			Bar2High = Price.High
			Bar2Low = Price.Low
	End If
Else If BarCount <= 15 Then
		If Price.High > Bar2High Then
			Output = 1 + BarCount / 100
			Bar2High = Single.NaN
			Bar2Low = Single.NaN
		Else If Price.Low < Bar2Low Then
		Output = -1 - BarCount / 100
			Bar2High = Single.NaN
			Bar2Low = Single.NaN
		End If
		If BarCount = 15 Then
			Bar2High = Single.NaN
			Bar2Low = Single.NaN
		End If
End If
Plot = Output


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Friday, March 1, 2019 11:21:53 AM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce

The formula seems to work for gap-ups, but 1) it does not identify any actual gap-downs, and 2) misidentifies some gap-ups as gap-downs, e.g., NFLX today >> plot = -1.03.  

The idea is to find gap-ups with subsequent bars that break to the upside (long trades), and gap-downs, with subsequent bars that break to the downside (short trades).

Thanks...Dan

Bruce_L
Posted : Friday, March 1, 2019 3:14:52 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

The RealCode was just checking for a gap in either direction instead of requiring a gap up for high(n) > high(2) and a gap down for lov(n) < low(2).

Please provide more than just a single example next time if this RealCode isn't doing what you want.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:New Code
'|******************************************************************
Static BarCount As Single
Static Bar2High As Single
Static Bar2Low As Single
Static Output As Single
BarCount += 1
If isFirstBar Then
	BarCount = Single.NaN
	Bar2High = Single.NaN
	Bar2Low = Single.NaN
	Output = Single.NaN
Else If Price.DateValue.Day <> Price.DateValue(1).Day Then
	If (Price.Low > Price.Close(1) OrElse _
		Price.High < Price.Close(1)) Then
		BarCount = 1
	Else
		BarCount = Single.NaN
	End If
	Bar2High = Single.NaN
	Bar2Low = Single.NaN		
	Output = 0
Else If BarCount = 2 Then
	If Price.High > Price.High(1) AndAlso _
		Price.Low(1) > Price.Low Then
		If Price.Low(1) > Price.Close(2) Then
			Bar2High = Price.High
		Else If Price.High(1) < Price.Close(2) Then
			Bar2Low = Price.Low
		End If
	End If
Else If BarCount <= 15 Then
		If Price.High > Bar2High Then
			Output = 1 + BarCount / 100
			Bar2High = Single.NaN
			Bar2Low = Single.NaN
		Else If Price.Low < Bar2Low Then
		Output = -1 - BarCount / 100
			Bar2High = Single.NaN
			Bar2Low = Single.NaN
		End If
		If BarCount = 15 Then
			Bar2High = Single.NaN
			Bar2Low = Single.NaN
		End If
End If
Plot = Output


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Friday, March 1, 2019 5:58:44 PM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce

1. Something is still incorrect.  Out of 6300 optionable stocks today, only 3 show as gap-downs: CSBR, ASSG, and NLY.  However, none of them are gap-downs.

2.  Is it possible to speed up the algorithm so that only the first bar is analyzed for stocks with no gap-up or gap-down? Simply set Plot = 0 to for these, and it is not necessary to look at bars two through 15. Since a vast majority of stocks are not gap-ups or gap-downs, that should speed up the algorithm significantly. 

Thanks .. have a great weekend.

Dan

 

 

Bruce_L
Posted : Monday, March 4, 2019 2:36:17 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

According to the definition you provided, "On the first bar, I just need to know if the gap is up or down compared to yesterdays close, there has to be a gap between yesterdays close and the low on gap up (or high on gap down) of the first bar.", CSBR and NLY are gap downs (ASSG does not exist).

CSBR: C1: 11.74  H: 11.70
NLY: C1: 10.13, H: 10.10
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:New Code
'|******************************************************************
Static BarCount As Integer
Static Bar2High As Single
Static Bar2Low As Single
Static Output As Single
Static GapUp As Boolean
Static GapDown As Boolean
Static Engulfing As Boolean
BarCount += 1
If isFirstBar Then
	Output = Single.NaN
	GapDown = False
	GapUp = False
	Engulfing = False
Else If Price.DateValue.Day <> Price.DateValue(1).Day Then
	If Price.Low > Price.Close(1) Then
		GapUp = True
		BarCount = 1
	Else If Price.High < Price.Close(1) Then
		GapDown = True
		BarCount = 1
	End If
	Output = 0
Else If BarCount = 2 AndAlso _
	(GapUp = True OrElse _
	GapDown = True) Then
	If Price.High > Price.High(1) AndAlso _
		Price.Low(1) > Price.Low Then
		Engulfing = True
		If GapUp = True Then
			Bar2High = Price.High
		Else If GapDown = True Then
			Bar2Low = Price.Low
		End If
	Else
		GapUp = False
		GapDown = False
	End If
Else If Engulfing = True Then
	If GapUp = True AndAlso _
		Price.High > Bar2High Then
		Output = 1 + BarCount / 100
		Bar2High = Single.NaN
		GapUp = False
		Engulfing = False
	Else If GapDown = True AndAlso _
		Price.Low < Bar2Low Then
		Output = -1 - BarCount / 100
		Bar2Low = Single.NaN
		GapDown = False
		Engulfing = False
	Else If BarCount = 15 Then
		Bar2High = Single.NaN
		Bar2Low = Single.NaN
		GapUp = False
		GapDown = False
		Engulfing = False
	End If
End If
Plot = Output


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
danielbender
Posted : Wednesday, March 6, 2019 12:21:44 AM
Registered User
Joined: 1/14/2006
Posts: 436

Bruce - thank you - Dan

Bruce_L
Posted : Wednesday, March 6, 2019 10:45:34 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You're welcome.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.