Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

COT Index Modification

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

    COT Index Modification

    Edit 2: SOLVED. I was able to fix my errors and mkae it so it plots NonReportable, Commercials, and Specs seperately. Sorry for the wall of text. Thanks

    EDIT: I was able to fetch the data and plot the NonReportables, though it is only plotting when I have CommercialSpeculators checked. Its plotting both at the same time rather than NonReportables by itself.

    Hello, I have been using the COT index attached to do my analysis, though wanted to add the Non reportables to this indicator as well. The NonCommercials and Commercials work perfectly but I am stumped on why i cant get the Non reportables to show up and plot. I am not sure if it's not fetching the data or plotting correctly. Mind you, I am brand new at this and trying to start off with a simple project. Below is the full code I am using and added to try and get the Nonreportables to plot. Looking for advice on how I can get this to work. Thanks.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class COTIndexCommsSpec : Indicator
    {
    private COT cot1;
    private double value1, value2;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"The COT Index Comms & Spec indicator as published in the October 2023 Technical Analysis of Stocks and Commodities article ""Backwardation, Positioning, And Momentum: A Recipe For High-Conviction Trades"" by Alfred François Tagher";
    Name = "COT Index Comms & Spec";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;

    OB = 90;
    OS = 10;
    DoComms = true;
    DoSpecs = false;
    DoRetail = false;
    Lkbk = 26;
    ExtremeClr = Brushes.Red;

    AddPlot(Brushes.Green, "COTCommIdx");
    AddPlot(Brushes.Purple, "COTSpecsIdx");
    AddPlot(Brushes.Purple, "COTNonRepIdx");

    AddLine(Brushes.DarkTurquoise, 90, "OB");
    AddLine(Brushes.DarkTurquoise, 10, "OS");
    }
    else if (State == State.DataLoaded)
    {
    Lines[0].Value = OB;
    Lines[1].Value = OS;

    cot1 = COT(2);
    cot1.CotReport1.ReportType = CotReportType.Futures;
    cot1.CotReport1.Field = CotReportField.CommercialNet;
    cot1.CotReport2.ReportType = CotReportType.Futures;
    cot1.CotReport2.Field = CotReportField.NoncommercialNet;
    cot1.CotReport3.ReportType = CotReportType.Futures;
    cot1.CotReport3.Field = CotReportField.NonreportablePositionsNet;

    }
    }

    protected override void OnBarUpdate()
    {
    // cot1.Cot1[0] is CommNet, cot1.Cot2[0] is SpecsNet

    if (DoComms)
    {
    value1 = cot1.Cot1[0] - MIN(cot1.Cot1, Lkbk)[0];
    value2 = MAX(cot1.Cot1, Lkbk)[0] - MIN(cot1.Cot1, Lkbk)[0];

    COTCommIdx[0] = (value2 != 0) ? 100.0 * (value1 / value2) : 1;

    if (COTCommIdx[0] > OB || COTCommIdx[0] < OS)
    PlotBrushes[0][0] = ExtremeClr;
    }

    if (DoSpecs)
    {
    value1 = cot1.Cot2[0] - MIN(cot1.Cot2, Lkbk)[0];
    value2 = MAX(cot1.Cot2, Lkbk)[0] - MIN(cot1.Cot2, Lkbk)[0];

    COTSpecsIdx[0] = (value2 != 0) ? 100.0 * (value1 / value2) : 1;

    if (COTSpecsIdx[0] > OB || COTSpecsIdx[0] < OS)
    PlotBrushes[1][0] = ExtremeClr;

    if (DoRetail)
    {
    value1 = cot1.Cot3[0] - MIN(cot1.Cot3, Lkbk)[0];
    value2 = MAX(cot1.Cot3, Lkbk)[0] - MIN(cot1.Cot3, Lkbk)[0];

    COTNonRepIdx[0] = (value2 != 0) ? 100.0 * (value1 / value2) : 1;

    if (COTNonRepIdx[0] > OB || COTNonRepIdx[0] < OS)
    PlotBrushes[1][0] = ExtremeClr;
    }
    }
    }
    region Properties
    [NinjaScriptProperty]
    [Display(Name="Show Comms", Order=1, GroupName="Parameters")]
    public bool DoComms
    { get; set; }

    [NinjaScriptProperty]
    [Display(Name="Show Specs", Order=2, GroupName="Parameters")]
    public bool DoSpecs
    { get; set; }

    [NinjaScriptProperty]
    [Display(Name="Show Retail", Order=3, GroupName="Parameters")]
    public bool DoRetail
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Look back period", Order=4, GroupName="Parameters")]
    public int Lkbk
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="OB", Description="Overbought", Order=5, GroupName="Parameters")]
    public int OB
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="OS", Description="Oversold", Order=6, GroupName="Parameters")]
    public int OS
    { get; set; }

    [NinjaScriptProperty]
    [XmlIgnore]
    [Display(Name="ExtremeClr", Order=7, GroupName="Parameters")]
    public Brush ExtremeClr
    { get; set; }

    [Browsable(false)]
    public string ExtremeClrSerializable
    {
    get { return Serialize.BrushToString(ExtremeClr); }
    set { ExtremeClr = Serialize.StringToBrush(value); }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> COTCommIdx
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> COTSpecsIdx
    {
    get { return Values[1]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> COTNonRepIdx
    {
    get { return Values[2]; }
    }
    #endregion

    }
    }​
    The COT Index Comms & Spec indicator as published in the October 2023 Technical Analysis of Stocks and Commodities article “Backwardation, Positioning, And Momentum: A Recipe For High-Conviction Trades” by Alfred François Tagher.
    Last edited by jordanq2; 03-06-2024, 05:34 PM.

    #2
    Hi jordanq2​,

    I am alos trying to plot the NonReportables, unfortunately its only plotting a straight line here.

    I assume there is no data fetched, could you please share you knowledge about how to fetch the right data?

    Thanks a lot,

    Greetings
    Electro

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    597 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X