Announcement

Collapse
No announcement yet.

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.

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          666 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          377 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X