Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Active Position, nothing on Chart / Chart Trader

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

    Active Position, nothing on Chart / Chart Trader

    Hi there!
    I've been learning Ninjascript and developing my strategy for a few months now. Its been a difficult but rewarding experience.
    I'm moving into trying to develop my order management system for my strategy, so I have copied and adjusted all my order logic into one of the sample strategies so that I can get more data. As an aside, there will probably be another post from me pretty soon crying about my order management and how difficult it is. Ha.
    But for now, the issue I am having, which i believe is hindering my testing is that my strategy toolbar shows that I am in a position (4L), however, I do not see any positions on my actual Chart (with Chart Trader Open). Earlier when I was in front of my screen I saw an order be placed and I watched as the orders were populated on the chart, so I know that it is a possibility. I have seen this behavior on my main strategy as well so it is obviously something I need to figure out.
    Just to add: I have seen similar behavior when I re-activate this strategy, and it had recently entered a position before disabling, that it would then show that I was in a position, but then the strategy would be yellow. This would happen regardless of whether I put "return;" in State == State.Historical{} But this feels like a separate issue.
    Would you kindly advise on the best way for me to figure out what is going on here?
    [Edit] I am using the SampleMACrossOver strategy appended with my own order logic, in case you wanted to know.
    Attached Files
    Last edited by kanjy; 09-29-2023, 12:21 PM.

    #2
    Hello kanjy,

    What start behavior are you using the for the strategy? The image shows the account is flat so there shouldn't be anything listed in the chart trader based on that detail. The chart trader will show active positions on the Account and not specifically for your strategy.

    Comment


      #3
      Hi Jesse!
      Thanks for the quick response. The chart in question had previously shown other orders & positions placed by the strategt, which was confusing me (chart trader set to Sim101 account, same as strategy).
      The strategy start behavior is currently 'wait until flat'. Would it be better to set it to ''immediately submit'? To be clear - I would always like to be able to view positions alongside stops and targets orders on my chart because I am diving into order handling, and I need the visual cues.
      [EDIT] - I did not choose 'synchronize', because I might be manually trading the same pair eventually, and as I understand it, it is better to not choose synchronize in that instance, but I am happy to be corrected.
      Last edited by kanjy; 09-29-2023, 01:41 PM.

      Comment


        #4
        Hello kanjy,

        If you had manually traded that is likely why you are not seeing anything. The strategy still thinks its in a position but the account is not so sync is false. Sync only is true if the strategies virtual position matches the account position.

        Wait until flat is the default and should prevent the account from being out of sync because the strategy will need to close any historical virtual positions before it is flat and starts working in realtime.

        I would suggest to do the following:
        1. Disable the strategy
        2. Make sure the account is flat
        3. Keep using wait until flat
        4. Then re enable the strategy.

        It should either be in a historical position and be listed as yellow or if its flat when it enters realtime and matches the account it will start trading and become green. At that point you should be able to see any orders the strategy places with chart trader open and if a position is open the PnL display will show a value.

        If you manually trade the strategy won't know about that so it would cause issues with position information showing up. For example if the strategy entered long and then you submitted a exit long order to the account to become flat the strategy will still think its long and the chart trader wont show any information.


        Comment


          #5
          Hi Jesse,

          I am fairly confident I had not taken a manual trade on that account as this is my Sim101 account. But since I cannot be 100% sure, I will do as you say and keep using 'wait until flat' and keep assessing. On your point regarding the historical orders. I have noticed that if the strategy would've historically taken an order recently, and I activate the strategy, it will show up as a 'Position' in the positions tab. I read somewhere on the forum that the solution was to add the following:

          Code:
          else if (State == State.Historical)
          {
          return;
          }​
          I did this, but the strategy still started up in yellow showing itself to be in a position. I have uploaded screenshots of the code as well as the yellow screenshot.
          Thank you in advance

          On a very unrelated note - do i need this using declaration? using NinjaTrader.CQG.ProtoBuf;
          Ninjascript keeps adding it to my strategies, but it keeps forcing errors to be spat out.
          Attached Files

          Comment


            #6
            Hello kanjy,

            If you start the strategy and it makes positions those won't appear in the positions tab if they were virtual historical positions, only the strategies tab will show the strategy is in a position like your current image shows. If you see a position in the control center positions tab that would mean the strategy actually submitted an order once it entered realtime that entered into a position.

            To prevent historical trading you would need to add the following code into OnBarUpdate and not OnStateChange.

            Code:
            if(State == State.Historical)
            return;
            If the strategy is yellow that means it entered into a historical position but did not close that position so it is now waiting to close it before working in realtime.

            You do not need that using statement, that is not a statement that would be generated by the platforms tools. You can look at any of the existing scripts like the SampleMACrossOver for the default using statements that your script should have. We suggest having all of those default using statements so that you can use intelleprompt and also reference normal NinjaScript code like drawing objects as needed without adding any more using statements.

            Comment


              #7
              Aaaaah thanks Jesse.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              66 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              141 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              76 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              47 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              51 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X