Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get trades above ask and below bid?

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

    How to get trades above ask and below bid?

    How can I detect trades that occurred above ask and below bid in ninjascript? (trades that are yellow and pink in T&S)

    Following does not work:

    PHP Code:
            protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
            {
                if (marketDataUpdate.MarketDataType != MarketDataType.Last)
                    return;
                    
                // Count buys (trades above ask)
                if (marketDataUpdate.Price > marketDataUpdate.Ask)
                {
                    upCount++;
                }
                // Count sells (trades below bid)
                else if (marketDataUpdate.Price < marketDataUpdate.Bid)
                {
                    downCount++;
                }&#8203; 
    

    #2
    Hello MiCe1999,

    Thank you for your post.


    The sample on the following forum post may help you replicate the Time & Sales window behavior:



    If you have any issues with the conditions or trades, debugging may help.
    To understand why the script is behaving as it is, add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.
    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).
    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

    Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


    Please let me know if I may be of any further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    566 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    330 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    548 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X