[PL] Divergence line chopping off a candle
[PL] Divergence line chopping off a candle
Dear All,
I am working on the markplex tutorial #26:
http://markplex.com/tutorial26.php
I use exactly the same code, and have adapted it to plot type 1 & 2 divergence lines:
http://www.elitetrader.com/tr/index.cfm ... tion=print
On the attached screenshot, you might see that the divergence line chops off the top of the candle before the pivot.
I am wondering how to tell PL that the top of the candle is chopped off by the divergence line, so that nothing is plotted if a candle is chopped off.
Do you have any idea?
Many thanks
I am working on the markplex tutorial #26:
http://markplex.com/tutorial26.php
I use exactly the same code, and have adapted it to plot type 1 & 2 divergence lines:
http://www.elitetrader.com/tr/index.cfm ... tion=print
On the attached screenshot, you might see that the divergence line chops off the top of the candle before the pivot.
I am wondering how to tell PL that the top of the candle is chopped off by the divergence line, so that nothing is plotted if a candle is chopped off.
Do you have any idea?
Many thanks
- Attachments
-
- cutoff.PNG
- (2.67 KiB) Downloaded 6679 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Dear TJ,
I am already using the "_s" extensions.
The divergence line plots right, I am just trying to find how it could not plot if it has to go through the body of a candle before its end point.
Many thanks,
sorry... can't tell if you don't post your code.
try this:
right click on chart,
go to Format Studies,
in the Scaling tab,
under Scaling Range,
select Same as Instrument.
The lines also chop off the indicator sometimes... is there no way to tell powerlanguage how to detect that there is something on the way of the tl_new?
- Attachments
-
- cutoff.PNG
- (2.67 KiB) Downloaded 6640 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Dear TJ,
My apologies if I wwas not clear enough, I did not mean to upset you.
Here is the code:
Please find attached a 6B data sample, that needs to be plotted using a 5 point resolution, and a screenshot showing a line chopping a candle wick.
It happened the 02/18/2010 at 18:05:21.
Let me know if you need anything,
Many thanks,
My apologies if I wwas not clear enough, I did not mean to upset you.
Here is the code:
Code: Select all
// http://markplex.com/tutorial26.php
Inputs : PriceL(Low),StochLength(7),SmoothingLength1(3),SmoothingLength2(3),SmoothingType(1),
Length(20),LeftStrength(3),RightStrength(1),BarTol(3);
vars: ofastk(0),oFastD(0),oSlowk(0),oSlowD(0),oPivotPrice1(0),oPivotBar1(0),oPivotPrice2(0),oPivotBar2(0),
oPivotPrice3(0),oPivotBar3(0),oPivotPrice4(0),oPivotBar4(0);
Value1=Stochastic(H,L,C,StochLength,SmoothingLength1,SmoothingLength2,SmoothingType,ofastk,ofastd,oslowk,oslowd);
//Determine if pivots in the price have occurred
Condition3 = Pivot(PriceL,Length,LeftStrength,RightStrength,1,-1,oPivotPrice3,oPivotBar3)<>-1;
Condition4 = Pivot(PriceL,Length,LeftStrength,RightStrength,2,-1,oPivotPrice4,oPivotBar4)<>-1;
//Determine if pivots in the stochstic have occurred
Condition1 = Pivot(oslowd,Length,LeftStrength,RightStrength,1,-1,oPivotPrice1,oPivotBar1)<>-1;
Condition2 = Pivot(oslowd,Length,LeftStrength,RightStrength,2,-1,oPivotPrice2,oPivotBar2)<>-1;
if condition3 and condition4 and condition1 and condition2
and (absvalue(oPivotbar1-oPivotBar3)<BarTol)
and (absvalue(oPivotbar2-oPivotBar4)<BarTol)
and (oPivotBar3 = RightStrength or oPivotbar1 = RightStrength)
and (oPivotPrice3<=oPivotPrice4 and oPivotPrice1>oPivotPrice2) and barstatus(1)=2 then
begin
value2= tl_new_S(D[oPivotBar4],Time_S[oPivotBar4],L[oPivotBar4],D[oPivotBar3],Time_s[oPivotBar3],L[oPivotBar3]);
tl_setcolor(value2,Green);
tl_setsize (value2,1);
value3= tl_new_Self_s(D[oPivotBar1],Time_S[oPivotBar1],oPivotPrice1,D[oPivotBar2],Time_s[oPivotBar2],oPivotPrice2);
tl_setcolor(value3,Green);
tl_setsize (value3,1);
end;
Plot1(oSlowD);
It happened the 02/18/2010 at 18:05:21.
Let me know if you need anything,
Many thanks,
- Attachments
-
- screenshot.png
- line chopping candle
- (126.4 KiB) Downloaded 6640 times
Last edited by duration on 15 Apr 2010, edited 1 time in total.
Data sample 03, the last one, to rename to 6B 06-10.zip.003
- Attachments
-
- 6B 06-10.zip
- (793.35 KiB) Downloaded 590 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
By chopping I mean that the trendline goes through the body/wick of a candle.
You can see it circled in red on this new screenshot.
You can see it circled in red on this new screenshot.
- Attachments
-
- screenshot2.png
- (126.37 KiB) Downloaded 6627 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
I gather, although the chopped candle made a low,By chopping I mean that the trendline goes through the body/wick of a candle.
You can see it circled in red on this new screenshot.
that low was not a "significant" low,
and that a latter low is where the divergent point lies.
Thus the line has to go through the chopped candle to arrive at the significant low.
I do not see it as a "problem".
but if you want modification, how would you propose the line be drawn?
can you use that same chart and make a hand drawn line to illustrate your view?
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
EasyLanguage is a flexible and power tool;Actually, I would like the line not to be drawn if it has to go through a candle like on the screenshot. This is why I am asking if it is possible to make powerlanguage detect that the line is going through a candle.
you can pretty well ask it to do any analysis you want.
All it take is a little bit of time and effort...
In this case, you will need to use trigonometry to evaluate the intersect of the line/bar.
It can be done; it is high school math, not rocket science... but it does take time.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
This is not a one or two keyword operation.Would you have a basic example, or a tutorial? I am looking through the Math & Trig help section, but still I find it difficult to project how to do it...
It will take time to code the logic and the process...
as to the basics,
a high school math textbook would be a good starting point.
Last edited by TJ on 15 Apr 2010, edited 1 time in total.
- Bruce DeVault
- Posts: 438
- Joined: 19 Jan 2010
- Location: Washington DC
- Been thanked: 2 times
- Contact:
Determining if a trend line intersects price is a simple matter of looking at the two end points, calculating the slope, and using the equation "y = m x + b" to figure out the trend line's price at each bar along the way, so you can compare with those bars' low/high range. There are very likely code snippets or functions already out there that do this - even if not, it should be very short to write.
That is correct. In fact, I've been using this method to draw tangents to prices to form trend lines. See, it does pay to listen at maths classesDetermining if a trend line intersects price is a simple matter of looking at the two end points, calculating the slope, and using the equation "y = m x + b" to figure out the trend line's price at each bar along the way, so you can compare with those bars' low/high range. There are very likely code snippets or functions already out there that do this - even if not, it should be very short to write.
For the case in question:
1. Compute the equation of a straight line going from point a to point b.
2. For each bar between points a and b, compute the y value from the equation.
3. If you are using the lows of the points a and b to draw the line, and any of the bars has a low value < the corresponding computed y value from 2, then the line cuts through the bar so don't draw it.
4. If using the highs of the points a and b to draw the line, and any of the bars has a high value > the corresponding computed y value from 2, then the line cuts through the bar so don't draw it.
Hello again !
Would you mind checking if the below is conceptually correct? I am trying to tell powerlanguage the values of each trendline point from barnumber 40 to 50, and I am not sure if a loop statement can achieve this.
Many thanks,
Would you mind checking if the below is conceptually correct? I am trying to tell powerlanguage the values of each trendline point from barnumber 40 to 50, and I am not sure if a loop statement can achieve this.
Code: Select all
variables:
PointA_y( 0 ),
PointA_x( 0 ),
PointB_y( 0 ),
PointB_x( 0 ),
Slope_m( 0 ),
TrendLine_AB( 0 ),
plotcondition( false ),
noplotcondition( false );
PointA_y = oPivotPrice2 ; //1.5210
PointA_x = oPivotBar2 ; //40
PointB_y = oPivotPrice1 ; //1.5230
PointB_x = oPivotBar1 ; // 50
Slope_m = ( PointB_y - PointA_y ) / ( PointB_x - PointA_x) ; //0.0002
For CurrentBar = PointA_x to CurrentBar = PointB_x
Begin
TrendLine_AB = slope_m * PointA_y ;
If Low < TrendLine_AB then noplotcondition = true;
If Low >= Trendline_AB then plotcondition = true;
End;
Or maybe I have to use an array to store the value of the trendline on each bar between the two points?
I have also tried SP's solution (see the end):
But I have no success so far
I have also tried SP's solution (see the end):
Code: Select all
// http://markplex.com/tutorial26.php
Inputs : PriceL(Low),StochLength(7),SmoothingLength1(3),SmoothingLength2(3),SmoothingType(1),
Length(20),LeftStrength(3),RightStrength(1),BarTol(3);
vars: ofastk(0),oFastD(0),oSlowk(0),oSlowD(0),oPivotPrice1(0),oPivotBar1(0),oPivotPrice2(0),oPivotBar2(0),
oPivotPrice3(0),oPivotBar3(0),oPivotPrice4(0),oPivotBar4(0);
Value1=Stochastic(H,L,C,StochLength,SmoothingLength1,SmoothingLength2,SmoothingType,ofastk,ofastd,oslowk,oslowd);
//Determine if pivots in the price have occurred
Condition3 = Pivot(PriceL,Length,LeftStrength,RightStrength,1,-1,oPivotPrice3,oPivotBar3)<>-1;
Condition4 = Pivot(PriceL,Length,LeftStrength,RightStrength,2,-1,oPivotPrice4,oPivotBar4)<>-1;
//Determine if pivots in the stochstic have occurred
Condition1 = Pivot(oslowd,Length,LeftStrength,RightStrength,1,-1,oPivotPrice1,oPivotBar1)<>-1;
Condition2 = Pivot(oslowd,Length,LeftStrength,RightStrength,2,-1,oPivotPrice2,oPivotBar2)<>-1;
if condition3 and condition4 and condition1 and condition2
and (absvalue(oPivotbar1-oPivotBar3)<BarTol)
and (absvalue(oPivotbar2-oPivotBar4)<BarTol)
and (oPivotBar3 = RightStrength or oPivotbar1 = RightStrength)
and (oPivotPrice3<=oPivotPrice4 and oPivotPrice1>oPivotPrice2) and barstatus(1)=2 then
begin
value2= tl_new_S(D[oPivotBar4],Time_S[oPivotBar4],L[oPivotBar4],D[oPivotBar3],Time_s[oPivotBar3],L[oPivotBar3]);
tl_setcolor(value2,Green);
tl_setsize (value2,1);
value3= tl_new_Self_s(D[oPivotBar1],Time_S[oPivotBar1],oPivotPrice1,D[oPivotBar2],Time_s[oPivotBar2],oPivotPrice2);
tl_setcolor(value3,Green);
tl_setsize (value3,1);
end;
Plot1(oSlowD);
for value10 = oPivotBar1 to value10 = oPivotbar2
begin
if tl_getvalue_s(value3,d[value10],time_s[value10]) < Low[value10] then tl_delete(value3);
end;
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
may I suggest you to draw a flow chart of your logic...Or maybe I have to use an array to store the value of the trendline on each bar between the two points?
I have also tried SP's solution (see the end):
...
But I have no success so far
it will help you to see how the computer process your insructions.
.
Hi TJ,
Sure.
1. IF DIVERGENCE THEN PLOT TRENDLINE (value3)
2. THEN LOOK AT BARS FROM OPIVOTBAR1 to OPIVOTBAR2 (from where the computer will plot the divergence.
3. IF A LOW IS LOWER THAN THE TRENDLIVE VALUE AT A GIVEN BAR BETWEN OPIVOTBAR1 AND OPIVOTBAR2 THEN DELETE THE TRENDLINE (value3).
I would prefer the computer to look at both the divergence and the lower low, before plotting a trendline, but I don't know how to get the value of the trendline if it has not plotted, so I tell it to plot and THEN to look for the lower low..
Sure.
1. IF DIVERGENCE THEN PLOT TRENDLINE (value3)
2. THEN LOOK AT BARS FROM OPIVOTBAR1 to OPIVOTBAR2 (from where the computer will plot the divergence.
3. IF A LOW IS LOWER THAN THE TRENDLIVE VALUE AT A GIVEN BAR BETWEN OPIVOTBAR1 AND OPIVOTBAR2 THEN DELETE THE TRENDLINE (value3).
I would prefer the computer to look at both the divergence and the lower low, before plotting a trendline, but I don't know how to get the value of the trendline if it has not plotted, so I tell it to plot and THEN to look for the lower low..
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
you can get the value before the TL is drawn...Hi TJ,
Sure.
1. IF DIVERGENCE THEN PLOT TRENDLINE (value3)
2. THEN LOOK AT BARS FROM OPIVOTBAR1 to OPIVOTBAR2 (from where the computer will plot the divergence.
3. IF A LOW IS LOWER THAN THE TRENDLIVE VALUE AT A GIVEN BAR BETWEN OPIVOTBAR1 AND OPIVOTBAR2 THEN DELETE THE TRENDLINE (value3).
I would prefer the computer to look at both the divergence and the lower low, before plotting a trendline, but I don't know how to get the value of the trendline if it has not plotted, so I tell it to plot and THEN to look for the lower low..
look for the TL_NEW keyword in the code.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Hi TJ,
Thank you for your replies.
I have read and re-read the section on TL_NEW() in the Multicharts 20 times, but I cannot figure out how to get the value of the trendline if it is not drawn I understand that the trendline only gets an ID # when it is drawn. How can I use TL_GETVALUE() if I do not know the ID of the trendline?
For 2.:
2.1 get the bar number between oPivotBar1 & oPivotBar2, which the For loop should get (for value10 = oPivotBar1 to value10 = oPivotbar2), so that the computer only looks at the bar between oPivot1 & oPivot2.
2.2 using the brackets "[]" the computer is going to assign a time value to each bar (value10) between oPivotBar1 oPivotBar2
2.2 for each of the bar in the loop, test the following: if the low of the bar is lower than the trendline value of the same bar, then delete the trendline.
2.3 if no low is lower than the trendline value, then nothing is deleted.
Thank you for your replies.
I have read and re-read the section on TL_NEW() in the Multicharts 20 times, but I cannot figure out how to get the value of the trendline if it is not drawn I understand that the trendline only gets an ID # when it is drawn. How can I use TL_GETVALUE() if I do not know the ID of the trendline?
For 2.:
2.1 get the bar number between oPivotBar1 & oPivotBar2, which the For loop should get (for value10 = oPivotBar1 to value10 = oPivotbar2), so that the computer only looks at the bar between oPivot1 & oPivot2.
2.2 using the brackets "[]" the computer is going to assign a time value to each bar (value10) between oPivotBar1 oPivotBar2
2.2 for each of the bar in the loop, test the following: if the low of the bar is lower than the trendline value of the same bar, then delete the trendline.
2.3 if no low is lower than the trendline value, then nothing is deleted.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Hi TJ,
Thank you for your replies.
I have read and re-read the section on TL_NEW() in the Multicharts 20 times, but I cannot figure out how to get the value of the trendline if it is not drawn I understand that the trendline only gets an ID # when it is drawn. How can I use TL_GETVALUE() if I do not know the ID of the trendline?
....
this is from your code above:
tl_new_S(D[oPivotBar4],Time_S[oPivotBar4],L[oPivotBar4],D[oPivotBar3],Time_s[oPivotBar3],L[oPivotBar3]);
I have highlighted the coordinates of the trendline.
these values are calculated before the trendline is drawn !
ie. before the TL_NEW statement is excuted.
but of course... you only get the beginning points and the end points.
that's why you need the step 2... to find out the value of the interim bars.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
if you know the beginning point value is 10
and end point value is 7,
can you figure out how to get the intermediate values?
ps. no trigonometry is needed.
and end point value is 7,
can you figure out how to get the intermediate values?
ps. no trigonometry is needed.
- Attachments
-
- TL.jpg
- TL
- (7.06 KiB) Downloaded 6660 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
yes... you have got the idea.I calculate the slope, which is:
( 7 - 10 ) / ( 0 - 3 ) = -1
it means that for every increase in x, the value will go down by -1
10 at 3, 9 at 2, 8 at 1, 7 at 0.
Is this correct?
use pseudo programming language...
(end point value - beginning point value) divided by the number of bars
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
from start point to end point
add: [(end point value - beginning point value)/abs(endpointbar-startpointbar)] to each bar after the start point and stop at the one before the end point
and check in the same time if this value is higher than the low of the same bar
and if it the value is higher than the low of the same bar then have a noplot condition become "true" so that the trendline is not plotted.
I think this is my issue, I am struggling how to coordinate all of this with a For loop
add: [(end point value - beginning point value)/abs(endpointbar-startpointbar)] to each bar after the start point and stop at the one before the end point
and check in the same time if this value is higher than the low of the same bar
and if it the value is higher than the low of the same bar then have a noplot condition become "true" so that the trendline is not plotted.
I think this is my issue, I am struggling how to coordinate all of this with a For loop
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
not so quick...
we are not programming yet,
we have to hash out the logic first.
1. are you evaluating this at EOB (end of bar) or intrabar?
2. what do you want to do with the line in diagram 3 ?
-- erase it?
-- move it back to the prev bar?
3. what if things changed by EOB?
e.g. the TL ended up below prev bar's low at the bar's close?
what do you want to do?
-- redraw the line?
-- forget it?
we are not programming yet,
we have to hash out the logic first.
1. are you evaluating this at EOB (end of bar) or intrabar?
2. what do you want to do with the line in diagram 3 ?
-- erase it?
-- move it back to the prev bar?
3. what if things changed by EOB?
e.g. the TL ended up below prev bar's low at the bar's close?
what do you want to do?
-- redraw the line?
-- forget it?
- Attachments
-
- TL-3a.png
- (21.4 KiB) Downloaded 6638 times
Hi TJ,
All calculations are at end of bar, nothing update at every tick: no line is redrawn.
It is a simple: if there is two pivot from where the computer can draw a line, BUT between those two pivots there is a low that is lower than the potential trendline, then don't draw the trendline.
Many thanks,
All calculations are at end of bar, nothing update at every tick: no line is redrawn.
It is a simple: if there is two pivot from where the computer can draw a line, BUT between those two pivots there is a low that is lower than the potential trendline, then don't draw the trendline.
Many thanks,
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
you don't really need a loop...Hi TJ,
All calculations are at end of bar, nothing update at every tick: no line is redrawn.
It is a simple: if there is two pivot from where the computer can draw a line, BUT between those two pivots there is a low that is lower than the potential trendline, then don't draw the trendline.
Many thanks,
you only need to find out the TL's value at prev bar.
can you work out the formula?
- Attachments
-
- TL-3b.jpg
- (8.37 KiB) Downloaded 6643 times
Sure, using TL_GETVALUE_S(), it "could" be:
Is it what you are asking me to do?
For the calculations with the slope etc. I cannot figure out how to synchronise everything in the right time: the getvalue and the higher thna low condition
But there is many bars between the two pivots points It could be the one before [1], or the second one before [2] etc.
Code: Select all
tl_new_s( tlid, d[oPivotBar1], time_s[oPivotBar1], oPivotPrice1, d[oPivotBar2], time_s[oPivotBar2], loPivotPrice2 );
if tl_getvalue_s( tlid, d[tldi], time_s[tlid])[1] > low[1] then tl_delete[tlid);
For the calculations with the slope etc. I cannot figure out how to synchronise everything in the right time: the getvalue and the higher thna low condition
But there is many bars between the two pivots points It could be the one before [1], or the second one before [2] etc.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
you only have to worry about the prev bar.Sure, using TL_GETVALUE_S(), it "could" be:
...
Is it what you are asking me to do?
For the calculations with the slope etc. I cannot figure out how to synchronise everything in the right time: the getvalue and the higher thna low condition
But there is many bars between the two pivots points It could be the one before [1], or the second one before [2] etc.
go draw some lines to test out my theory.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
I thought we have already worked out the general formula...Sure, using TL_GETVALUE_S(), it "could" be:
Is it what you are asking me to do?Code: Select all
tl_new_s( tlid, d[oPivotBar1], time_s[oPivotBar1], oPivotPrice1, d[oPivotBar2], time_s[oPivotBar2], loPivotPrice2 );
if tl_getvalue_s( tlid, d[tldi], time_s[tlid])[1] > low[1] then tl_delete[tlid);
For the calculations with the slope etc. I cannot figure out how to synchronise everything in the right time: the getvalue and the higher thna low condition
....
you only need to make one tweak.
Well, I returned to the charts, and I see sometimes highs (if looking for high divergences) or lows that are higher than the trenldline, 1-2 bars after the start of the trendline.
Also, if I start plotting longer trendlines, for example from pivot with a longer "instance" (instead of 2, then 3, 4, etc.) then the trendlines often go through some high/lows in the middle of the trendline (not just or bar back or just after the start of the trendline).
Would you like some screenshots?
Also, if I start plotting longer trendlines, for example from pivot with a longer "instance" (instead of 2, then 3, 4, etc.) then the trendlines often go through some high/lows in the middle of the trendline (not just or bar back or just after the start of the trendline).
Would you like some screenshots?
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Those screenshots are made with highs, but it is the same (inverse) story for the lows.
You might see that the trendline might go through a higher high (or a lower low if talking about lows) at anytime between the two pivot points.
You might see that the trendline might go through a higher high (or a lower low if talking about lows) at anytime between the two pivot points.
- Attachments
-
- 2highpivotpoint.png
- (49.93 KiB) Downloaded 6618 times
-
- 6-7highpivotpoint.png
- (14.52 KiB) Downloaded 6626 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
I would go through the EasyLanguage manual first...
there are examples inside.
try out different loops as exercises...
then give this a try.
don't just into coding yet.
write out your logic in pseudo language first,
because the computer is going to execute your instructions line-by-line,
just like a robot.
there are examples inside.
try out different loops as exercises...
then give this a try.
don't just into coding yet.
write out your logic in pseudo language first,
because the computer is going to execute your instructions line-by-line,
just like a robot.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
if you can write out your logic in plain English,
I can give you a hand.
try this format:
1. write out one thought at a time,
2. write out one action per thought,
3. write out one action per line (start a new line when you have a new action)
this will help you to organize your thoughts into code-able logics.
I can give you a hand.
try this format:
1. write out one thought at a time,
2. write out one action per thought,
3. write out one action per line (start a new line when you have a new action)
this will help you to organize your thoughts into code-able logics.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
ps. don't jump into the "loop" yet.
inside the loop is your evaluation logic... this is the meat of your indicator.
the loop is just a mechanism to repeat the evaluation multiple times.
ie. work out the evaluation process first.
start with the 1st bar after the beginning point.
(or, you can work from the 1st bar before the ending point, it is the same thing)
inside the loop is your evaluation logic... this is the meat of your indicator.
the loop is just a mechanism to repeat the evaluation multiple times.
ie. work out the evaluation process first.
start with the 1st bar after the beginning point.
(or, you can work from the 1st bar before the ending point, it is the same thing)
Thank you so much!! I start with the markplex tutorial logic.
1. if there is two low pivot on price.
2. if the oldest pivot is higher than the youngest one.
3. then pricepivot condition is true.
4. if there is two pivot on the stochastic slow.
5. if the oldest pivot is lower than the youngest one.
6. then stochpivot condition is true.
7. if the oldest pivot on the price and the oldest pivot on the stochastic slow are within three bars of each others.
8. 7. if the youngest pivot on the price and the youngest pivot on the stochastic slow are within three bars of each others.
9. then pivotlocation condition is true.
10. if pricepivot and stochpivot and pivotlocation condition are true then begin
11. calculate how many bars there is from the youngest price pivot point to the oldest price pivot point
12. substract the value of the youngest pivot point by the oldest pivot point, and divide this result by the number of bar to get the slope value.
13. starting from the bar just after the oldest price pivot point, add incrementally the slope value to the oldest price pivot point value to each bar until the bar just before the youngest price pivot point.
14. within this loop compare the value computed at each bar with the value of the each bar low.
15. if a low is lower than this value, then stop the calculation.
16. if no low is lower than the value, then plot the trendline.
Is it clear enough?
1. if there is two low pivot on price.
2. if the oldest pivot is higher than the youngest one.
3. then pricepivot condition is true.
4. if there is two pivot on the stochastic slow.
5. if the oldest pivot is lower than the youngest one.
6. then stochpivot condition is true.
7. if the oldest pivot on the price and the oldest pivot on the stochastic slow are within three bars of each others.
8. 7. if the youngest pivot on the price and the youngest pivot on the stochastic slow are within three bars of each others.
9. then pivotlocation condition is true.
10. if pricepivot and stochpivot and pivotlocation condition are true then begin
11. calculate how many bars there is from the youngest price pivot point to the oldest price pivot point
12. substract the value of the youngest pivot point by the oldest pivot point, and divide this result by the number of bar to get the slope value.
13. starting from the bar just after the oldest price pivot point, add incrementally the slope value to the oldest price pivot point value to each bar until the bar just before the youngest price pivot point.
14. within this loop compare the value computed at each bar with the value of the each bar low.
15. if a low is lower than this value, then stop the calculation.
16. if no low is lower than the value, then plot the trendline.
Is it clear enough?
Sorry, I was writing while you posted the above.
1. if there is two low pivot on price.
2. if the oldest pivot is higher than the youngest one.
3. then pricepivot condition is true.
4. if there is two pivot on the stochastic slow.
5. if the oldest pivot is lower than the youngest one.
6. then stochpivot condition is true.
7. if the oldest pivot on the price and the oldest pivot on the stochastic slow are within three bars of each others.
8. 7. if the youngest pivot on the price and the youngest pivot on the stochastic slow are within three bars of each others.
9. then pivotlocation condition is true.
10. if pricepivot and stochpivot and pivotlocation condition are true then begin
11. calculate how many bars there is from the youngest price pivot point to the oldest price pivot point
12. substract the value of the youngest pivot point by the oldest pivot point, and divide this result by the number of bar to get the slope value.
13. for the bar right after the oldest pivot point, add the slope value to the oldest pivot point value, and call it value1, and check if this value is higher than the low on the same bar.
14. for the second bar after the oldest pivot point, add the slope value to value1, and check if this value is higher than the low on the same bar.
15. for the thirdbar after the oldest pivot point, add the slope value to value2, and check if this value is higher than the low on the same bar.
16. do this until the bar just before the youngest pivot point is reached.
17. if at some point the low of the bar is lower than the value1,2,3... then stop calculations, then if not, plot a trendline.
1. if there is two low pivot on price.
2. if the oldest pivot is higher than the youngest one.
3. then pricepivot condition is true.
4. if there is two pivot on the stochastic slow.
5. if the oldest pivot is lower than the youngest one.
6. then stochpivot condition is true.
7. if the oldest pivot on the price and the oldest pivot on the stochastic slow are within three bars of each others.
8. 7. if the youngest pivot on the price and the youngest pivot on the stochastic slow are within three bars of each others.
9. then pivotlocation condition is true.
10. if pricepivot and stochpivot and pivotlocation condition are true then begin
11. calculate how many bars there is from the youngest price pivot point to the oldest price pivot point
12. substract the value of the youngest pivot point by the oldest pivot point, and divide this result by the number of bar to get the slope value.
13. for the bar right after the oldest pivot point, add the slope value to the oldest pivot point value, and call it value1, and check if this value is higher than the low on the same bar.
14. for the second bar after the oldest pivot point, add the slope value to value1, and check if this value is higher than the low on the same bar.
15. for the thirdbar after the oldest pivot point, add the slope value to value2, and check if this value is higher than the low on the same bar.
16. do this until the bar just before the youngest pivot point is reached.
17. if at some point the low of the bar is lower than the value1,2,3... then stop calculations, then if not, plot a trendline.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Hi TJ,
This is what I have written:
But all trendlines plot either with dashes or dots irrelevant of the "low lower than tlvalue" condition
This is what I have written:
Code: Select all
// http://markplex.com/tutorial26.php
Inputs : PriceL(Low),StochLength(7),SmoothingLength1(3),SmoothingLength2(3),SmoothingType(1),
Length(20),LeftStrength(3),RightStrength(1),BarTol(3);
vars: ofastk(0),oFastD(0),oSlowk(0),oSlowD(0),oPivotPrice1(0),oPivotBar1(0),oPivotPrice2(0),oPivotBar2(0),
oPivotPrice3(0),oPivotBar3(0),oPivotPrice4(0),oPivotBar4(0),
tlslope(0), bback(0), tlvalue(0);
Value1=Stochastic(H,L,C,StochLength,SmoothingLength1,SmoothingLength2,SmoothingType,ofastk,ofastd,oslowk,oslowd);
//Determine if pivots in the price have occurred
Condition3 = Pivot(PriceL,Length,LeftStrength,RightStrength,1,-1,oPivotPrice3,oPivotBar3)<>-1;
Condition4 = Pivot(PriceL,Length,LeftStrength,RightStrength,2,-1,oPivotPrice4,oPivotBar4)<>-1;
//Determine if pivots in the stochstic have occurred
Condition1 = Pivot(oslowd,Length,LeftStrength,RightStrength,1,-1,oPivotPrice1,oPivotBar1)<>-1;
Condition2 = Pivot(oslowd,Length,LeftStrength,RightStrength,2,-1,oPivotPrice2,oPivotBar2)<>-1;
if condition3 and condition4 and condition1 and condition2
and (absvalue(oPivotbar1-oPivotBar3)<BarTol)
and (absvalue(oPivotbar2-oPivotBar4)<BarTol)
and (oPivotBar3 = RightStrength or oPivotbar1 = RightStrength)
and (oPivotPrice3<=oPivotPrice4 and oPivotPrice1>oPivotPrice2) and barstatus(1)=2 then
begin
value2= tl_new_S(D[oPivotBar4],Time_S[oPivotBar4],L[oPivotBar4],D[oPivotBar3],Time_s[oPivotBar3],L[oPivotBar3]);
tl_setcolor(value2,Green);
tl_setsize (value2,1);
value3= tl_new_Self_s(D[oPivotBar1],Time_S[oPivotBar1],oPivotPrice1,D[oPivotBar2],Time_s[oPivotBar2],oPivotPrice2);
tl_setcolor(value3,Green);
tl_setsize (value3,1);
tlslope = (oPivotPrice2 - oPivotPrice1) / AbsValue(oPivotbar1-oPivotBar2); //value of the slope
for bback = oPivotBar2 - 1 downto bback = oPivotBar1 + 1 //from bar just after oPivotBar2 downto bar just before oPivotBar1
begin
tlvalue = oPivotPrice2 + tlvalue[bback] * tlslope; //intercept (oPivotPrice2) + value of trendline * slope
if tlvalue > low[bback] then tl_setstyle(value2,2) else tl_setstyle(value2,3); //instead of deleting, just change style, so that it is easier to see what is plotted
end;
end;
Plot1(oSlowD);
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
you are rushing it... LOL
slow down!
focus on #13 onward only
work on a 1 bar evaluation... if it works then you can put it in a loop.
suggestion:
do not use generic variables like Condition1 or value1.
always create a meaningful name,
because you will need it when you re-visit your code in 3 months' time.
ps. except Value1=Stochastic etc., because it is only a dummy variable.
slow down!
focus on #13 onward only
work on a 1 bar evaluation... if it works then you can put it in a loop.
suggestion:
do not use generic variables like Condition1 or value1.
always create a meaningful name,
because you will need it when you re-visit your code in 3 months' time.
ps. except Value1=Stochastic etc., because it is only a dummy variable.
I am trying to check the value of the bar just before the oPivotBar3:
It does not work but am I on the right way?
Code: Select all
// http://markplex.com/tutorial26.php
inputs :
PriceL(Low),
StochLength(7),
SmoothingLength1(3),
SmoothingLength2(3),
SmoothingType(1),
Length(20),
LeftStrength(3),
RightStrength(1),
BarTol(3);
vars:
ofastk(0),
oFastD(0),
oSlowk(0),
oSlowD(0),
oPivotPrice1(0),
oPivotBar1(0),
oPivotPrice2(0),
oPivotBar2(0),
oPivotPrice3(0),
oPivotBar3(0),
oPivotPrice4(0),
oPivotBar4(0),
tlslope(0),
bback(0),
tlvalue(0),
pricepivotcondition1(false),
pricepivotcondition2(false),
stochpivotcondition1(false),
stochpivotcondition2(false),
stochvalue(0),
tlstoch(0),
tlprice(0);
stochvalue=Stochastic(H,L,C,StochLength,SmoothingLength1,SmoothingLength2,SmoothingType,ofastk,ofastd,oslowk,oslowd);
//Determine if pivots in the stochstic have occurred
stochpivotcondition1 = Pivot(oslowd,Length,LeftStrength,RightStrength,1,-1,oPivotPrice1,oPivotBar1)<>-1;
stochpivotcondition2 = Pivot(oslowd,Length,LeftStrength,RightStrength,2,-1,oPivotPrice2,oPivotBar2)<>-1;
//Determine if pivots in the price have occurred
pricepivotcondition1 = Pivot(PriceL,Length,LeftStrength,RightStrength,1,-1,oPivotPrice3,oPivotBar3)<>-1;
pricepivotcondition2 = Pivot(PriceL,Length,LeftStrength,RightStrength,2,-1,oPivotPrice4,oPivotBar4)<>-1;
if pricepivotcondition1 and pricepivotcondition2 and stochpivotcondition1 and stochpivotcondition2
and (absvalue(oPivotbar1-oPivotBar3)<BarTol)
and (absvalue(oPivotbar2-oPivotBar4)<BarTol)
and (oPivotBar3 = RightStrength or oPivotbar1 = RightStrength)
and (oPivotPrice3<=oPivotPrice4 and oPivotPrice1>oPivotPrice2) and barstatus(1)=2 then
begin
tlprice= tl_new_S(D[oPivotBar4],Time_S[oPivotBar4],L[oPivotBar4],D[oPivotBar3],Time_s[oPivotBar3],L[oPivotBar3]);
tl_setcolor(tlstoch,Red);
tl_setsize (tlstoch,1);
tlstoch= tl_new_Self_s(D[oPivotBar1],Time_S[oPivotBar1],oPivotPrice1,D[oPivotBar2],Time_s[oPivotBar2],oPivotPrice2);
tl_setcolor(tlprice,Green);
tl_setsize (tlprice,1);
tlslope = (oPivotPrice3 - oPivotPrice4) / AbsValue(oPivotbar3-oPivotBar4); //value of the slope
tlvalue = oPivotPrice4 * (AbsValue(oPivotBar3 - oPivotBar4)-1) * tlslope; //the -1 is for the bar just before the oPivotBar3
if tlvalue > low[oPivotBar3+1] then tl_setstyle(tlprice,2) else tl_setstyle(tlprice,3); //+1 for bar just before oPivotBar3
{for bback = oPivotBar4 - 1 downto bback = oPivotBar3 + 1 //from bar just after oPivotBar4 downto bar just before oPivotBar3
begin
tlvalue = oPivotPrice4 + tlvalue[bback] * tlslope; //intercept (oPivotPrice4) + value of trendline * slope
if tlvalue[bback] > low[bback] then tl_setstyle(tlprice,2) else tl_setstyle(tlprice,3); //instead of deleting, just change style, so that it is easier to see what is plotted
end;}
end;
Plot1(oSlowD);
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
I can't see where #13 starts...I am trying to check the value of the bar just before the oPivotBar3:
...
It does not work but am I on the right way?
I am not concerned with the complete code...
I am only interested in only a small section of the logic.
ie #13...
because without this logic, the rest is useless...
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
this is a loooooong winded sentence...13. for the bar right after the oldest pivot point, add the slope value to the oldest pivot point value, and call it value1, and check if this value is higher than the low on the same bar.
with multiple actions in the same line.
if you are going to get anywhere,
you have to break it down
into chewable sizes.
ps. see how I write?
short sentence,
one thought at a time
one thought per line...
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Well, as long as you put in your fair share... I can help you out.Oh I see (thanks for your patience!). Is the below ok?
tlslope = (oPivotPrice3 - oPivotPrice4) / AbsValue(oPivotbar3-oPivotBar4);
value1 = oPivotPrice4*tlslope;
if value1 >= low[oPivotBar4-1] then then tl_setstyle(tlprice,2) else tl_setstyle(tlprice,3);
otherwise I will have to refer you to Bruce DeVault. LOL
let's go back to this diagram:
the line is drawn with this statement:
tl_new_S( Date[oPivotBar4], Time_S[oPivotBar4], Low[oPivotBar4], Date[oPivotBar3], Time_s[oPivotBar3], Low[oPivotBar3]);
can you see the TL's coordinates?
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
you are on the right track... but you need to be a little bit more specific.
Yes :
oPivotBar4 = 3 and oPivotPrice4 = 10
oPivotBar3 = 0 and oPivotPrice4 = 7
beginning price = Low[oPivotBar4]
ending price = Low[oPivotBar3]
.
Last edited by TJ on 19 Apr 2010, edited 1 time in total.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
TJ,
I am getting crazy. I could not get anything done with breaking down the logic and doing it line by line, and I have been breaking my head for like 8 hours on this...
The first problem is: if I print the oPivotBarX values, I get values like 8-10 (oPivotBar4) and 1-2 (oPivotBar3), but the For loop only work with DownTo, no matter I write:
or
The second problem is that if I print value1, it seems that the loop only works for 3 bars, not matter oPivotBar4 is 10 and oPivotBar3 is 1.....
The third problem is that, I have tried every combination and I don't know how to go further, I am completely stuck
The Prints are still in the code above if you or anybody want to have a look..
At least I know the print function inside and out now!
I am getting crazy. I could not get anything done with breaking down the logic and doing it line by line, and I have been breaking my head for like 8 hours on this...
The first problem is: if I print the oPivotBarX values, I get values like 8-10 (oPivotBar4) and 1-2 (oPivotBar3), but the For loop only work with DownTo, no matter I write:
Code: Select all
for bback = oPivotBar3 + 1 to bback = oPivotBar4 - 1
Code: Select all
for bback = oPivotBar4 - 1 to bback = oPivotBar3 + 1
The third problem is that, I have tried every combination and I don't know how to go further, I am completely stuck
Code: Select all
// http://markplex.com/tutorial26.php
inputs :
PriceL(Low),
StochLength(7),
SmoothingLength1(3),
SmoothingLength2(3),
SmoothingType(1),
Length(20),
LeftStrength(3),
RightStrength(1),
BarTol(3);
vars:
ofastk(0),
oFastD(0),
oSlowk(0),
oSlowD(0),
oPivotPrice1(0),
oPivotBar1(0),
oPivotPrice2(0),
oPivotBar2(0),
oPivotPrice3(0),
oPivotBar3(0),
oPivotPrice4(0),
oPivotBar4(0),
tlslope(0),
bback(0),
tlvalue(0),
pricepivotcondition1(false),
pricepivotcondition2(false),
stochpivotcondition1(false),
stochpivotcondition2(false),
stochvalue(0),
tlstoch(0),
tlprice(0)
tlcounter(0),
tldistance(0);
stochvalue=Stochastic(H,L,C,StochLength,SmoothingLength1,SmoothingLength2,SmoothingType,ofastk,ofastd,oslowk,oslowd);
//Determine if pivots in the stochstic have occurred
stochpivotcondition1 = Pivot(oslowd,Length,LeftStrength,RightStrength,1,-1,oPivotPrice1,oPivotBar1)<>-1;
stochpivotcondition2 = Pivot(oslowd,Length,LeftStrength,RightStrength,2,-1,oPivotPrice2,oPivotBar2)<>-1;
//Determine if pivots in the price have occurred
pricepivotcondition1 = Pivot(PriceL,Length,LeftStrength,RightStrength,1,-1,oPivotPrice3,oPivotBar3)<>-1;
pricepivotcondition2 = Pivot(PriceL,Length,LeftStrength,RightStrength,2,-1,oPivotPrice4,oPivotBar4)<>-1;
if pricepivotcondition1 and pricepivotcondition2 and stochpivotcondition1 and stochpivotcondition2
and (absvalue(oPivotbar1-oPivotBar3)<BarTol)
and (absvalue(oPivotbar2-oPivotBar4)<BarTol)
and (oPivotBar3 = RightStrength or oPivotbar1 = RightStrength)
and (oPivotPrice3<=oPivotPrice4 and oPivotPrice1>oPivotPrice2) and barstatus(1)=2 then
begin
tlprice= tl_new_S(D[oPivotBar4],Time_S[oPivotBar4],L[oPivotBar4],D[oPivotBar3],Time_s[oPivotBar3],L[oPivotBar3]);
tl_setcolor(tlstoch,Red);
tl_setsize (tlstoch,1);
tlstoch= tl_new_Self_s(D[oPivotBar1],Time_S[oPivotBar1],oPivotPrice1,D[oPivotBar2],Time_s[oPivotBar2],oPivotPrice2);
tl_setcolor(tlprice,Green);
tl_setsize (tlprice,1);
tldistance = absvalue(oPivotBar3-oPivotBar4);
//print(opivotbar2,";",opivotbar4,";",opivotbar1,";",opivotbar3,";",tldistance);
tlslope = (oPivotPrice3 - oPivotPrice4) / AbsValue(oPivotbar3-oPivotBar4); //value of the slope
for bback = oPivotBar4 - 1 downto bback = oPivotBar3 + 1
begin
tlcounter = oPivotPrice3 - (tlslope*bback);
//print(date:7:0,";",time:4:0,";",bback,";",tlslope:0:6,";",value1:0:6);
if tlcounter[bback] > low[bback] then tl_setstyle(tlprice,3) else tl_setstyle(tlprice,2);
end;
end;
Plot1(oSlowD);
At least I know the print function inside and out now!
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
can you re-do the coordinates in this section?Hello again !
Would you mind checking if the below is conceptually correct? I am trying to tell powerlanguage the values of each trendline point from barnumber 40 to 50, and I am not sure if a loop statement can achieve this.
Many thanks,Code: Select all
variables:
PointA_y( 0 ),
PointA_x( 0 ),
PointB_y( 0 ),
PointB_x( 0 ),
Slope_m( 0 ),
TrendLine_AB( 0 ),
plotcondition( false ),
noplotcondition( false );
PointA_y = oPivotPrice2 ; //1.5210
PointA_x = oPivotBar2 ; //40
PointB_y = oPivotPrice1 ; //1.5230
PointB_x = oPivotBar1 ; // 50
Slope_m = ( PointB_y - PointA_y ) / ( PointB_x - PointA_x) ; //0.0002
For CurrentBar = PointA_x to CurrentBar = PointB_x
Begin
TrendLine_AB = slope_m * PointA_y ;
If Low < TrendLine_AB then noplotcondition = true;
If Low >= Trendline_AB then plotcondition = true;
End;
I am only interested in the coordinates only at this moment...
we have to take the steps one step at a time.
rushing will only get us headaches.
Sure!
Here you are:
Here you are:
Code: Select all
Variables:
PointA_Y( 0 ),
PointA_X( 0 ),
PointB_Y( 0 ),
PointB_X( 0 ),
Slope_M( 0 ),
TrendLine_AB( 0 ),
PlotCondition( false ),
NoPlotCondition( false );
PointA_Y = Low[oPivotBar4] ;
PointA_x = oPivotBar4 ;
PointB_y = Low[oPivotPrice3] ;
PointB_x = oPivotBar3 ;
Slope_M = ( PointB_Y - PointA_Y ) / AbsValue( PointB_X - PointA_X ) ;
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
... you have to be more carefulSure!
Here you are:
Code: Select all
Variables:
PointA_Y( 0 ),
PointA_X( 0 ),
PointB_Y( 0 ),
PointB_X( 0 ),
Slope_M( 0 ),
TrendLine_AB( 0 ),
PlotCondition( false ),
NoPlotCondition( false );
PointA_Y = Low[oPivotBar4] ;
PointA_x = oPivotBar4 ;
PointB_y = Low[oPivotPrice3] ;
PointB_x = oPivotBar3 ;
Slope_M = ( PointB_Y - PointA_Y ) / AbsValue( PointB_X - PointA_X ) ;
... you have to check everything in detail,
because you are instructing the computer to perform an operation.
garbage instruction will net garbage results.
can you plug your Slope_M formula with these values and check the result?
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Sure:
( 7 - 10 ) / ABS( 0 - 3 )
-3 / 3 = -1
Slope_M = -1
It means that for a move from x = 3 to x = 2, y decrease of 1.
I read your graph from left to right, AY = 10, AX = 3, BY = 7, BX = 0.
hah... my mind slipped.
you must be wondering what the heck I am talking about.
I am the one who needs to be more careful. LOL
Yes, your numbers are correct.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
you need to study the loop a bit more...TJ,
I am getting crazy. I could not get anything done with breaking down the logic and doing it line by line, and I have been breaking my head for like 8 hours on this...
The first problem is: if I print the oPivotBarX values, I get values like 8-10 (oPivotBar4) and 1-2 (oPivotBar3), but the For loop only work with DownTo, no matter I write:
orCode: Select all
for bback = oPivotBar3 + 1 to bback = oPivotBar4 - 1
The second problem is that if I print value1, it seems that the loop only works for 3 bars, not matter oPivotBar4 is 10 and oPivotBar3 is 1.....Code: Select all
for bback = oPivotBar4 - 1 to bback = oPivotBar3 + 1
The third problem is that, I have tried every combination and I don't know how to go further, I am completely stuck
...
there are examples in the manual as well as in the dictionary.
can you post the complete loop?
LOL no worries
The loop is as follow:
The loop is as follow:
It is part of the 11:28 am post above.tlslope = (oPivotPrice3 - oPivotPrice4) / AbsValue(oPivotbar3-oPivotBar4); //value of the slope
for bback = oPivotBar4 - 1 downto bback = oPivotBar3 + 1
begin
tlcounter = oPivotPrice3 - (tlslope*bback);
//print(date:7:0,";",time:4:0,";",bback,";",tlslope:0:6,";",value1:0:6);
if tlcounter[bback] > low[bback] then tl_setstyle(tlprice,3) else tl_setstyle(tlprice,2);
end;
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
watistis ?
Code: Select all
tlslope = (oPivotPrice3 - oPivotPrice4) / AbsValue(oPivotbar3-oPivotBar4); //value of the slope
It must be something wrong.
Is this better?
Is this better?
Code: Select all
tlslope = (Low[oPivotBar3] - Low[oPivotBar4]) / AbsValue(oPivotbar3-oPivotBar4);
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Well, a loop has a control variable, which is bback in this case.
The loop should look at every bar between the bar before oPivotBar3 and the Bar after oPivotBar4.
The value of the control variable should then be the bar before oPivotBar3 and the Bar after oPivotBar4.
It should give:
Is this correct?
The loop should look at every bar between the bar before oPivotBar3 and the Bar after oPivotBar4.
The value of the control variable should then be the bar before oPivotBar3 and the Bar after oPivotBar4.
It should give:
Code: Select all
For bback = oPivotBar3 +1 to oPivotbar4 -1
begin
end;
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
yes, that's correct.
try this...
set the plot to a cross, and see where the plots appear.
this step is to test your evaluation process...
to see which bars are checked.
try this...
Code: Select all
For bback = oPivotBar3 +1 to oPivotbar4 -1
begin
plot99( h, "Loop test");
end;
this step is to test your evaluation process...
to see which bars are checked.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
That is a useful tip!
Better than Print!
If you look at the screenshot, it shows that the loop does not look in the bar it should look in.
Also according to the screenshot, the no bar is either dashed or dotted anymore.
Is there a problem with the control variable values?
Better than Print!
If you look at the screenshot, it shows that the loop does not look in the bar it should look in.
Also according to the screenshot, the no bar is either dashed or dotted anymore.
Is there a problem with the control variable values?
- Attachments
-
- looptest.png
- (124.5 KiB) Downloaded 6619 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Please find below the version with the loop, to make your life easier!
I have tryinng to tweak the inputs, to use tldistance etc. in the loop for 2 hours, but no luck If anyone else want also to have a look, you are all welcome!
Code: Select all
// http://markplex.com/tutorial26.php
inputs :
PriceL(Low),
StochLength(7),
SmoothingLength1(3),
SmoothingLength2(3),
SmoothingType(1),
Length(20),
LeftStrength(3),
RightStrength(1),
BarTol(3);
vars:
ofastk(0),
oFastD(0),
oSlowk(0),
oSlowD(0),
oPivotPrice1(0),
oPivotBar1(0),
oPivotPrice2(0),
oPivotBar2(0),
oPivotPrice3(0),
oPivotBar3(0),
oPivotPrice4(0),
oPivotBar4(0),
tlslope(0),
bback(0),
tlvalue(0),
pricepivotcondition1(false),
pricepivotcondition2(false),
stochpivotcondition1(false),
stochpivotcondition2(false),
stochvalue(0),
tlstoch(0),
tlprice(0),
tldistance(0);
stochvalue=Stochastic(H,L,C,StochLength,SmoothingLength1,SmoothingLength2,SmoothingType,ofastk,ofastd,oslowk,oslowd);
//Determine if pivots in the stochstic have occurred
stochpivotcondition1 = Pivot(oslowd,Length,LeftStrength,RightStrength,1,-1,oPivotPrice1,oPivotBar1)<>-1;
stochpivotcondition2 = Pivot(oslowd,Length,LeftStrength,RightStrength,2,-1,oPivotPrice2,oPivotBar2)<>-1;
//Determine if pivots in the price have occurred
pricepivotcondition1 = Pivot(PriceL,Length,LeftStrength,RightStrength,1,-1,oPivotPrice3,oPivotBar3)<>-1;
pricepivotcondition2 = Pivot(PriceL,Length,LeftStrength,RightStrength,2,-1,oPivotPrice4,oPivotBar4)<>-1;
if pricepivotcondition1 and pricepivotcondition2 and stochpivotcondition1 and stochpivotcondition2
and (absvalue(oPivotbar1-oPivotBar3)<BarTol)
and (absvalue(oPivotbar2-oPivotBar4)<BarTol)
and (oPivotBar3 = RightStrength or oPivotbar1 = RightStrength)
and (oPivotPrice3<=oPivotPrice4 and oPivotPrice1>oPivotPrice2) and barstatus(1)=2 then
begin
tldistance = absvalue(oPivotBar3-oPivotBar4);
tlprice=tl_new_S(D[oPivotBar4],Time_S[oPivotBar4],L[oPivotBar4],D[oPivotBar3],Time_s[oPivotBar3],L[oPivotBar3]);
tl_setcolor(tlprice,yellow);
tl_setsize(tlprice,1);
for bback = oPivotBar3+1 to oPivotBar4-1
begin
plot99(h,"Loop Test");
end;
tlstoch= tl_new_Self_s(D[oPivotBar1],Time_S[oPivotBar1],oPivotPrice1,D[oPivotBar2],Time_s[oPivotBar2],oPivotPrice2);
tl_setcolor(tlstoch,Green);
tl_setsize (tlstoch,1);
end;
Plot1(oSlowD);
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
I got the trendline values!
But now I am struggling to place in the loop:
All the trendlines use style 2 at the moment.
I think it is because the loop does not stop as soon as the tlvalue > low is true.
Is there any way to stop the loop as soon as the condition is true?
But now I am struggling to place in the loop:
Code: Select all
if tlvalue[bback] > low[bback] then tl_setstyle(tlprice, 3) else tl_setstyle(tlprice, 2);
I think it is because the loop does not stop as soon as the tlvalue > low is true.
Is there any way to stop the loop as soon as the condition is true?
- Attachments
-
- loop test beta 0.03 by TJ.txt
- with plotted trendlines values
- (2.57 KiB) Downloaded 538 times
Last edited by duration on 19 Apr 2010, edited 1 time in total.
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Actually, the proper calculation for the trendline seems to be:
Code: Select all
tlvalue = low[oPivotBar3] - (tlslope*(bback-RightStrength));