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

Re: [amibroker] Re: Can be coded without loop?



PureBytes Links

Trading Reference Links

Brian & Mark,

Thanks for responses. Valuewhen was the function I was somehow forgetting - too much screen time ;-)

Code below draws simple hi/lo pivot level lines on selected plot.

John   <|:-) .........(dunces hat)

8<
/* draw horizontal lines at hi & lo pivot points*/
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);
8<

  ----- Original Message ----- 
  From: brian.z123 
  To: amibroker@xxxxxxxxxxxxxxx 
  Sent: Friday, October 13, 2006 3:29 AM
  Subject: [amibroker] Re: Can be coded without loop?


  Hello John,

  I came out of weekly hibernation on account of you being a gentleman 
  and a scholar.

  Here is a small suite that fits nicely with Prakash's example.
  I modified his code to make it consistent with my style (I prefer 
  bar charts to candlestick and generally overlay for this type of 
  *indicator*).
  I haven't got around to doing the troughs.
  They are the introductory modules for some higher level indicators 
  (still in the pipeline).

  I hope they offer some help or stimulate some ideas that lead to 
  resolutions for you.

  ----------------------------------------------------------
  //PLOTSRCHANNEL

  //Plots a support and resistance channel
  //Top Band looks back X periods and plots a new recent HHV each time 
  the Close crosses above the MA
  //Bottom Band looks back X periods and plots a new recent LLV each 
  time Close crosses below the MA
  //Suitable for overlaying on charts

  /* Modified from AFL Code by Prakash Shenoi */

  P= Param("Periods",10,1,30,1);//Periods
  R=ValueWhen(Cross(C,MA(C,P)),HHV(H,P),1);//Resistance
  S=ValueWhen(Cross(MA(C,P),C),LLV(L,P),1);//Support
  Plot (R,"Res",34,8+16);
  Plot (S,"Supp",32,8+16);

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

  //PLOTALLPEAKS

  //PLOTS ALL PEAK RESISTANCE LINES

  //Suitable for overlaying charts
  //Best viewed with chart in colorBlack, styleLine view
  //This example is for use with Price(C) charts
  //Peaks can be defined for any array 
  //A Peak is defined as the Highest High central to any three bars
  /*Alternative Peak definitions can use more bars 
  AND/OR allow for equal highs on consecutive bars*/
  /*Green is chosen as the Resistance line color to 
  standardise ProfitStop lines for Bull trades*/
  /*Red is chosen as the Support line color to 
  standardise StopLoss lines for Bear trades*/

  PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
  PKV = ValueWhen(PK,C,1);//PeakValue
  Plot(PKV, "LastPeak",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 nominated peak
  //Add additional resistance lines if a deeper history is required
  /*Code variations can identify major peaks or alternatively 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 (unwrap this line back to SD)

  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 (unwrap this line 
  back to SD)

  Plot(SD2, "LastPeak2",34,8);

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

  //PlotDynHiPeak

  //DYNAMICALLY PLOTS HIGHEST PEAK VALUE FOR THE PERIOD

  //Suitable for overlaying 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*/
  /*Caution: it will not see peaks with flat tops (two or more equal 
  closes)*/
  /*Caution: (draft code) occasionally selects HHV resistance one bar 
  outside of range, cause not known*/

  PK = C > Ref(C,-1) AND Ref(C,1) < C;//Peak
  PKV = ValueWhen(PK,C,1);//PeakValue
  P = LastValue(BarIndex(),Lastmode=True) - BeginValue(BarIndex
  ());//Period (unwrap this line back to P)
  HPK = HHV(PKV,P);//HighestPeakValue
  SD = IIf(DateNum() < BeginValue(DateNum()), Null, LastValue
  (HPK,lastmode=True));//SelectedDate (unwrap this line back to SD)

  Plot(SD, "PeriodHiPeak",34,8);

  BrianB2 8:-).............(RayBans on forehead)

  --- In amibroker@xxxxxxxxxxxxxxx, "John R" <jr-ta@xxx> wrote:
  >
  > Hi
  > 
  > I wanted to plot some horizontal lines extending from successive 
  hi and lo
  > pivot points. The code below illustrates the intention but does 
  not work as
  > I guess IIF is evaluating the argument arrays prior to execution.
  > 
  > Wondering if there is a way to do this without looping? Basically 
  need
  > method to propagate same value thru array until condition changes 
  then
  > propagate next value...
  > 
  > John
  > 
  > 8<
  > /* draw horizontal lines at hi & lo pivot points*/
  > //P = ParamField("Price field",-1);
  > p=Close;
  > 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);
  > Hline=0;
  > hline=IIf(hipiv==1,Ref(p,-1),Ref(hline,-1));
  > Plot (C,"close",colorBlack);
  > Plot (Hline,"hline",colorRed);
  > 8<
  > /
  >



   
Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.27/517 - Release Date: 11/3/2006