how to calculate candle values from prices

ayyaz
ayyaz edited April 2018 in General
i have java ticker program , i would like to calculate candle open,close, high low for all charts ,
what i have done is
open--> first price for that minute say (10:10:02) or last minute candle close
close--> last price value of that minute
high --> highest price value of that minute
low --> lowest price values
while reconfirming with candle values from zerodha i found that open is not always same as last close
and also most of the time rest of values are also different from what i calculated .
and also prices are not on the boundary of minute it can start from some seconds and end before finishing of minute ,
please suggest out of prices i have recieved from zerodha how can i calculate exact candle values for minute and extend these callculation for other charts like 3 , 5 , 10 , 15 , 30 minutes etc..
when i say price value
i mean
double lastTradedPrice = ticks.get(i).getLastTradedPrice();

do you think i should use following values in someway while callculating candles
double close=ticks.get(i).getClosePrice();
double high=ticks.get(i).getHighPrice();
double open=ticks.get(i).getOpenPrice();

if not let me know what are the significance of these close , high , open ,low
this parameters of which interval.

Please try to answer all my question in single answer as i am waiting to finish this implementation .
  • sujith
    sujith edited March 2018
    @ayyaz,
    It is impossible to match the candles from two trading platforms.
    The historical data provided by Kite Connect is generated using a different source. It will be near but won't exactly match.
    Your logic is correct. There are many reasons it won't match, one of them would be your system clock might not exactly match with our server clock.
    You can check more details here.
  • ayyaz
    please answer another question from previous thread infact please try to answer all questions from my post.

    How to calculate candle values from ticker
    like to callculated OHLC
    starting tick is open for that minute
    closing tick is close
    highest is high
    and lowest is low

    below are some of candle values from zerodha


    open | close | high | low | tm | veiwtype | symbol | dt
    ---------+---------+---------+---------+----------+----------+--------+------------
    1305.9 | 1305.85 | 1306.45 | 1305.2 | 14:30:00 | 0 | LT | 2018-03-28 -- one minute

    1305.9 | 1304.9 | 1305.9 | 1304.9 | 14:31:00 | 0 | LT | 2018-03-28 -- candles from 14:30
    1305.5 | 1305.7 | 1305.75 | 1304.85 | 14:32:00 | 0 | LT | 2018-03-28 -- to 14:33
    1305.75 | 1306.2 | 1306.25 | 1305.7 | 14:33:00 | 0 | LT | 2018-03-28

    so 3 minute candle formed at 14:33 should be callculated out of 1 minute candles from 14:31 to 14:33 with that logic lowest of all low's --> 1304.85 , highest of all hi's --> 1306.25 , open=1305.9 and close=1306.2

    1305.75 | 1307.5 | 1308 | 1305.7 | 14:33:00 | 7 | LT | 2018-03-28 -- (14:33 3 minute candle)

    please dont skip this question choose to answer small portion of it . please let me know how callculate 3min, 5 min candles out of 1 min . if my logic is correct then why zerodha values are different , if zerodha values are correct how it came to these values , i am interested in callculating all charts values out of tick by tick prices
  • ayyaz
    i synchronize my clock with NTP , on redhat linux let me know zerodha suggest any common clock source of NTP or zerodha has it own , it if issue is of clock sync , i think zerodha should host an NTP server for algo traders to avoid clock sync issues .
  • ayyaz
    how to get open value of a day is there any API
  • ayyaz
    Please reply
  • ayyaz
    please answer another question from previous thread infact please try to answer all questions from my post.

    How to calculate candle values from ticker
    like to callculated OHLC
    starting tick is open for that minute
    closing tick is close
    highest is high
    and lowest is low

    below are some of candle values from zerodha


    open | close | high | low | tm | veiwtype | symbol | dt
    ---------+---------+---------+---------+----------+----------+--------+------------
    1305.9 | 1305.85 | 1306.45 | 1305.2 | 14:30:00 | 0 | LT | 2018-03-28 -- one minute

    1305.9 | 1304.9 | 1305.9 | 1304.9 | 14:31:00 | 0 | LT | 2018-03-28 -- candles from 14:30
    1305.5 | 1305.7 | 1305.75 | 1304.85 | 14:32:00 | 0 | LT | 2018-03-28 -- to 14:33
    1305.75 | 1306.2 | 1306.25 | 1305.7 | 14:33:00 | 0 | LT | 2018-03-28

    so 3 minute candle formed at 14:33 should be callculated out of 1 minute candles from 14:31 to 14:33 with that logic lowest of all low's --> 1304.85 , highest of all hi's --> 1306.25 , open=1305.9 and close=1306.2

    1305.75 | 1307.5 | 1308 | 1305.7 | 14:33:00 | 7 | LT | 2018-03-28 -- (14:33 3 minute candle)

    please dont skip this question choose to answer small portion of it . please let me know how callculate 3min, 5 min candles out of 1 min . if my logic is correct then why zerodha values are different , if zerodha values are correct how it came to these values , i am interested in callculating all charts values out of tick by tick prices
  • nithin
    @ayyaz do go through this link once. Your logic seems right, but that doesn't mean the candles you capture to what we capture will be the same.

    There could be hundreds of trades getting executed every second on the exchange. Through Kite connect you might get LTP based on random 2 to 3 trades every second on exchange. Similarly our charting server will capture 2 to 3 random ticks that it receives (which maybe completely different to the 2 to 3 you receive as it is hosted in a different place). Neither of them is wrong.
  • ayyaz
    precision matters a lot to our algo because we are trying to work at minute chart where a slight change in the candle price or LTP entirely changes our candle pattern analysis ..
    please suggest a solution where we can bank on .
  • nithin
    If every tick matters, I think the data that you get from our OMS wouldn't be good enough. The best way to get all ticks is by subscribing to tick by tick data (putting your servers on the exchange itself, can cost upwards of 10lks per year including server+colocation cost). Second best option is to go to a professional data vendor, the data quality is better if you subscribe to data feeds from them. This link from NSE has all types of data feed you can subscribe to at NSE. The issue you will have with professional data vendors is that they'd probably not give you raw data feed. You can speak and see. Here is the list.
This discussion has been closed.