The following script is intended to have the following functions:
- find a row in eurusd_m1 where volume=250,
- find the row before row 1,
- find the row after row 1,
copy the required values from each of these rows into a single row in obsh4
Create procedure doji_result () begin DECLARE initial DATETIME; DECLARE final DATETIME; DECLARE centre DATETIME; DECLARE x int; SET x = 0; SET @initial = (select MQLTime from eurusd_m1 where volume=250 order by mqltime asc limit 1); SET @final = (select MQLTime from eurusd_m1 where volume=250 order by mqltime desc limit 1); REPEAT SET @centre = (select MQLTime from eurusd_m1 where volume=250 order by mqltime asc limit x,1); INSERT INTO obsh4 (MQLrefTime,RrefTime,Open,High,Low,Close,Volume) select MQLTime,RTime,Open,high,Low,Close,Volume from eurusd_m1 where MQLTime = @centre order by MQLTime asc limit 1; INSERT INTO obsh4 (Open2,High2,Low2,Close2,Volume2) select Open,high,Low,Close,Volume from eurusd_m1 where MQLTime < @centre order by MQLTime desc limit 1; INSERT INTO obsh4 (Open3,High3,Low3,Close3,Volume3) select Open,high,Low,Close,Volume from eurusd_m1 where MQLTime > @centre order by MQLTime asc limit 1; SET x=x+1; UNTIL @centre=@final END REPEAT; END $$ DELIMITER ;
When I run this each row from eurusd_m1 is copied to a new row in obsh4 (rather than all three rows being collapsed into a single row with each loop iteration)
I tried to use UPDATE for adding the second and third row of data using the following script however I get a syntax issue on FROM and I'm not sure how to remedy that either :/
update obsh4 set Open2 = open, High2 = high, Low2 = low, Close2 = close, Volume2 = volume, from select Open,high,Low,Close,Volume from eurusd_m1 where MQLTime < @centre order by MQLTime desc limit 1;
I can see three options:
1) the update statement needs to be remedied
2) there needs to be row specification added to the insertion of the second/third rows
3) binning and generating something from scratch.
Any suggestions on either of these would be most welcome. Thank you
Edit: the loop itself operates correctly and has been tested independently of the current problem.