maybe you can write this one line of gcode in a file, store it on the SD card and then just “print” that file. But the easier option is to get pronterface or octoprint etc. and just send the gcode manually.
You may want to add the following lines to the beginning of your custom END G-CODE in your slicer iot retract filament:
G91 ; Relative positioning
G1 E-17 F1200 ; Retract 17mm
G4 S3 ; wait 3 seconds
G1 E-50 F2700 ; Retract 50mm
PS: Edited iot add a few seconds waiting time for filament to cool down