Applystop with ExitAtStop = 1,Volatile = True

Why am I getting my ProfitTarget on the exit bar (too late) during backtest? I should have it on the previous bar in order to set it at the broker before market opening, i.e. the ProfitTarget is not available after today's close. What's wrong with the below settings?

SetOption("AllowSameBarExit",0);                       
SetOption( "PriceBoundChecking", 1);           
SetOption( "ActivateStopsImmediately", 0);                                                
SetTradeDelays( 1, 1, 1, 1 );      
...
Sell = Formula...;
ApplyStop( stopTypeNBar, stopModeBars,10); // N-bar stop                       
SellPrice=O; 
ProfitTarget = Ref(ATR(5),-1);                 
ApplyStop(stopTypeProfit, stopModePoint,ProfitTarget ,1,1,0 ); //ExitAtStop = 1,Volatile = True, ReentryDelay = 0 

Maybe I wasn't clear, I try to be more specific. Below is the full code of the trading system and the graphs. The problem is when I use Volatile = True I don't get the correct ProfitTarget value on Graph1 on the trading day before the exit. See line
ApplyStop(stopTypeProfit, stopModePoint,ProfitTarget ,1,1,0 ); //ExitAtStop = 1,Volatile = True

However, if I use Volatile = False Graph1 shows the correct ProfitTarget value on the trading day before the exit.
ApplyStop(stopTypeProfit, stopModePoint,ProfitTarget ,1,0,0 ); //ExitAtStop = 1,Volatile = False

What's wrong with the code if I use Volatile=True? Why doesn't it work?

SetOption("AllowSameBarExit",0);                       
SetOption( "PriceBoundChecking", 1);           
SetOption( "ActivateStopsImmediately", 0);                                                
SetTradeDelays( 1, 1, 1, 1 );                         
Buy = Cross(c,MA(C,50));
BuyPrice=O;
Sell = Cross(MA(C,50),c);;
ApplyStop( stopTypeNBar, stopModeBars,10); // N-bar stop                       
SellPrice=O; 
ProfitTarget = Ref(ATR(5),-1);                 
ApplyStop(stopTypeProfit, stopModePoint,ProfitTarget ,1,1,0 ); //ExitAtStop = 1,Volatile = True, ReentryDelay = 0 

MaxGraph=3;
Graph0= BuyPrice;
Graph0Name="BuyPrice";
Graph0Color = colorBlue;
Graph1= ProfitTarget;
Graph1Name="ProfitTarget";
Graph1Color = colorRed;
Graph2= ValueWhen(Buy,Ref(BuyPrice,1))+ ProfitTarget;
Graph2Name="BuyPrice+ProfitTarget";
Graph2Color = colorBrightGreen;
Graph2Style=styleLine; 

Hi Tomasz,

Thank you for the hint of using the debug detailed log but it doesn't show anything about why the Profittarget is triggered late on Graph1 when I change Volatile to 1. I only tells me that Exit long and the Price.

Is there anything else I could try why I don't get the correct ProfitTarget value on Graph1 on the trading day before the exit?

Without "volatile", the stop amount is sampled at the time of trade entry and held throughout the entire trade.
With "volatile", the stop amount changes every bar.
So it is not late. It is just different amount that caused different exit.

I know this but why volatile=1 shows the Profittarget on Graph1 on the day of the exit day, i.e. too late for me? While I change volatile=0 Profittarget is shown the day before the exit trade day. Run the backtest, select one trade with Profittarget, check the exit price, go to Graph1 and see when the exit price is shown.

Simply your graph formula is NOT doing the same as ApplyStop. Knowledge Base shows how to code properly: http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/

Thank you for the KB link, I have already read it and tried to translate it to my example and this is what I figured out (the AFL code above). In fact the problem is with Graph2 and the tricky part is that ProfitTarget is not a constant value like in the KB link but it is an array. In the KB example Volatile=0, which is also working for me but how do I get it work if Volatily=1?

Is there any idea where the problem is with Graph2? Is it possible to solve it in AFL without going to low level programming?