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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    47 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    15 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    21 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X