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

Market position not showing as flat even though no orders have been placed

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

    Market position not showing as flat even though no orders have been placed

    Hello,

    I am debugging my strategy and I am noticing an issue which I do not know how to resolve...I can't make any sense of it so can you help? This is in the Playback mode.

    I have created a simple MA cross over strategy to demonstrate the issue I'm experiencing. In the example, when the 9ema crosses above the 21ema I want to place a market order to go long however the order is not placed because the strategy thinks that my current market position is not flat and as I've set my strategy up to wait until flat the order does not get placed.

    To help me debug the logic, I added a white dot when the current market position is flat and a red dot when the current market position is not flat. The image below shows the last crossover on the right hand side (with the green background) with no order being placed. It also shows a red dot against each bar demonstrating that the current market position is not flat therefore the order is not placed.

    Click image for larger version  Name:	NQ 09-21 (1 Minute) 2021_07_01 (14_20_09).png Views:	0 Size:	122.8 KB ID:	1170813

    If I add a profit target and stop loss (16 ticks for both) in the 'stops and targets' window of the Strategy Builder then the current market position changes to flat as shown by the white dots, albeit it still shows as not being flat for the 3No. crossovers on the left hand side of the image below where the red dots are indicated. In this instance the order is placed as expected.

    Click image for larger version  Name:	NQ 09-21 (1 Minute) 2021_07_01 (14_26_38).png Views:	0 Size:	126.0 KB ID:	1170814

    This behaviour is odd, because if I widen my profit target and stop loss in the 'stops and targets' window of the Strategy Builder to a value greater than the highest or lowest price between the current crossover and the previous crossover then the strategy considers the current market position to not be flat and therefore no order is placed.

    Click image for larger version  Name:	NQ 09-21 (1 Minute) 2021_07_01 (14_39_27).png Views:	0 Size:	123.3 KB ID:	1170815

    My view is that it seems as though the exit conditions (profit target & stop loss) from the previous crossover are influencing the ability to place a trade on the current crossover, even if the order wasn't placed. It is as though the strategy is being applied to earlier data and not just starting from the time when the strategy is enabled.

    I've attached the exported strategy, would you please be able to take a look and let me know how I can resolve this issue?

    Many thanks,

    Neil

    Last edited by burtoninlondon; 09-11-2021, 08:12 AM.

    #2
    Hello Neil,

    The file you have attached is an assembly and is not open source so we cannot see the code.

    To debug the logic, use Print().

    Print the time of the bar, and the Position.MarketPosition to the output window in OnBarUpdate() where the condition is, along with any other values used in the condition. Print the order object in OnOrderUpdate() to see when orders are being filled. Print the marketPosition from OnPositionUpdate() to see the new position at the time the position changes.

    Below is a link to a forum post that demonstrates using prints to understand behavior.


    One note, it takes time after an order is submitted for a position to change.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    1 response
    17 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by benmarkal, Yesterday, 12:52 PM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by helpwanted, Today, 03:06 AM
    1 response
    19 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Working...
    X