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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    64 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    35 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    59 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Working...
    X