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

Method not behaving correctly

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

    Method not behaving correctly

    HI

    I have a button that calls 2 methods
    DrawShortStopLine and
    DrawShortEntryLine

    the Entry line always appears but the stop Line appears at random.always the first time but thereafter sporadically.
    It gets called again on IsFirstTickOfBar where it works just fine.

    Below is the button calling the method
    Code:
    if(BuildingShortEntryLine == false)    
                        {    
                    
                        BuildingShortEntryLine = true;
                        shortTradePrice = findlow1-(TickSize*EntryAdjustTicks);//set in IsFirstTickOfBar
                        shortStopPrice =Math.Max(shortTradePrice + TickSize * 8,shortTradePrice + StopLossDistance);
    ​
                            BuildingShortStopLine = true;
                            DrawShortStopLine(shortStopPrice);
                            DrawShortEntryLine(shortTradePrice);    ​
    and here are the two methods I use to Draw LInes - as you can see apart from names they are identical

    Code:
        private void DrawShortEntryLine(double price)
        {    
                            
            TriggerCustomEvent(o =>
        {            
            if (BuildingShortEntryLine )//bool
                {
                shortEntryLine = DrawLL.LabeledHorizontalLine(this,"SELine",price,CyanBG,DashStyleHelper.Dot,3,true);
                shortEntryLine.IsLocked = false;
                }
        }, null);
            
        }
      
        
            
        private void DrawLongStopLine(double price)
        {
    
        if(BuildingLongStopLine)//bool
        {    
            TriggerCustomEvent(o =>
                {
                        {
    longStopLine = DrawLL.LabeledHorizontalLine(this,"LXLine",price,Brushes.Fuchsia,true);    
    longStopLine.IsLocked = false;
    longStopLine.IsVisible = true;
                }
            //    ForceRefresh();no effect    
            }, null);        
        }
    }​
    I have discovered in my debugging that the shortStopPrice is coming up with weird numbers but I have no idea why?
    And it also comes up with weird numbers even when the IsFirstTickOfBar calls the method but the line prints exactly where it should?

    Any pointers anyone?
    Last edited by Mindset; 02-14-2024, 03:13 AM.

    #2
    Hello Mindset,

    Thank you for your post.

    In your first snippet, you are calling the following methods:

    DrawShortStopLine(shortStopPrice);
    DrawShortEntryLine(shortTradePrice);

    In your second snippet, I see the logic for the following:
    private void DrawShortEntryLine(double price)​
    private void DrawLongStopLine(double price)

    What is your logic for DrawShortStopLine()? Do you need to rename the method DrawLongStopLine() to DrawShortStopLine() or did you happen to leave out the relevant snippet?

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Apologies Emily. I have pasted the wrong code - however the short Stop Line is identical in code to the long - just a syntax change.

      Code:
          private void DrawShortStopLine(double price)
          {
      
          if(BuildingShortStopLine)
          {
              TriggerCustomEvent(o =>
                  {
                          {
      shortStopLine = DrawLL.LabeledHorizontalLine(this,"SXLine",price,Brushes.Fuchsia,true);        
      shortStopLine.IsLocked = false;
      shortStopLine.IsVisible = true;
                  }
              }, null);        
          }
      
      
      }    
      ​

      Comment


        #4
        I realised I had confused a variable price with ShortStopPrice. Problem solved.

        Comment


          #5
          Sometimes you can look at code a thousand times and miss finding the error every time.
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          834 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,290 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          10 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          62 views
          0 likes
          Last Post halgo_boulder  
          Started by Option Whisperer, Today, 09:55 AM
          0 responses
          8 views
          0 likes
          Last Post Option Whisperer  
          Working...
          X