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

Null object reference order flow

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

    Null object reference order flow

    Hi, I'm trying to develop a strategy for different types of futures thinking that they are all the same.
    The problem is that when i use futures such as FDAX or FDXS the strategy works perfectly without any error, when i use other futures such ask RTY 3 22 it gives me the error Object reference not set to an instance of an object.

    Trying with the RTY 12 21 it doesn't give me any error? what could it be?
    this is the code : the bar in progress is :
    else if (State == State.Configure)
    {
    AddVolumetric(Instrument.FullName, BarsPeriodType.Tick, 1, VolumetricDeltaType.BidAsk, 1);
    }

    if ( BarsInProgress == 1)
    {

    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    double price;
    double buyVol = barsType.Volumes[CurrentBar].TotalBuyingVolume;
    double sellVol = barsType.Volumes[CurrentBar].TotalSellingVolume;
    if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Ticks) > m_tikTrailing*TickSize && firstTrail)
    {
    SetStopLoss(CalculationMode.Ticks, 0 );
    firstTrail = false;

    }


    if (Position.MarketPosition == MarketPosition.Flat)
    {


    if (m_orderSizeMin < Math.Abs(sellVol) || m_orderSizeMin < Math.Abs(buyVol))
    {

    if (buyVol - sellVol > 0 && Math.Abs(buyVol) > m_orderSizeMin)
    {
    firstTrail = true;
    m_marketHint = MyEnum.LONG;
    SetProfitTarget(CalculationMode.Ticks, m_TakeProfitMAX);
    SetStopLoss(CalculationMode.Ticks, m_StopLossMAX);

    var result2 = EnterLong();
    Print("long " + result2.ToString());

    }
    else if (buyVol - sellVol < 0 && Math.Abs(sellVol) > m_orderSizeMin)
    {
    firstTrail = true;
    m_marketHint = MyEnum.SHORT;
    SetProfitTarget(CalculationMode.Ticks, m_TakeProfitMAX);
    SetStopLoss(CalculationMode.Ticks, m_StopLossMAX);

    var result3 = EnterShort();
    Print("short " + result3.ToString());

    }
    }

    m_marketHint = MyEnum.FLAT;
    }


    #2
    Hi Alessio, thanks for posting.

    Please first use Visual Studio debugging to find the exact line where the exception is occurring. When you run visual studio and attach to the NinjaTrader process it will stop at the line that caused this exception.



    I look forward to hearing of your results.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    14 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,983 views
    3 likes
    Last Post jhudas88  
    Working...
    X