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

"NinjaTrader.Indicators.CurrentDayOHL is a type but is used as a variable"

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

    "NinjaTrader.Indicators.CurrentDayOHL is a type but is used as a variable"

    Hi everyone!

    I caught an error "NinjaTrader.Indicators.CurrentDayOHL is a type but is used as a variable".


    I use this indicator CurrentDayOHL() in my code in order to find the nearest StopLoss level. For example:

    protected override void OnOrderUpdate(....) {
    .....
    if (order.IsLong) {
    SetStopLoss("", CalculationMode.Price, CurrentDayOHL().CurrentLow[1], false);
    }
    if (order.IsShort) {
    SetStopLoss("", CalculationMode.Price, CurrentDayOHL().CurrentHigh[1], false);
    }
    ....
    }

    And this code works fine when I compile it from the source. There is not an error.


    When I try to export my strategy via "Tools - Export - NinjaScript Add-On..." WITHOUT protect the code http://joxi.ru/1A5VKxLTDqzzMr - everything works fine too. Ninja just proposes me include an indicator @CurrentDayOHL.cs in NinjaScript Archive File http://joxi.ru/KAxaBopcZzvVLr. After that everything works fine.



    But when I try to protect my code using this option "Protect compiled assembly" - I get an error "NinjaTrader.Indicators.CurrentDayOHL is a type but is used as a variable"

    How should I rewrite my code to use CurrentDayOHL() indicator correctly in the case "Protect compiled assembly"?



    I tried to define a variable 'curDayOHL' like a CurrentDayOHL type:
    private CurrentDayOHL curDayOHL;

    And then use it like this:
    curDayOHL().CurrentLow[1] instead of CurrentDayOHL().CurrentLow[1] - get an error of compilation "The name 'curDayOHL' does not exist in the current context"

    Try to use like this:
    curDayOHL.CurrentLow[1] instead of CurrentDayOHL().CurrentLow[1] - compilation is successful. But I get an error during work 'Object reference not set to an instance of an object'

    Could you help me to fix this issue?
    Handlar
    NinjaTrader Ecosystem Vendor - Handlar

    #2
    Hello Handlar,

    If you do choose use a variable to store the indicator instance, the indicator must be called once the data is loaded and the instance assigned to the variable so that there is an object that exists assigned to the variable.
    Code:
    else if (State == State.DataLoaded)
    {
        curDayOHL = CurrentDayOHL();
    }
    I'll need to give exporting a script that calls this system indicator with Agile.NET applied a test.
    I will let you know what I find.
    I appreciate your patience.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea B, thank you for the answer. But it doesn't work for me again. The is the same error.

      But I've resolved this issue: I've included a part of code from source CurrentDayOHL indicator into my strategy and the code compiled successfully with protect compiled assembly.
      Handlar
      NinjaTrader Ecosystem Vendor - Handlar

      Comment


        #4
        Hello handlar,

        I appreciate your patience while we did some testing.

        NinjaTrader_AlanP has a license for Agile.NET so I had him do the testing using a test script I've created that calls the CurrentDayOHL().CurrentHigh[0] in two different ways.

        Below is a link to a video of the test.
        Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


        Attached is the open source script CurrentDayExportTest, and the exported protected version created in the video.

        Please import the open source test script. Then follow the exact steps as shown in the video.
        Do you experience different behavior than what is shown in the video?
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by samish18, 04-17-2024, 08:57 AM
        17 responses
        64 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by rocketman7, Today, 02:12 AM
        2 responses
        16 views
        0 likes
        Last Post rocketman7  
        Started by briansaul, Today, 05:31 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by PaulMohn, Today, 03:49 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by frslvr, 04-11-2024, 07:26 AM
        6 responses
        106 views
        1 like
        Last Post NinjaTrader_BrandonH  
        Working...
        X