The advantages of proton therapy can be further enhanced with online magnetic resonance imaging (MRI) guidance. One of the challenges in the realization of MRI-guided proton therapy (MRPT) is accurately calculating the radiation dose in the presence of magnetic fields. This study aims to develop an efficient and accurate proton dose calculation algorithm adapted to the presence of magnetic fields. An analytical-numerical radiation dose calculation algorithm, Proton and Ion Dose Engine (PRIDE), was developed. The algorithm combines the pencil beam algorithm (PBA) with a novel iterative voxel-based ray-tracing algorithm. The new ray-tracing method uses fewer assumptions and ensures broader applicability for proton beam trajectory prediction in magnetic fields, and has been compared to Wolf's method and Schellhammer's method. The accuracy of PRIDE algorithm was validated on three phantoms and two practical plans (one single-field water plan and one prostate tumor plan) in different magnetic field strengths up to 3.0 T. The validation was performed by comparing the results against the Monte Carlo (MC) simulations, using the global gamma index criteria of 2%/2mm and 3%/3mm with a 10% threshold. PRIDE showed good agreement with MC in homogeneous and slab heterogeneous phantom, achieving gamma passing rates (%GPs) above 99% for 2%/2mm criteria when magnetic field strength is not greater than 1.5 T. Although the agreement decreased for scenarios involving high proton energy (240 MeV) and strong magnetic field (3.0 T), the 2%/2mm %GPs still remained above 98%. In lateral heterogeneous phantom, the accuracy of PRIDE decreased due to the PBA's limitation. For the two practical plans in different magnetic fields, %GPs exceeded 98% and 99% for 2%/2mm and 3%/3mm criteria, respectively. PRIDE can perform efficient and accurate proton dose calculation in magnetic fields up to 3.0 T, and is expected to work as a useful tool for proton dose calculation in MRPT.