Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PositionAccount value on disabling strategy on playback account

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

    PositionAccount value on disabling strategy on playback account

    Hello

    Found an issue with PositionAccount value on strategy termination.
    My task is to detect if there is open position when strategy is being disabled.
    My code is:
    Code:
    protected override void OnStateChange()
    {
    ......
    
    else if (State == State.Terminated)
    {
    CloseCurrentPosition();
    }
    }
    
    
    ......
    
    private void CloseCurrentPosition()
    {
    Print("CloseCurrentPosition started");
    if (!Simulation)
    {
    Print("PositionAccount="+PositionAccount.MarketPos ition.ToString());
    Print("Position=" + Position.MarketPosition.ToString());
    Step by step:
    1)Do connect to Playback Connection
    2)Open Chart, enable strategy
    3)Move playback slider. After that I see on Strategies tab values 1L in Position and Acct. position column.
    Click image for larger version

Name:	2020-11-23_12-31.png
Views:	212
Size:	73.7 KB
ID:	1128896

    4)Disable Strategy
    Click image for larger version

Name:	2020-11-23_12-33.png
Views:	190
Size:	87.4 KB
ID:	1128897

    My question is, why do I see "PositionAccount=Flat" in the output while it was 1L before disabling strategy
    Thank You.

    #2
    Hello injatrader,

    Thank you for your post.

    After testing this on our end we were unable to reproduce the behavior you are seeing.

    Please test the attached example script which uses the code snippet you provided along with printing the current strategy position and account position in OnExecutionUpdate and OnPositionUpdate. I have also attached a screenshot showing the results we received after testing the script using the Playback connection.

    In the first image, we see that we are in a short position for both the strategy position and account position. After disabling the strategy, we see in the second attached image that our prints in the Output window are updating correctly and show that both positions are short .

    Do you see the same behavior after testing the attached example script using the Playback connection?

    Thanks in advance, I look forward to your reply.
    Attached Files
    <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


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello injatrader,

      Please test the attached example script
      Where can I find attached script? I can see only 2 screenshots.

      Comment


        #4
        Hello injatrader,

        Thank you for your note.

        I had forgotten to attach the example script, please test the example script attached here.

        Please let us know if we may assist further.
        Attached Files
        <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


          #5
          Thank you
          Found out, that the issue shows up only with specific Historical Fill Configuration:

          Code:
           if (State == State.SetDefaults)
          {
          Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
          Name = "SampleMACrossoverMod";
          Fast = 10;
          Slow = 25;
          // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
          // See the Help Guide for additional information
          IsInstantiatedOnEachOptimizationIteration = false;
          
          [B]OrderFillResolution = OrderFillResolution.High;
          OrderFillResolutionType = BarsPeriodType.Minute;
          OrderFillResolutionValue = 1;[/B]
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X