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

limits of Print()

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

    limits of Print()

    I am still struggling with an old issue.

    I did succeed to merge my lists and somehow part of my filtering script is working.

    var list = zlist.Union(alist)
    .Union(blist)
    .Union(clist)
    .Union(dlist)
    .Union(elist)
    .Union(flist)
    .Union(glist)
    .Union(hlist)
    .Union(jlist)
    .Union(klist)
    .Union(mlist)
    .Union(nlist)
    .Union(olist)
    .Union(plist)
    .Union(qlist)
    .Union(rlist)
    .Union(slist)
    .Union(zzlist)
    .ToList();

    double minDistance = list.Min(no => Math.Abs(fibo- no));
    double closest =list.First(no => Math.Abs(fibo- no) == minDistance);
    var output = String.Join(", ", closest);


    Print(closest);

    What i cant figure out is why the Output Window returns more than one answer when it should be returning only one.

    If i do Print(minDistance) i get numbers from the first part of the script and if i do Print(closest) i get another filtering and return closest number of fibo in all the Union list.

    But even if the numbers are different in minDistance and closest in the end the OnRender still return more than one number like you can see in the attach file.

    Is it a code problem or Print() limitation or the fact that OnRender refresh every tick and throw at the same time more than one closest number from the fibo variable?
    Attached Files

    #2
    Hello frankduc, thanks for your post.

    If you are getting multiple print outs of the "closest" variable then this just means that this bit of code is being hit multiple times: Print(closest); That can be tested by making a class level int counter variable and incrementing it right after "Print(closest);" and then printing it out. This will show you how many times it is being called. If this code is in OnRender then it will be called multiple times in the runtime of the script at random. I like to use boolean flags in my code where I set up a class level bool variable called "ShouldUpdateX" then you can set that bool to true or false if the code block needs to be ran. This will depend on the specific code, of course.

    A pseudo-code example would be:

    Code:
    class MyStrategy
    {
        bool shouldUpdate = true
    
       function someEvent
        {
            if(shouldUpdate)
            {
                 //Update the variable.
                 shouldUpdate = false
    
            }
        }
    
        function someOtherEvent
        {
            if(someCondition)
            {
                shouldUpdate = true
            }
        }
    }
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I tried with the entire lists union and the result is a complete freeze of NT, i had to close down NT from task manager. There is so many print(), NT cant handle. Is there a solution ? The multiple prints weight on the system. In fact if i Print(minDistance) and Print(closest) i get 2 different set of numbers. But they dont seem in order because if i use
      if (Math.Abs(fibo - closest) < 0.01) than the last number represent the closest number from my variable fibo.
      If i apply closest number one by one to each list individually the last number in the list of multiple prints is the closest to fibo variable. That would mean i should apply

      double minDistance = list.Min(no => Math.Abs(fibo- no));
      double closest =list.First(no => Math.Abs(fibo- no) == minDistance);

      to every list one by one and than union each closest! That's ridiculous there must be a better way. What's bothering me is that i will need the variable closest to project a line in the chart to predict the market. If there's multiple results from multiple hits will the return of the code will be the last number in the list or it will flash passing every returns till the last closest in the lists? You get where i am going with this? My wish is the return of only the closest number without the multiple prints of all the lists "unioned".


      var list = zlist.Union(alist)
      .Union(blist)
      .Union(clist)
      .Union(dlist)
      .Union(elist)
      .Union(flist)
      .Union(glist)
      .Union(hlist)
      .Union(jlist)
      .Union(klist)
      .Union(mlist)
      .Union(nlist)
      .Union(olist)
      .Union(plist)
      .Union(qlist)
      .Union(rlist)
      .Union(slist)
      .Union(zzlist)
      .Union(aalist)
      .Union(bblist)
      .Union(cclist)
      .Union(ddlist)
      .Union(eelist)
      .Union(fflist)
      .Union(gglist)
      .Union(hhlist)
      .Union(jjlist)
      .Union(kklist)
      .Union(mmlist)
      .Union(nnlist)
      .Union(oolist)
      .Union(pplist)
      .Union(qqlist)
      .Union(rrlist)
      .Union(sslist)
      .ToList();

      double minDistance = list.Min(no => Math.Abs(fibo- no));
      double closest =list.First(no => Math.Abs(fibo- no) == minDistance);
      var output = String.Join(", ", closest);

      if (Math.Abs(fibo - closest) < 0.01)

      Print(closest.ToString("N4"));

      Print(closest);

      Comment


        #4
        Hello frankduc, thanks for your reply.

        I'm not sure I can suggest anything about these list unions, I do not know what it is doing or how it ties in with the rest of your code. Being able to use and manipulate data structures is a broad C# topic and we will assume you have practiced and used data structure concepts before. It's possible that debugging in Visual Studio and setting breakpoints will be better than using Prints because they are in OnRender, and Print statements will cause performance issues if used too much.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Max238, Today, 01:28 AM
        5 responses
        40 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by habeebft, Today, 07:27 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by AveryFlynn, Today, 04:57 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by r68cervera, Today, 05:29 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X