IIF works on *both* arrays and scalars, if both arguments are scalar it will return scalar.
Best regards, Tomasz Janeczko amibroker.com ----- Original Message ----- From: "edwol53" <[email protected]> To: <[email protected]> Sent: Tuesday, July 28, 2009 8:42 AM Subject: [amibroker] Re: Trailing stop does not work - > Keith > > Thanks for your input BUT this is TJ's code, I would expect that it would be > correct, I recall reading somewhere that assigning a > scalar in this fashion works as a Logical AND for scalars againts the entire > array. > > I had to stare at this for a while myself. > > Any other sugesstions? > > > --- In [email protected], Keith McCombs <kmcco...@...> wrote: >> >> In the code below, TL[i] is a 'value'. IIf() operates on arrays and >> returns an 'array'. Therefore, you are trying to set a 'value' equal to >> an array, which is impossible. >> >> TL[ i ] = IIf( Cond1 AND Stop[ i ] > Value3, Stop[ i ], >> IIf( Cond1 AND Stop[ i ] < Value3, Value3, >> IIf( NOT Cond1, Prev, Stop[ i ] * HoldingDays[ i ] ) ) ); >> >> Re-read User Manual and/or Help regarding arrays. Re-read it again, and >> again. >> This is a classic mistake made by many AFL newbees. >> >> >> edwol53 wrote: >> > >> > >> > Hello >> > >> > Could any AFL expert or any one else see why the traing stop (for long >> > side) in the code below does not work? >> > >> > I have uploaded a PDF ("PROFIT LOCKING AND THE RELATIVE PRICE >> > CHANNEL-2.pdf " >> > http://f1.grp.yahoofs.com/v1/0IVuSoMsbmfIJkS8BkrK-OzCjyoqwQfjxR02zpQSIVvPq-fWYu_5Bakzj2IZQxSdhHaawLCqyDLqtawdnYI3uJezUqn-/PROFIT%20LOCKING%20AND%20THE%20RELATIVE%20PRICE%20CHANNEL%202.pdf >> > <http://f1.grp.yahoofs.com/v1/0IVuSoMsbmfIJkS8BkrK-OzCjyoqwQfjxR02zpQSIVvPq-fWYu_5Bakzj2IZQxSdhHaawLCqyDLqtawdnYI3uJezUqn-/PROFIT%20LOCKING%20AND%20THE%20RELATIVE%20PRICE%20CHANNEL%202.pdf>) >> > >> > of screen shots of Amibroker and the working version of Metastock for >> > the same indicator in the files section for temporary reference. >> > >> > There seems to be an intial value that I cannot see where it >> > originates from. There are some commented out attempts to see where >> > the problem left in the code below that can be deleted - they give the >> > same result. >> > >> > Thanks in advance for some input >> > Ed >> > >> > Code: >> > //PROFIT LOCKING AND THE RELATIVE PRICE CHANNEL >> > //Amended - 27 July 2009 >> > //S&C Traders' Tips Issue 1/2008 >> > Version(5.20); //Requires v5.20 >> > SetBarsRequired(sbrAll); //Use all available bars >> > dt = ParamDate("Date of the trend", "2008-11-21" ); // get start date >> > Value1 = Param("Bearish Periods", 21, 3, 55 ); >> > Value2 = Param("Multiplication Factor", 3.8, 1, 10 ); >> > Value3 = Param("Initial Stop", 10, 0, 1e6 ); >> > Value4 = Param("Channel Periods", 21, 3, 55 ); // Channel Periods >> > Value5 = Param("Overbought region", 75, 1, 100 ); // Overbought region >> > Value6 = Param("Channel Smoothing", 1, 1, 10 ); >> > >> > Start = Cross(DateNum(),dt); >> > Started = Flip(Start, 0); >> > >> > HoldingDays = BarsSince( DateNum() < dt ); >> > >> > Index = RSI( Value4 ); >> > OB = EMA( Index - Value5, Value6 ); >> > Bullish = Close - ( Close * OB/100 ); >> > >> > //Calculate trailing stop line >> > TL = Null; >> > Stop = Null; >> > Prev = 0; //Temporary scalar variable >> > trailstop = 0; >> > >> > Bearish = Sum( abs( Low - Ref( Low, -1 ) ), Value1 ) / Value1; >> > RangeA = Sum( Close - Low, Value1 ) / Value1; >> > Stop = Close - ( ( Bearish + RangeA ) * Value2 ); >> > >> > for( i = 1; i < BarCount; i++ ) >> > { >> > if(Started[i] == 0 ) continue; >> > Prev = TL[ i - 1 ]; >> > Cond1 = Stop[ i ] > Prev; >> > >> > // if(NOT(Started[i-1]) AND Started[i]) TL[i-1] = Value3; //OR use >> > TL[i-1] = Stop[i-1]; >> > >> > /* if( Stop[ i ] > Prev AND Stop[ i ] > Value3) >> > trailstop = Stop[ i ]; >> > else >> > if( Stop[ i ] > Prev AND Stop[ i ] < Value3) >> > trailstop = Value3; >> > else >> > if( Stop[ i ] <= Prev) >> > trailstop = Prev; >> > else trailstop = Stop[ i ] * HoldingDays[ i ] ; >> > TL[ i ] = trailstop; >> > */ >> > /* >> > TL[ i ] = IIf( Stop[ i ] > Prev AND Stop[ i ] > Value3, Stop[ i ], >> > IIf( Stop[ i ] > Prev AND Stop[ i ] < Value3, Value3, >> > IIf( Stop[ i ] <= Prev, Prev, Stop[ i ] * HoldingDays[ i ] ) ) ); >> > */ >> > >> > TL[ i ] = IIf( Cond1 AND Stop[ i ] > Value3, Stop[ i ], >> > IIf( Cond1 AND Stop[ i ] < Value3, Value3, >> > IIf( NOT Cond1, Prev, Stop[ i ] * HoldingDays[ i ] ) ) ); >> > >> > } >> > /* _TRACE(" i = " + NumToStr(i, 1.0) + " index date = " + NumToStr(dt, >> > 1.0) + " Stop i = " + NumToStr(Stop, 3.0) + " TL[i] = " + NumToStr(TL, >> > 3.0)); */ >> > >> > // TL = IIf( HoldingDays == 0, Null, TL ); // Plot from the input date >> > Bullish = IIf( HoldingDays == 0, Null, Bullish ); >> > >> > Plot( C, "Price", IIf( C > O, colorGreen, colorRed ), styleCandle ); >> > Plot( TL, "TL", colorBlue ); >> > Plot( Stop, "Stop", colorGreen ); >> > // Plot( Prev, "Prev", colorRed ); >> > // Plot( Bullish, "Bullish", colorLightGrey ); >> > // PlotOHLC( TL, TL, Bullish, Bullish, "", ColorRGB( 230, 230, 230), >> > styleCloud | styleNoLabel ); >> > Title = "{{NAME}} - {{DATE}} - {{VALUES}}"; >> > >> > >> > > > > > ------------------------------------ > > **** IMPORTANT PLEASE READ **** > This group is for the discussion between users only. > This is *NOT* technical support channel. > > TO GET TECHNICAL SUPPORT send an e-mail directly to > SUPPORT {at} amibroker.com > > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at > http://www.amibroker.com/feedback/ > (submissions sent via other channels won't be considered) > > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: > http://www.amibroker.com/devlog/ > > Yahoo! Groups Links > > >
