Investigation of the thermoelastic martensitic transformation is of high interest nowadays because of the numerous applications of the materials with such structural peculiarities. Thermodynamics, kinetics, structure, morphology of martensitic transformation still remain unclear in many respects. From this point of view, the effective way to study various properties of metallic crystals on atomistic level is molecular dynamics simulation, for which good qualitative agreement with the experiment can be achieved even with simple Morse or Lennard-Jones interatomic potentials. In this paper, the effect of dislocations on the direct and reverse martensitic transformation is studied by molecular dynamics simulation in a two-dimensional model of the ordered alloy with the AB stoichiometry. The three dimensional analog to this structure is B2 superstructure based on bcc lattice, which is characteristic for intermetallic NiTi alloy. It is found, that the dislocations can be considered as the nucleation centers for martensite phase, increasing the temperature of the direct martensitic transformation in comparison with the homogeneous martensitic transformation. The martensite domains found in the structure after transformation and the reverse martensitic transformation takes place in the presence of the domain boundaries, meaning that the austenite nucleates heterogeneously. At the reverse transformation, splitting of perfect dislocations into partials dislocations took place. Thus, it was established in the present study that, on the one hand, dislocations affect the direct martensitic transformation as the nucleation centers, and from the other hand, reverse martensitic transformation changes the dislocation structure of the modeled alloy.