Integrated Application Platform › Forums › General › Error while updating › Re: Re: Error while updating
Hi Ajith,
Good to hear from you after so long! I hope you are well.
I ran it here. I think this is the part of the output you are looking for:
329.88 prev_EMA: 330.39 difference: -3.34 rec_price: 327.05 rec_date: #20101110
[macdhisto: -329.53, aroonup: 4, ema: 329.94, open: 335, aroondown: 60, high: 345.6, sma: 329.455, turnover: 34002.51, low: 325.55, date: #20101110, ttq: 10217605, ltp: 327, calc2: 329.47, serialno: 217, calc1: 329.83, macd: -.06, vol_sign: "neg", close: 327.05]
327.82 prev_EMA: 329.83 difference: -13.08 rec_price: 316.75 rec_date: #20101111
[macdhisto: -327.99, aroonup: 4, ema: 328.96, open: 325.45, aroondown: 100, high: 326.75, sma: 328.065, turnover: 22661.5, low: 316, date: #20101111, ttq: 7070523, ltp: 317.2, calc2: 326.93, serialno: 218, calc1: 327.86, macd: -1.06, vol_sign: "neg", close: 316.75]
It seems the same as what you are talking about.
I do not understand what it is doing exactly, but I can suggest some possible issues:
Doing a Query1 to get the previous record will use a separate transaction from the QueryApply, so it will get the record before the update (since the QueryApply transaction does not get committed till the very end). If you want it to get the new updated record then you need to do transaction.Query1 using the same transaction as the QueryApply. To do this you can wrap the loop in a Transaction block and use t.QueryApply and t.Query1. Or you can get the QueryApply transaction using rec.Transaction() e.g.
t = rec.Transaction()
prevrec = t.Query1(stockname, serialno: (rec.serialno -1))
If I do this, I get:
329.88 prev_EMA: 330.39 difference: -3.34 rec_price: 327.05 rec_date: #20101110
[macdhisto: -329.53, aroonup: 4, ema: 329.94, open: 335, aroondown: 60, high: 345.6, sma: 329.455, turnover: 34002.51, low: 325.55, date: #20101110, ttq: 10217605, ltp: 327, calc2: 329.47, serialno: 217, calc1: 329.88, macd: -.06, vol_sign: "neg", close: 327.05]
327.86 prev_EMA: 329.88 difference: -13.13 rec_price: 316.75 rec_date: #20101111
[macdhisto: -327.99, aroonup: 4, ema: 328.96, open: 325.45, aroondown: 100, high: 326.75, sma: 328.065, turnover: 22661.5, low: 316, date: #20101111, ttq: 7070523, ltp: 317.2, calc2: 326.93, serialno: 218, calc1: 327.86, macd: -1.06, vol_sign: "neg", close: 316.75]
But maybe you do not need to do Query1 at all? You can just have a variable for the previous record, and do prev_rec = rec at the end of the loop. Although this would not supply a prev_rec for the first loop.
I hope that helps.