Lameness is an important economic problem in the dairy sector, resulting in production loss and reduced welfare of dairy cows. Given the modern-day expansion of dairy herds, a tool to automatically detect lameness in real-time can therefore create added value for the farmer. The challenge in developing camera-based tools is that one system has to work for all the animals on the farm despite each animal having its own individual lameness response. Individualising these systems based on animal-level historical data is a way to achieve accurate monitoring on farm scale. The goal of this study is to optimise a lameness monitoring algorithm based on back posture values derived from a camera for individual cows by tuning the deviation thresholds and the quantity of the historical data being used. Back posture values from a sample of 209 Holstein Friesian cows in a large herd of over 2000 cows were collected during 15 months on a commercial dairy farm in Sweden. A historical data set of back posture values was generated for each cow to calculate an individual healthy reference per cow. For a gold standard reference, manual scoring of lameness based on the Sprecher scale was carried out weekly by a single skilled observer during the final 6 weeks of data collection. Using an individual threshold, deviations from the healthy reference were identified with a specificity of 82.3%, a sensitivity of 79%, an accuracy of 82%, and a precision of 36.1% when the length of the healthy reference window was not limited. When the length of the healthy reference window was varied between 30 and 250 days, it was observed that algorithm performance was maximised with a reference window of 200 days. This paper presents a high-performing lameness detection system and demonstrates the importance of the historical window length for healthy reference calculation in order to ensure the use of meaningful historical data in deviation detection algorithms.