Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:	178
Size:	73.7 KB
ID:	1128896

    4)Disable Strategy
    Click image for larger version

Name:	2020-11-23_12-33.png
Views:	151
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
    Brandon H.NinjaTrader Customer Service

    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
        Brandon H.NinjaTrader Customer Service

        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 andrewtrades, Today, 04:57 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X