select symbol from bhav_data group by 1 into cursor distsymbol nofilter scan wait window distsymbol.symbol nowait select date,close from bhav_data where symbol = distsymbol.symbol into cursor s1 nofilter use dbf('s1') in 0 alias s2 again select s1 set relation to recno()+1 into s2 create cursor gainloss(date D,gain f(10,2),loss f(10,2)) select s1 scan if eof('s2') exit endif m.diff = s1.close - s2.close if m.diff > 0 insert into gainloss values(s2.date,m.diff,0) else insert into gainloss values(s2.date,0,m.diff*-1.00) endif endscan use in select('s2') use in select('s1') select gainloss index on date tag date1 desc locate use dbf('gainloss') in 0 alias gainloss1 again select gainloss1 index on date tag date2 desc select gainloss set relation to date into gainloss1 scan select gainloss1 average gain,loss next 14 to m.gain,m.loss m.rs = m.gain/m.loss update bhav_data set RSI = (100-(100/(1+m.rs))) ; where date = gainloss.date and ; symbol = distsymbol.symbol endscan use in select('gainloss') use in select('gainloss1') endscanit takes abt 15 - 20 minutes to process