Shape memory alloys (SMAs) exist in different phases depending on temperature and stress level. Experimental evidence shows that SMAs oscillate between two shapes during thermal cycling. This phenomenon, known as two-way shape-memory effect, occurs due to a transformation between the austenitic phase and the martensitic phase. The two-way shape-memory behavior is studied here by molecular dynamics simulations in NiTi nanowires of different diameter to understand the effect of loading on the size-dependent behavior. Thermal cycling is performed while holding the system at zero stress and at a fixed compressive stress. At zero stress, the martensite structure formed on cooling depends on the wire diameter. However, when cooling is performed at a sufficiently large constant compressive stress, the formation of a single martensitic variant is observed for all diameters.