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

Re: [amibroker] Creating a toggle switch



PureBytes Links

Trading Reference Links

you could try this
Tog = Flip( O_Bought, O_Sold );
Toggle = iif( tog, 1, -1 );

or just use the Tog if 0/1 is sufficient

else using looping you would need something like this

for( i = 1; i < BarCount; i++ )
{
 if( O_Bought[i] )
 { ExhInd[i] =1; }
 else
 {
  if( O_Sold[i] )
  {  ExhInd[i] = -1; }
  else
  { ExhInd[i] = ExhInd[i-1]; }
 }
}
On 6/27/05, ricko8294_98 <ricko@xxxxxxxxxx> wrote:
> Hello
> 
> I have been unable to code a variable that will toggle between two
> values (+1 and -1) and to hang onto the assigned values until the
> other value is encountered.
> 
> For example, I am trying to code a variable that will keep track of
> exhaustion points - first overbought, then oversold.
> 
> I have the following code:
> 
> O_Bought = StochD(45,1) < 30 AND Ref(StochD(7,1),-1) < 10 AND
>         StochD(7,1)> Ref(StochD(7,1),-1);
> O_Sold = StochD(45,1) > 70 AND Ref(StochD(7,1),-1) > 90 AND
>         StochD(7,1) < Ref(StochD(7,1),-1);
> 
> for( i = 1; i < BarCount; i++ )
> {
> ExhInd[i] = IIf(O_Bought[i],1,
>         IIf(O_Sold[i],-1,ExhInd[i-1]));
> }
> 
> I find that sometimes this code seems to work - but not always - very
> frustrating.
> 
> If anyone can help solve this for me I would be mose appreciative
> 
> Thanks
> Rick
> 
> 
> 
> 
> Please note that this group is for discussion between users only.
> 
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
> 
> For other support material please check also:
> http://www.amibroker.com/support.html
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 


-- 
Cheers
Graham
http://e-wire.net.au/~eb_kavan/


Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

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/

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