Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check P&L for each tick inside a Strategy executing at the close of each bar

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Check P&L for each tick inside a Strategy executing at the close of each bar

    Hi,

    (Two questions)

    1)
    I have a strategy with logic that executes at the close of each bar. It initiates ATM Orders based on certain conditions.

    This strategy also has to track current Profit&Loss (e.g. the day's Realized + Unrealized P&L) constantly - with each tick, so that the drawdown within each bar never violates certain limits. In other words, just this portion of the code needs to be executed with each tick, while the rest of the strategy executes at the end of each bar. How can this be accomplished..?

    2) A corollary...:
    - If I have a strategy that's set to execute On Each Tick, then, how can I add code to that Strategy (assume it's unlocked), that executes only at the close of a bar..?

    Thank you for your advice and assistance.

    Regards,

    RK
    Last edited by rasdaka; 10-23-2022, 06:21 PM.

    #2
    Hello RK,

    Thanks for your post.

    Yes, logic can be separated between Calculate.OnEachTick and Calculate.OnBarClose using IsFirstTickOfBar.

    Please see this reference sample which demonstrates a technique used for those who need to separate their logic to calculate some values on each tick and others only on the close of a bar. You will set your host script to Calculate.OnEachTick and use if(IsFirstTickOfBar) and place all code that needs to calculate once every bar within that condition check. Then place all code that you want to calculate OnEachTick outside of the IsFirstTickOfBar condition check.

    SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm

    Let us know if we may assist further.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X