Open/Close Trade For Candle

 
If I wanted to open/close a short/long trade using the below criteria, what methodes and/or stratagies would you recommend to me to accomplish following candles:

Tail is n % of total Hammer height - input=Minimum percentage of total Candle height represented by the Tail.

Long Trade, Open Candle:

Open – Low

------------- = n%
High – Low

Long Trade, Closed Candle:
Close – Low
-------------- = n%
High – Low

Short Trade, Open Candle:
High – Close
-------------- = n%
High – Low

Short Trade, Closed Candle:
High – Open
-------------- = n%
High – Low

Hammer is n pips in height (H to L) - input=Minimum height of candle in pips.

There is 'no cover' for preceding n bars - input=Number of pips that S/L will trail 2nd half of trade after each new high/low is made. ***If this is set to 0, both positions exit at Take Profit input.
Long trades: Tail low must be the lowest price for the preceding n bars. If a lower price was marked at any time during the prior n bars, the Long Hammer is disqualified and no trade is initiated.
Short trades: Tail high must be the highest price for the preceding n bars. If a higher price was marked at any time during the prior n bars, the Short Hammer is disqualified and no trade is initiated.

There must be an x pips move over n bars prior to Hammer (x pips move down for Long Hammer, x pips move up for Short Hammer) - input=Beginning time – sets the GMT hour that EA becomes active. Ending time – sets the GMT hour that EA becomes inactive (goes inactive at scheduled time if no trades are open; if trade is open, goes inactive as soon as trade is closed out by EA rules).
 

My current code is attached and I know that some of it is not working right, but it is trading.

I could use some help getting the above criteria working properly.

Files:
candles.mq4  35 kb
 
Here is the document I am trying to make happen.