Imagine being on computer A. You want to shutdown computer B. How do you do this?
ssh -t computer.B 'shutdown -p now'
Now you want to execute that command ("ssh -t computer.B...") on your computer. You need to quote it, but in the command there are already two quotes, so you need to escape them:
ssh -t computer.A 'ssh -t computer.B \'shutdown -p now\''
and actually you want to execute two commands, so you need to add it inside the outer quotes:
ssh -t computer.A 'ssh -t computer.B \'shutdown -p now\'; shutdown -p now'
If you want to iterate this by connecting to your computer from outside, just rinse and repeat:
first stage, escape all quotes and all slashes, so
\'. Which means that
ssh -t computer.A \'ssh -t computer.B \\\'shutdown -p now\\\'; shutdown -p now\'
second stage: enclose in quotes, add the shutdown command and prepend the ssh instruction:
ssh -t mycomputer 'ssh -t computer.A \'ssh -t computer.B \\\'shutdown -p now\\\'; shutdown -p now\'; shutdown -p now'