[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Looking for an indicator to display higher-highs/lower lows



PureBytes Links

Trading Reference Links

Brian - thanks to you and everyone else for their detailed responses.
 I've found an EasyLanguage example of what I'm trying to duplicate. 
Any further help greatly appreciated.

/ This indicator labels HH, HL, LL, LH on the chart.
//

inputs:  
	LeftStrength( 3 ) ,  
	RightStrength( 3 ), 
	LookBackLength( 100 );
 
variable:  
	ID(-1), 
	Offset( 0 ) , 
	HighValue1(0),
	HighValue2(0),
	LowValue1(0),
	LowValue2(0);



 
Offset = .15 * Average( Range, 5 ) ; 
 
if PivotHighVSBar( 1, High, LeftStrength, RightStrength, RightStrength
+ 1 ) <> -1 then 
begin 
	HighValue1 = PivotHighVS(1, High, Leftstrength, RightStrength,
LookBackLength );  
	HighValue2 = PivotHighVS(2, High, Leftstrength, RightStrength,
LookBackLength );  
 
	if HighValue2 <> -1 and ( ( HighValue1 >= HighValue2 - Offset ) and (
HighValue1 <= HighValue2 + Offset ) ) then  
	begin 
		ID = Text_New(Date[RightStrength], Time[RightStrength],
High[RightStrength] + Offset, "DT");  
		Text_SetStyle(ID, 2, 1 ) ; 
		Text_SetColor(ID, darkyellow);

		Value1 = 1;
	end ;  

	if HighValue2 <> -1 and HighValue1 > HighValue2 and value1 = 0 then  
	begin 
		ID = Text_New(Date[RightStrength], Time[RightStrength],
High[RightStrength] + Offset, "HH");  
		Text_SetStyle(ID, 2, 1 ) ; 
		Text_SetColor(ID, darkgreen);
	end 
	else 
	if HighValue2 <> -1 and HighValue1 < HighValue2 and value1 = 0 then
	begin
		ID = Text_New(Date[RightStrength], Time[Rightstrength],
High[RightStrength] + Offset, "(LH)");
		Text_SetStyle(ID, 2, 1 ) ;
		Text_SetColor(ID, Red);
	end ;
	Value1 = 0;
end ; 
 
if PivotLowVSBar( 1, Low, LeftStrength, RightStrength, RightStrength +
1 ) <> -1 then 
begin 
	LowValue1 = PivotLowVS(1, Low, Leftstrength, RightStrength,
LookBackLength );  
	LowValue2 = PivotLowVS(2, Low, Leftstrength, RightStrength,
LookBackLength );  
 
	if LowValue2 <> -1 and ( ( LowValue1 >= LowValue2 - Offset ) and (
LowValue1 <= LowValue2 + Offset ) ) then  
	begin 
		ID = Text_New(Date[RightStrength], Time[RightStrength],
Low[RightStrength] - Offset, "DB");  
		Text_SetStyle(ID, 2, 0 ) ; 
		Text_SetColor(ID, darkyellow);

		Value1 = 1;
	end;  

	if LowValue2 <> -1 and LowValue1 < LowValue2 and Value1 = 0 then  
	begin  
		ID = Text_New(Date[RightStrength], Time[RightStrength],
Low[RightStrength] - Offset, "LL");  
		Text_SetStyle(ID, 2, 0 ) ; 
		Text_SetColor(ID, Red);
	end 
	else 
	
	if LowValue2 <> -1 and LowValue1 > LowValue2 and Value1 = 0 then
	begin
		ID = Text_New(Date[RightStrength], Time[RightStrength],
Low[RightStrength] - Offset, "(HL)");
		Text_SetStyle(ID, 2, 0 ) ;
		Text_SetColor(ID, darkgreen);
	end;
	Value1 = 0;
end ; 


--- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@xxx> wrote:
>
> Carrying on from Tim's recent discussion, which is also relevant to 
> your chart example.
> 
> 
> In your example they recommend drawing a line under the 'pivots'.
> Theoretically this plots a classic trend but in practice iti s not so 
> easy because the pivots don't play the game by lining up nicely along 
> the line. Typically the slope (monentum) of the 'pivot to pivot' line 
> changes througout the wave (note that I use my own system for wave 
> analysis ... sorry I won't publish my core methods that I still use .. 
> especially if they are original work).
> There are also other problems with plotting a trendline from low to low 
> or high to high e.g. once some retracement starts to occur then some 
> lows or highs have to be 'missed' to retain the integrity of the 
> sraight line but using ValueWhen(higher low OR lower high,N) can give 
> you something precise to work with, including ROC.
> 
> IMO the term 'Pivot' is interchangeable with Peak/Trough etc  .. 
> sometimes, in my code, I use both terms to mean the same thing.
> 
> As per my comments to Tim, I have some old code laying around ... not 
> complete and perhaps not the best but it gives you another avenue of 
> thought (while I am not using it at the moment I found it a worthwhile 
> subject of study and the fact I am not using it is not a negative 
> assessment of its value).
> 
> Note - all of my examples were written to use as visual tools only - 
> they contain a look forward component so they aren't suitable for 
> backtesting (they can be recoded for BT) ... a few incomplete examples 
> (AFAIK all that I have left) ..... it is basically my own stuff, 
> especially the idea of MajorPeaks which are the macro patterns (they 
> correspond to a higher timeframe).
> 
> 
> Written for AB 4.9 in my early AB days (pretty basic stuff).
> 
> Incomplete examples ... use variations to achieve other results 
> including similar to the TS example.
> 
> Haven't used them for a long time OR checked them recently so no 
> guarantees as to their accuracy.
> 
> I probably haven't even backtested many or any of them.... I am not 
> really an algorithmic trader ... I just use AB for reasearching and 
> thinking about strategies etc.
> 
> My idea of a peak/trough is based on three bars with the central bar 
> either higher or lower.
> 
> 
> I did write other versions and consider variations but I think that 
> code is gone.
> 
> One of the issues in writing code for a peak/trough is identifying when 
> two bars have equal highs ... what to do about that is personal 
> choice ... I did have some solutions ... it looks like some of the code 
> may include some of that stuff ... not sure if it is good or not.
> 
> The examples are biased to the long side because I tend to work the 
> code out in one direction first and only code the short side later.
> 
> ***********************************************************
> 
> /*PLOTDYNHI*/
> 
> /*DYNAMICALLY PLOTS HIGHEST VALUE FOR THE PERIOD*/
> 
> 
> //Suitable for overlaying price(C)charts
> //DoubleClick left mouse button on any bar in the chart to select the 
> period
> //DoubleClick left mouse button on space to the right of the chart to 
> deselect the period
> //If no period is selected the default is all bars
> 
> 
> 
> P = (LastValue(BarIndex()) - BeginValue(BarIndex())) + 1;//Periods
> PH = HHV(C,P);//PeriodHigh
> SD = IIf(DateNum() < BeginValue(DateNum()), Null, LastValue
> (PH));//SelectedDate
> 
> Plot(SD, "PeriodHi",34,8);
> 
> ******************************************************************
> /*P_DYNHIPEAK*/
> 
> /*DYNAMICALLY PLOTS HIGHEST 3 Bar PEAK VALUE FOR THE PERIOD*/
> 
> 
> /*Suitable for overlaying price(C)charts*/
> /*DoubleClick left mouse button on any bar in the chart to select the 
> period*/
> /*DoubleClick left mouse button on space to the right of the chart to 
> deselect the period*/
> /*If no bar is selected the defaults is all bars*/
> /*Caution: it will not see peaks with flat tops (two or more equal 
> closes)*/
> /*Caution:if there is no peak within the selected period the most 
> recent peak will be indicated*/ 
> 
> PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> PKV = IIf(PK == 1, ValueWhen(PK,C,1), ValueWhen(PK,C,0));//PeakValue
> P = (LastValue(BarIndex()) - BeginValue(BarIndex())) + 1;//Periods
> HPK = HHV(PKV,P);//HighestPeakValue
> SD = IIf(DateNum() < BeginValue(DateNum()), Null, LastValue
> (HPK));//SelectedDate
> 
> Plot(SD, "PeriodHiPeak",34,8);
> 
> 
> 
> 
> ********************************************************************
> //PLOTMAJORPEAKS
> 
> //PLOTS ALL MAJOR PEAK RESISTANCE LINES
> 
> //Suitable for overlaying charts
> //A MajorPeak is defined as the Highest Peak of any three Peaks
> 
> 
> PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> PKV0 = ValueWhen(PK,C,0);//PeakValue0
> PKV1 = ValueWhen(PK,C,1);//PeakValue1
> PKV2 = ValueWhen(PK,C,2);//PeakValue2
> MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
> MPKV =  ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, 
> PKV1,1);   //MajorPeakValue
> 
> 
> Plot(MPKV, "LastPeak",34,1);
> 
> **********************************************************************
> 
> /*P_DYNHIPEAK*/
> 
> /*DYNAMICALLY PLOTS HIGHEST 3 Bar PEAK VALUE FOR THE PERIOD*/
> 
> 
> /*Suitable for overlaying price(C)charts*/
> /*DoubleClick left mouse button on any bar in the chart to select the 
> period*/
> /*DoubleClick left mouse button on space to the right of the chart to 
> deselect the period*/
> /*If no bar is selected the defaults is all bars*/
> /*Caution: it will not see peaks with flat tops (two or more equal 
> closes)*/
> /*Caution:if there is no peak within the selected period the most 
> recent peak will be indicated*/ 
> 
> PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> PKV = IIf(PK == 1, ValueWhen(PK,C,1), ValueWhen(PK,C,0));//PeakValue
> P = (LastValue(BarIndex()) - BeginValue(BarIndex())) + 1;//Periods
> HPK = HHV(PKV,P);//HighestPeakValue
> SD = IIf(DateNum() < BeginValue(DateNum()), Null, LastValue
> (HPK));//SelectedDate
> 
> Plot(SD, "PeriodHiPeak",34,8);
> 
> **********************************************************
> 
> //P_3BarPeaks
> 
> //Suitable for overlaying charts
> //References future bars
> 
> //PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> //PKV = ValueWhen(PK,C,1);//PeakValue
> //Plot(PKV, "LastPeak",34,1);
> 
> /********************************************************************/
> 
> /* draw horizontal lines at hi & lo pivot points*/
> //JohnRUK TraderJUK
> //Shifts resistance line 1 bar
> //3 Bar peaks
> 
> //P = ParamField("Price field",-1);
> //Hipiv = IIf(P<Ref(P,-1) AND (Ref(P,-1)>Ref(P,-2)),1,0);
> //Lopiv = IIf(P>Ref(P,-1) AND (Ref(P,-1)<Ref(P,-2)),1,0);
> //hiline=ValueWhen(hipiv==1,Ref(P,-1),1);
> //loline=ValueWhen(lopiv==1,Ref(P,-1),1);
> //Plot (Hiline,"hiline",colorRed);
> //Plot (Loline,"loline",colorBlue);
> 
> /*********************************************************************/
> 
> /*P_Peaks*/
> 
> /*PLOTALLPEAKS*/
> 
> /*PLOTS ALL PEAK VALUES FOR THE PERIOD*/
> 
> 
> //Suitable for overlaying price(C)charts
> //References future bars
> //Recognises flat peaks of any length
> 
> 
> PKR = ROC(C,1) >= 0 AND Ref(ROC(C,1),1) < 0 ;//PeakRight
> PKRV = ValueWhen(PKR == 1, C,1);//PeakRightValue
> PKL = ROC(C,1) > 0 AND Ref(ROC(C,1),1) <= 0 ;//PeakLeft
> BSPKL = BarsSince(PKL == 1);//BarsSincePeakLeft
> PKP = ValueWhen(PKR == 1, BSPKL,1);//PeakPeriods
> PKPH = HHV(C,PKP + 1); //PeakPeriodHigh
> PKV = ValueWhen(PKRV == PKPH AND PKR == 1, PKRV,1);//PeakValue
> 
> Plot(PKV, "PeakHi",34,8);
> 
> *****************************************************************
> 
> /*P_HHV*/
> 
> P = Param("periods",7,0,50,1);
> H = HHV(C,P);
> Plot(H,"HHV",34,1);
> 
> *******************************************************************
> 
> //PLOTLASTPEAK
> 
> //Suitable for overlaying charts
> //Once overlayed on one chart use the keyboard arrows to scroll up or 
> down through symbol lists
> //SelectedDate ignores dates (bars) before the peak
> //Add additional resistance lines if a deeper history is required
> //Code variations can identify major peaks or change the timeframe 
> upwards
> 
> //PLOTS THE MOST RECENT PEAK RESISTANCE LINE
> 
> PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> PKV = ValueWhen(PK,C,1);//PeakValue
> PKD = ValueWhen(PK,DateNum(),1);//PeakDate
> SD = IIf(DateNum() < LastValue(PKD,lastmode = True ), Null, LastValue
> (PKV,Lastmode = True));//SelectedDate
> 
> Plot(SD, "LastPeak",34,8);
> 
> //PLOT 2ND LAST PEAK RESISTANCE LINE
> 
> PKV2 = ValueWhen(PK,C,2);//PeakValue2
> PKD2 = ValueWhen(PK,DateNum(),2);//PeakDate2
> SD2 = IIf(DateNum() < LastValue(PKD2,lastmode = True ), Null, LastValue
> (PKV2,Lastmode = True));//SelectedDate
> 
> Plot(SD2, "LastPeak2",34,8);
> 
> ****************************************************************
> 
> //PLOTCurrentMAJORPEAKS
> 
> //Suitable for overlaying charts
> //A MajorPeak is defined as the Highest Peak central to any three Peaks
> 
> //PLOT THE LAST MAJOR PEAK RESISTANCE LINE
> 
> 
> PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> PKV0 = ValueWhen(PK,C,0);//PeakValue0
> PKV1 = ValueWhen(PK,C,1);//PeakValue1
> PKV2 = ValueWhen(PK,C,2);//PeakValue2
> MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
> MPKV =  ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, 
> PKV1,1);   //MajorPeakValue
> MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum
> (),1);   //MajorPeakDate
> SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue
> (MPKV,Lastmode = True));//SelectedDate
> 
> Plot(SD, "LastMajorPeak",34,8);
> 
> 
> 
> //PLOT THE SECOND LAST MAJOR PEAK RESISTANCE LINE
> 
> 
> //PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> //PKV0 = ValueWhen(PK,C,0);//PeakValue0
> //PKV1 = ValueWhen(PK,C,1);//PeakValue1
> //PKV2 = ValueWhen(PK,C,2);//PeakValue2
> //MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
> MPKV2 =  ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, 
> PKV1,2);   //MajorPeakValue
> MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum
> (),2);   //MajorPeakDate
> SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue
> (MPKV2,Lastmode = True));//SelectedDate
> 
> Plot(SD2, "LastMajorPeak",34,8);
> 
> ******************************************************************
> 
> //PLOT ALL PEAKS
> 
> //Suitable for overlaying charts
> //References future bars
> 
> //PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
> //PKV = ValueWhen(PK,C,1);//PeakValue
> //Plot(PKV, "LastPeak",34,1);
> 
> /********************************************************************/
> 
> /* draw horizontal lines at hi & lo pivot points*/
> //JohnRUK TraderJUK
> //Shifts resistance line 1 bar
> 
> //P = ParamField("Price field",-1);
> //Hipiv = IIf(P<Ref(P,-1) AND (Ref(P,-1)>Ref(P,-2)),1,0);
> //Lopiv = IIf(P>Ref(P,-1) AND (Ref(P,-1)<Ref(P,-2)),1,0);
> //hiline=ValueWhen(hipiv==1,Ref(P,-1),1);
> //loline=ValueWhen(lopiv==1,Ref(P,-1),1);
> //Plot (Hiline,"hiline",colorRed);
> //Plot (Loline,"loline",colorBlue);
> 
> /*********************************************************************/
> 
> /*P_TROUGHS*/
> 
> /*PLOTS ALL TROUGH VALUES FOR THE PERIOD*/
> 
> 
> //Suitable for overlaying price(C)charts
> //References future bars
> //Recognises flat troughs of any length
> 
> 
> TR = ROC(C,1) <= 0 AND Ref(ROC(C,1),1) > 0 ;//TroughRight
> TRV = ValueWhen(TR == 1, C,1);//TroughRightValue
> TL = ROC(C,1) < 0 AND Ref(ROC(C,1),1) >= 0 ;//TroughLeft
> BSTL = BarsSince(TL == 1);//BarsSinceTroughLeft
> TP = ValueWhen(TR == 1, BSTL,1);//PeakPeriods
> TPL = LLV(C,TP + 1); //TroughPeriodLow
> TV = ValueWhen(TRV == TPL AND TR == 1, TRV,1);//TroughValue
> 
> Plot(TV, "TroughLo",32,8);
> 
> 
> *****************************************************************
> 
> /*PLOTSALLMAJORTROUGHS*/
> 
> /*PLOTS ALL MAJOR TROUGH VALUES FOR THE PERIOD*/
> 
> 
> //Suitable for overlaying price(C)charts
> //References future bars
> //Recognises flat troughs of any length
> //A Major Trough comprises any two Troughs where a Trough is followed 
> by a higher Trough
> 
> 
> TR = ROC(C,1) <= 0 AND Ref(ROC(C,1),1) > 0 ;//TroughRight
> TRV = ValueWhen(TR == 1, C,1);//TroughRightValue
> TL = ROC(C,1) < 0 AND Ref(ROC(C,1),1) >= 0 ;//TroughLeft
> BSTL = BarsSince(TL == 1);//BarsSinceTroughLeft
> TP = ValueWhen(TR == 1, BSTL,1);//TroughPeriods
> TPL = LLV(C,TP + 1); //TroughPeriodLow
> //TV = ValueWhen(TRV == TPL AND TR == 1, TRV,1);//TroughValue
> //MTV = ValueWhen(TV < Ref(TV,1),TV,1);
> 
> TV0 = ValueWhen(TRV == TPL AND TR == 1, TRV,0);//TroughValue0
> TV1 = ValueWhen(TRV == TPL AND TR == 1, TRV,1);//TroughValue1
> TV2 = ValueWhen(TRV == TPL AND TR == 1, TRV,2);//TroughValue2
> TV3 = ValueWhen(TRV == TPL AND TR == 1, TRV,3);//TroughValue3
> 
> MT = TV2 > TV1 AND TV1 < TV0 OR TV3 > TV2 AND TV2 == TV1 AND TV1 < 
> TV0;                                      ; //MajorTrough
> MTV =  ValueWhen(Ref(MT,-1) == 0 AND MT == 1, 
> TV1,1);   //MajorTroughValue
> 
> Plot(MTV, "MajorTroughLo",32,8);
> 
> 
> 
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "droskill" <droskill@> wrote:
> >
> > Hey all - I'm looking for an indicator that produces something similar
> > to this chart from Tradestation:
> > 
> > http://www.elitetrader.com/vb/attachment.php?s=&postid=1582014
> > 
> > I'm talking about the code to show a higher high and lower lows.
> > 
> > Any help appreciated!
> >
>



------------------------------------

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/