Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade Tracking Object not working as expected

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

    Trade Tracking Object not working as expected

    Good day,

    Please could someone assist me with the following Ninjascript Strategy for (Forex markets) that I am trying to create (I am new to Ninjascript).

    The goal of the script is to test an object which I have called "TradeTracker". The object simply stores the following information regarding a trade, when an entry is provided (for the purpose of this test script, the entry and exit signal are generated by the Sample MACrossover script):

    1. EntryPrice
    2. StopLoss (if one is used)
    3. The trade type indicted by the field "Position"- this can be either flat, short or long.

    Also note that I have added two additional data series to the strategy: a minute bid and a minute ask series. These are used only for entries and exits, as I require higher granularity when back testing.
    The problem with the current script is that if the first entry signal is a long signal, the TradeTracker will only record long entries and exits for the rest of the backtest. Similarly, if the first trade is a short trade, the TradeTracker will only record short entries and exits for the rest of the backtest.

    Please could you assist me by identifying a possible error in my code. I have tried my best but I cannot seem to find the error. I have attached the compressed source file titled "TestTradeTracking".

    Sincerely,
    David
    Attached Files

    #2
    Hello DavidSpire,

    Thanks for your post.

    To understand exactly how the TradeTracker in your script is processing, you must print out the values of the TradeTracker throughout the script.

    Please add prints to the script that print out the TradeTracker values so that you could see how the logic in your script is processing and see the TradeTracker values that are being assigned. For example, outside the condition, add prints that print out tracker.TrackerPosition to see what position the tracker is in before the condition is called to update the tracker. Then, after updating the tracker, print out that value again to see if it is being updated correctly.

    Once you understand exactly how the TradeTracker logic is processing and why, you could modify the script to suit your goals.

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

    https://ninjatrader.com/support/foru...121#post791121

    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


      #3
      Thank you for your response Brandon. I will do so and will post any results that I find, on the forum.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      86 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      151 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      79 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      53 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      60 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X