Pseudocode for pyramiding into a sell-off:

Code:
prevShortPrice = NULL;                            //this is were the last Order lies, could be stored into this variable or directly fedged from Order-Management-System
numShortLevels = 10;            //this is the maximum of orders allowed in one direction.

If (numShort() != 0 and prevShortPrice != NULL and numShort() <= numShortLevels)
{
   if( (prevShortPrice - Bid) >= 25_Pips )      //or ATR(x) instead 25 Pips
   {
       enterShort();
       prevShortPrice = currentlyEnteredOrderprice;    //currentlyEnteredOrderprice is the Openprice of the current enterShort()-execution
   }
}

If (numShort() == 0 and whatever_Condition == TRUE)
{
   enterShort();
   prevShortPrice = currentlyEnteredOrderprice;
}