Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

Latest Posts

Collapse

Topics Statistics Last Post
Started by geddyisodin, 04-25-2024, 05:20 AM
8 responses
58 views
0 likes
Last Post NinjaTrader_Gaby  
Started by jxs_xrj, 01-12-2020, 09:49 AM
4 responses
3,285 views
1 like
Last Post jgualdronc  
Started by Option Whisperer, Today, 09:55 AM
0 responses
5 views
0 likes
Last Post Option Whisperer  
Started by halgo_boulder, 04-20-2024, 08:44 AM
2 responses
22 views
0 likes
Last Post halgo_boulder  
Started by mishhh, 05-25-2010, 08:54 AM
19 responses
6,189 views
0 likes
Last Post rene69851  
Working...
X