Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Spread Calculation

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

    Spread Calculation

    I am looking to analyze the widening and narrowing of the Spread in two of my strategies

    I am currently calculating the Spread in each relevant tick (where tick bar object = 2)

    double Bid = GetCurrentBid(2);
    double Ask = GetCurrentAsk(2);
    double spread = Ask - Bid;

    If i wanted to do a 100 Tick SMA of the spread, what would be the code structure, right now

    I am using

    double maSpread = SMA(GetCurrentAsk(2) - GetCurrentBid(2)) ,100)[0];

    and getting the following error.

    Argument '1': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries'


    Thanks kindly in advance for any help,

    Andrew

    #2
    Hello Andrew,
    The best overload for calculating the SMA is

    SMA(dataSeries, period)

    You are using a double instead of data series.

    Please add an data series and then assign it to calculate the SMA

    In Variable
    Code:
    DataSeries spread;
    In Initialize
    Code:
    spread = new DataSeries(this);
    in OnBarUpdate
    Code:
    double Bid = GetCurrentBid();
    double Ask = GetCurrentAsk();
    spread.Set(Ask - Bid);
    double maSpread = SMA(spread ,100)[0];
    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    646 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    570 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X