Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Divergence between multiple instruments in strategy builder

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

    Divergence between multiple instruments in strategy builder

    I am very new to this and before i throw myself into this adventure i want to make sure what i am planning to do is even possible.

    I would be looking at a way to detect divergence between 2 different trading instruments, for example gold and silver.
    Let's say i want to detect divergences over a maximum time period of 60 minutes, but it could also be less, anything within those 60 minutes is fine.

    So if silver low 1 is at 2:30 and silver low 2 is at 3:29, that's fine, but if silver low 1 is at 2:30 and silver low 2 is at 2:35 that's also fine, then if gold doesn't make a low 2 while silver did, that would be a divergence that i want to implement in strategy builder.

    I will attach a screenshot as an example of what i mean


    In this screenshot you can clearly see the top instrument is making new highs, while the second instrument is.

    .Click image for larger version

Name:	Screenshot_28.jpg
Views:	334
Size:	11.9 KB
ID:	1232483

    #2
    Hello FTDK1,

    Thanks for your post.

    "..if gold doesn't make a low 2 while silver did, that would be a divergence that i want to implement in strategy builder."

    When you mention low 2, are you referring to the Low price 2 bars prior to the currently forming bar?

    I would be possible to compare the Low price of 1 instrument to the Low price of a different instrument.

    Say the primary series that the script will be enabled on is the SI 03-23 instrument. You could add an additional data series to the strategy, such as GC 02-23, in the Additional Data screen of the Strategy Builder. Price values, such as Low, could be compared between the two instruments on the Conditions and Actions screen of the Strategy Builder.

    To reference the Low price of the primary series (SI 03-23) in the Condition Builder, open the Price folder > Low. If you want to refer to the Low price 2 bars prior to the current bar, you would set a value of 2 in the Low price 'Bars ago' field.

    To reference the Low price of the secondary added series (GC 02-23) in the Condition Builder, open the Price folder > Low > click in the 'Series 1' field >open the Data Series folder > select 'Low of <added instrument>'. If you want to refer to the Low price 2 bars prior to the current bar, you would set a value of 2 in the Low price 'Bars ago' field.

    You could then offset each value by a certain number of ticks to check if say the Low price of SI 03-23 is less than the Low price of GC 02-23 + 10 Ticks.

    Time Filters could be used to check if the time is between a certain timeframe.

    See the help guide documentation below for more information.

    Additional Data Screen: https://ninjatrader.com/support/help...standingTheAdd itrionalDataScreen
    Price Comparison Conditions: https://ninjatrader.com/support/help..._builder.htm#H owToMakePriceDataComparisons
    Offset a Value: https://ninjatrader.com/support/help..._builder.htm#H owToOffsetAnItemValue
    Time Filter: https://ninjatrader.com/support/help...ateTimeFilters
    Actions: https://ninjatrader.com/support/help...t8/actions.htm

    Here is a link to our publicly available training video, 'Strategy Builder 301', which you might find to be helpful.

    Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE&t=13s

    Please let me know if I 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
      Hello Brandon,

      Thanks for your reply.

      I am not necessary looking for a divergence X amount of candles back, i would prefer to have a way to look a certain amount of time back, in my case probably 60 minutes, so on the one minute timeframe it would be 60 bars.

      However i do not only want to compare bar 60 to the latest bar, but i want to look for divergence in between those as well. So basically i want to look for divergences anywhere between bar 60 and the current bar. But not only for the lowest low in those 60 minutes or bars, but also for other lows.

      I will add another screenshot as an example.

      In this screenshot you can see 2 divergencies, the blue line and the green line. As you can see the green one occurred in a much shorter timeperiode than the blue one, so i don't want to look 5 or 10 bars back, i want to look a maximum of 60 bars back and detect all divergencies within those 60 bars.

      As you can also see the green divergency didn't happen with the highest high within this time period, but rather the top instrument did make a new high compared to the second instrument that at the same time did not make a new high in the same time period.

      Click image for larger version

Name:	Screenshot_29.jpg
Views:	322
Size:	55.6 KB
ID:	1232628

      Comment


        #4
        Hello FTDK1,

        Thanks for your note.

        You could use a Time comparison or Time Filter in your script to limit a when condition/action in your script occurs.

        Creating Time Conditions: https://ninjatrader.com/support/help...imeComparisons

        Creating Time Filters: https://ninjatrader.com/support/help...ateTimeFilters

        Calculating the Highest High and Lowest Low value for a specified time range would require manually programming logic in an unlocked script.

        See this reference sample demonstrating how to calculate the Highest High and Lowest Low value for a specified time range in an unlocked script: https://ninjatrader.com/support/help...est_high_o.htm

        Note that it would ultimately be up to you to come up with the exact logic to accomplish your specific goals.

        Please let me know if I 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


          #5
          I have made a work around with the strategy builder but now i am running into a new issue for which i can't find a quick solution.

          When my conditions are met i am playing a sound, however since i calculate the strategy on each tick the sound also keeps playing until the bar is closed.
          Is there an easy solution to make the sound only place once per bar?

          Comment


            #6
            Hello FTDK1,

            Thanks for your note.

            If you are running the strategy with Calculate.OnEachTick, the condition to play the sound could become true multiple times within a bar so this could occur.

            A bool could be used to control when an action occurs. For example, you could consider creating a bool variable (initially set to false). Create your condition to call PlaySound and include a check in the condition to see if the bool is false, call your PlaySound action and flip the bool to true within that Set. This way the PlaySound method will only trigger when the bool is false.

            Note that you would need to come up with a condition to flip the bool back to false, otherwise it would remain true.

            Another thing you could consider is unlocking the script and programming the strategy to calculate some logic OnEachTick and other logic OnBarClose. This would not be possible to do using the Strategy Builder.

            Here is a reference sample from the help guide demonstrating how this would be done:
            SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm

            Please let me know if I 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

            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