This ProBuilder code snippet is designed to detect scenarios where a trading order is opened and closed within the same bar, which can be crucial for analyzing trade execution and strategy performance.
if ( (not onmarket and onmarket[1]) or (tradeindex(1)=tradeindex(2) and tradeindex(1)=barindex[1] and tradeindex(1)>0) ) and lastcheck<>barindex then
lastcheck = barindex
wasonmarket=1
else
wasonmarket=0
endif
This code snippet checks specific conditions to determine if an order was both opened and closed within the same bar. Here’s a step-by-step explanation:
(not onmarket and onmarket[1]) checks if the current bar is not on the market but the previous bar was, indicating a potential quick open and close.(tradeindex(1)=tradeindex(2) and tradeindex(1)=barindex[1] and tradeindex(1)>0) checks if the trade index of the current and previous trades are the same and matches the bar index of the previous bar, which also suggests a trade opened and closed within one bar.lastcheck<>barindex ensures that this check is only performed once per bar to avoid repeated evaluations.lastcheck is updated to the current barindex, and wasonmarket is set to 1, indicating that there was a market presence in this bar.wasonmarket is set to 0, indicating no market presence in the bar.This snippet is useful for traders and analysts using automated trading systems to ensure accurate tracking and analysis of trades that open and close rapidly within a single price bar.
Check out this related content for more information:
https://www.prorealcode.com/topic/how-to-find-limit-order-has-been-executed-or-not/#post-105732
Visit Link