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

loading data from a text file and updating indicator

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

    loading data from a text file and updating indicator

    I have an issue that when I load my data in a text file. The information exists and it will will load to the parameters needed for drawing.


    I have a draw button, when you click the button it calls a subroutine and it will draw on the screen.

    When I load the data i run the same subroutine during OnStartup it will not draw. I have to press the draw button to trigger the method in order for it to draw.

    The question is how do I force it to draw?

    I even tried this

    btnDraw_Click(new object(), new EventArgs());
    Update();

    and still it won't work.



    private void btnDraw_Click(object sender, EventArgs e)
    {
    if (btnDraw.Text == "Draw")
    {
    //button parameters
    btnDraw.Text = "Complete";
    btnDraw.Font = boldFont;
    btnDraw.ForeColor = Color.Black;
    btnDraw.BackColor = Color.Gray;


    DrawMyLines();

    bShowMarkerLine = false;
    RemoveDrawObject("VLine");
    RemoveDrawObject("EndLine");

    }
    else if (btnDraw.Text == "Complete")
    {
    btnDraw.Text = "Draw";
    btnDraw.Font = regularFont;
    btnDraw.ForeColor = Color.Black;
    btnDraw.BackColor = Color.Lavender;
    bShowMarkerLine = true;//
    }

    btnDraw.Enabled = true;
    bUpdate = true;
    Update();
    }
    Last edited by ballboy11; 11-15-2017, 04:02 PM.

    #2
    Hello,

    Thank you for the post.

    Out of context, it would be hard to say what may be happening, have you checked if the objects are being placed at the beginning of the chart in historical data?

    Also, Are you currently using a DateTime to place the objects or a BarsAgo? A DateTime would be required if you are using OnStartUp as the BarsAgo would not be helpful in that state. Can you confirm this for me?

    The last item which may be related is that I see you tried to call the button click handler. Did you add a print to make sure that worked? If it had not you may instead try to just contain this code in its own method. Basically the logic you have posted, but inside of its own method.

    Code:
    private void myButtonLogic()
    {
        if (btnDraw.Text == "Draw") ......\\ existing code from button event handler
    }
    
    
    private void btnDraw_Click(object sender, EventArgs e)
    {
        myButtonLogic();
    }
    
    protected override void OnStartUp()
    {
        myButtonLogic();
    }


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      -1,2017-11-15 9:26:00 AM,2017-11-15 10:59:00 AM,0,0,True

      I made a cvs and loaded my data

      int
      DateTime
      DateTime
      int
      int
      bool

      I parsed the information from my cvs AND it is working when I print out the information on the output screen

      //************************************************** ************************************************** ****
      public void parseString(string sInformation )
      {

      string[] separatingChars = { "," };
      string text = sInformation;
      string[] words = text.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);

      int nCounting = 0;

      tTime1 = Convert.ToDateTime (words[1]);
      tTime2 = Convert.ToDateTime(words[2]);
      nResTime = Convert.ToInt16(words[3]);
      nBarRange = Convert.ToInt16(words[4]);
      bReversePolarity = Convert.ToBoolean(words[5]);
      Print("Time 1 is " + tTime1);
      Print("Time 2 is " + tTime2);
      Print("nResTime is " + nResTime);
      Print("nBarRange is " +nBarRange);
      Print("bReversePolarity is " + bReversePolarity);
      }

      when I print all my data is correct and these variables are global

      i even tried this


      in onBarUpdate

      if (CurrentBar == 2)
      {

      if(bLoadedFromDatabase == true)
      {

      LoadTradingTemplate(sFileName);
      Print("In Here");
      }
      }
      Last edited by ballboy11; 11-15-2017, 04:41 PM.

      Comment


        #4
        wierd algo works live but not loaded

        SOLVED!!!

        FOR some reason Time[0] timestamp when loading is still the first bar on the loaded chart

        I had to use DateTime.Now;

        Thanks for your help
        Last edited by ballboy11; 11-15-2017, 05:37 PM.

        Comment


          #5
          Hello,

          Thank you for the reply.

          If you are using NinjaScript properties in an out of sync method like a buttons event handler, you may need to use TriggerCustomEvent to sync the NinjaScript inherited values to avoid using DateTime.Now. I would also not suggest using DateTime.Now in the platform as this has no relation to the bars times.



          you would likely need to change the method you use to have an object overload like shown in the help guide. Once you do that, you can call trigger custom event like the following:

          Code:
          private void btnDraw_Click(object sender, EventArgs e)
          {
              TriggerCustomEvent(MyCustomHandler, null);
          }
          private void MyCustomHandler(object state)
          {
              Print("Time[0] should now work: " + Time[0].ToString());			
          }
          Could you try this as well to see if this can be used instead of DateTime.Now in your use case?

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by yertle, Yesterday, 08:38 AM
          7 responses
          28 views
          0 likes
          Last Post yertle
          by yertle
           
          Started by bmartz, 03-12-2024, 06:12 AM
          2 responses
          20 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by funk10101, Today, 12:02 AM
          0 responses
          4 views
          0 likes
          Last Post funk10101  
          Started by gravdigaz6, Yesterday, 11:40 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by MarianApalaghiei, Yesterday, 10:49 PM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X