Global Variables in PI-TradeScript


Is there a way I can setup a variable in Buy script and use it in Exit script?
Something like this:
Buy Script

Sell Script

Top > Global #here I use the variable that I created in Buy script.
AND … (other conditions)

(All am looking to do is to make sure am not exiting in loss because the sell script has triggered)

@nithin can you help please?

@siva @AlgoGeek + +

Hello, any luck with this query please?

It is not possible to define condition on buy script and use it on exit or sell script as there is no such option available on tradescript and also pi takes buy and sell codes individually while backtesting,

Hi @AlgoGeek, thank you.
I suppose I can use fixed value comparisons instead?
for example Top (my variable) < 3000?

I want some help regarding the AFL script. I have a pine script from that I want to code for amibroker. I can not backtest for longer period in tradingview so want to test in amibroker for backtest. Its volatility based indicator if You can help it will be great.
I attached the pine code.
Thank You.

length = Param( "Length", 20 , 1 , 100 , 1 );
src = ParamField("PriceFlied",3);
factor = Param("vStop Multiplier", 0.25 , 0.25 , 20 , 0.25 );

volStop(src, atrlen, atrfactor) =>
    var max     = src;
    var min     = src;
    var uptrend = True;
    var stop    = 0.0;
    atrM        = nz(atr(atrlen) * atrfactor, tr);
    max         := max(max, src);
    min         := min(min, src);
    stop        := nz(uptrend ? max(stop, max - atrM) : min(stop, min + atrM), src);
    uptrend     := src - stop >= 0.0;
    IIf uptrend != nz(uptrend[1], true);
        max    := src;
        min    := src;
        stop   := uptrend ? max - atrM : min + atrM;
    [stop, uptrend];

[vStop, uptrend] = volStop(src, length, factor);


strategy.entry(id="long", long = true, when = crossover(close, vStop) and window())

strategy.close("long", when = crossunder(close, vStop))

plot(vStop,"Vstop",, linewidth=2)