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

[amibroker] Median Calculations of 2 Separate Conditional Arrays



PureBytes Links

Trading Reference Links



How do I create separate arrays of conditional values, such as the last four
peak arrows and the last trough arrows, in this example?
Specifically LongTPTop and LongTPBot in the example below
Then plot that LastValue of the Medians of both those newly created arrays?

Trying to learn array manipulation, Thanks in advance,
Mr Valley

/////////////////This is not working as I would like
// If I want to take the median of the last four conditional events - not
using Peak or Trough
// How can I use a loop to iterate through 0,1,2,3 to arrive at 4 values in
the array and take the median of those 4 values

top = LongTPTop1 == Close; // whatever
bot = LongTPBot2 == Close; //whatever

variable = 5;

x=Cum(1);

cond1[ 0 ] = top[ 0 ]; // initialize first value
cond2[ 0 ] = bot[ 0 ]; // initialize first value

for( i = 1; i < variable   i++ )
{
cond1[ 0 ] = Close[ 0 ]; // initialize first value
cond2[ 0 ] = Close[ 0 ]; // initialize first value

}


Condition1 = cond1[ 0 ];
Condition2 = cond2[ 0 ];

result1 = IIf( condition1, c, 0.00 );
result2 = IIf( condition2, c, 0.00 );


MedianH = Median(result1 ,variable );
MedianMid = Median(result1  AND result2,variable )
MedianL =  Median(result2 ,variable );
 //////////////////////////////////////////



///////////////////Below is the formula I would like to take the median of
the last for values of LongTPTop and LongTPBot from - (Plot and See what I
mean on EOD data)

 /*trend find */
GraphXSpace =4;
LongPer = 4;
longrisecheck =0;
longfallcheck =0;
//BAR AVERAGE PRICE
avrg = IIf(IsIndex() AND L!=H, (H+L+C*3)/5, IIf(V>0, (H+L+C*3)/5, 0));

// LONG TRENDS

LongStart = BarIndex()%(LongPer)==0;
LongEnd = BarIndex()%(LongPer)==(LongPer-1) OR BarIndex()==(BarCount-1);

LongFirst = ValueWhen(LongStart, BarIndex(), 1);
LongLast = IIf( LongEnd, BarIndex(), ValueWhen(LongEnd, BarIndex(), 0));

LongHighValue = IIf( LongEnd, HHV(H,LongPer), ValueWhen( LongEnd,
HHV(H,LongPer), 0 ));
LongLowValue = IIf( LongEnd, LLV(L,LongPer), ValueWhen( LongEnd,
LLV(L,LongPer), 0 ) );

LongHigh = LongHighValue == H;
LongLow = LongLowValue == L;

LongBarsToGo = IIf( LongEnd, 0 , LongLast - BarIndex());
LongBarsGone = BarIndex() - LongFirst + 1;

RestOfLongHigh = IIf( LongEnd, 0 ,
ValueWhen(LongEnd, Sum(LongHigh,LongPer), 0) - Sum(LongHigh,LongBarsGone) );

RestOfLongLow = IIf( LongEnd, 0 ,
ValueWhen(LongEnd, Sum(LongLow,LongPer), 0 ) - Sum(LongLow,LongBarsGone) );

LongCount = Sum( IIf(IsIndex(),L!=H,V>0), LongPer );
LongAvg = Nz( Sum(avrg, LongPer) / Longcount );
LongLevelAvg = IIf( LongEnd, LongAvg, ValueWhen(LongEnd, LongAvg, 0) );

//FIND LONG PERIOD HIGH & LOW

LongBarHigh= 0;
LongBarLow= 0;
LongLevelLow =Null;
LongLevelHigh =Null;

for( i=1; i<=BarCount-1 ; i++ )
{
if( LongHigh[i] && RestOfLongHigh[i]==0 )
{
  LongBarHigh[i] = 1;
  LongLevelHigh[i] = H[i];
}
else
{
  LongBarHigh[i] = 0;
  LongLevelHigh[i]=LongLevelHigh[i-1];
}
}

