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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    56 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    143 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    276 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X