Search code examples
pine-scriptback-testing

Fill order below/above the low/ high of the bar in pine script


Is it possible to fill an order below/above the low/high of the bar (not below/above the close)? With process_orders_on_close = true - the order is filled on close of the bar and with process_orders_on_close = false - on the next bar but I need an order to be filled n per cent below or above the low/high of the specific bar. Would be grateful for a solution. enter image description here Here an example:


Solution

  • There is only OHLC values available for backtesting, so you can do it only for realtime ticking bars (where price changing information is available) by using calc_on_every_tick parameter set to true.

    strategy(title="My example strategy", calc_on_every_tick=true)
    
    

    https://kodify.net/tradingview/strategy-settings/calculate-every-tick/

    https://www.tradingview.com/pine-script-docs/en/v4/essential/Strategies.html#backtesting-and-forwardtesting