Trailing-stop to enter a position

So, I want to create a trailing stop order to enter a new position when certain conditions are met in my strategy.

I do not want to do this tick by tick, since I want it to enter immediately when the conditions are met and not wait until the next candle.

How can I do this?

It would be very nice to have a flag in the "ApplyStop" function that would specify whether you are opening a long, opening a short, or closing an active position.

Thank you.

For channel breakout strategies, etc, it works really well to simply place a stop-buy at your breakout level, for instance. Is there a way to use ApplyStop to open positions?

Well, I answered my own question, it was pretty obvious.

But, if anyone else has the same issue, use the BuyPrice, SellPrice, ShortPrice and CoverPrice commands to set the entry price to wherever the stop-limit order should be if trade conditions are met, and also might need to use-


Example to have a stop-limit buy order at the previous candle's high price (backtest settings to trade NEXT BAR ON OPEN):

buycondition = H>Ref(H,-1);
Buy = Cover = buycondition;

SetOption("PriceBoundChecking",False); //disables checking and adjusting buyprice/sellprice/coverprice/shortprice arrays to current symbol High-Low range. 
BuyPrice  = CoverPrice = IIf(buycondition,Ref(H,-2),O);   //must set buy price to high 2 ticks ago since I am trading on next-bar open