Announcement

Collapse
No announcement yet.

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.
        https://www.screencast.com/t/Kw0K7cmU

        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 Oracletrades, Today, 09:10 PM
        0 responses
        2 views
        0 likes
        Last Post Oracletrades  
        Started by SteveAU, Today, 08:35 PM
        0 responses
        6 views
        0 likes
        Last Post SteveAU
        by SteveAU
         
        Started by Lloyd143, Today, 05:24 PM
        1 response
        20 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by Hagar, Today, 04:38 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by [email protected], Today, 04:49 PM
        0 responses
        12 views
        0 likes
        Last Post bpatel20@gmail.com  
        Working...
        X