for( i=1; i<=BarCount-1 ; i++ )
{
if( LongLow[i] && RestOfLongLow[i]==0 )
{
  LongBarLow[i] = 1;
  LongLevelLow[i] = L[i];
}
else
{
  LongBarLow[i] = 0;
  LongLevelLow[i] = LongLevelLow[i-1];
}
}

//FIND TRENDS OF PERIODS USING PERIOD END

LongTopLevelAvgNext1 = ValueWhen(LongBarHigh, LongLevelAvg, 0);
LongTopLevelAvgNext2 = ValueWhen(LongBarHigh, LongLevelAvg, -1);

LongBotLevelAvgNext1 = ValueWhen(LongBarLow, LongLevelAvg, 0);
LongBotLevelAvgNext2 = ValueWhen(LongBarLow, LongLevelAvg, -1);

//Combinations
LT1 = LongLevelAvg>LongTopLevelAvgNext1;
LT2 = LongTopLevelAvgNext1>LongTopLevelAvgNext2;

LB1 = LongLevelAvg<LongBotLevelAvgNext1;
LB2 = LongBotLevelAvgNext1<LongBotLevelAvgNext2;

LongRise = 0;
LongFall = 0;

for(i=1;i<=BarCount-1;i++)
{
if( LongBarHigh[i] AND LT1[i] AND LT2[i] )
{
  LongRise[i] = 0;
  LongFall[i] = 1;
}
else
{
  if( LongBarLow[i] AND LB1[i] AND LB2[i] )
  {
   LongRise[i] = 1;
   LongFall[i] = 0;
  }
  else
  {
   LongRise[i] = LongRise[i-1];
   LongFall[i] = LongFall[i-1];
  }
}
}

LongTPBot = LongBarLow AND LongRise AND Ref(LongRise,-1)==0;
LongTPTop = LongBarHigh AND LongFall AND Ref(LongFall,-1)==0;
LongTPBotBar = ValueWhen(LongTPBot, BarIndex());
LongTPTopBar = ValueWhen(LongTPTop, BarIndex());
LongTPBotPrice = ValueWhen(LongTPBot, LongLevelLow);
LongTPTopPrice = ValueWhen(LongTPTop, LongLevelHigh);

Plot(C,"", IIf( longRise AND LongRiseCheck, colorBlue, IIf(longFall AND
LongFallCheck, colorRed, colorBlack)), styleBar +styleThick);
GraphXSpace=5;
_N( Title = Name()+" "+Date() + ": Moves Trading System, Period( " + LongPer
+ " ) Long Moves - Rising = Blue bars, Falling = Red bars ");

Plot( LongTPBotPrice, "",
colorDarkGreen,styleDots|styleNoLine|styleNoRescale );
Plot( LongTPTopPrice, "", colorBrown, styleDots|styleNoLine|styleNoRescale);


PlotShapes( shapeUpArrow*LongTPBot, colorDarkGreen, 0, L, -20 );
PlotShapes( shapeDownArrow*LongTPTop, colorBrown, 0, H, -20 );


Buynow = shapeUpArrow*LongTPBot == 1;
SellNow =shapeDownArrow*LongTPTop > 0;
Plot(Close  ,"Close" + EncodeColor( colorWhite )  ,2, styleNoLine |
styleNoRescale );
Plot(7,   /* defines the height of the ribbon in percent of pane width
*/"",IIf( BuyNow, colorGreen, IIf( SellNow, colorRed, 7 )), /* choose
color*/styleOwnScale|styleArea|styleNoLabel, -0.5, 100);

//--Indicator-End--
// INTERPRETATION WINDOW

Decimal = IIf(IsIndex(),1,1.3);

Name();
"Moves System, Long Trend Plot";

"Trend Period( " + LongPer + " )  ";
"Trends are " + WriteIf(LongRiseCheck,"Rising Long, ","Falling Long, ");

"Current Levels ";
"   Support    = " + WriteVal(LongTPBotPrice,Decimal);
"   Resistance = " + WriteVal(LongTPTopPrice,Decimal);


[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

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

<*> 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/