Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to code a general method in your script

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

    How to code a general method in your script

    Hi Ninjas,

    The purpose of this thread is very simple and general. I'm trying to create a method to have within a certain Strategy script. My method could be something like this:

    #region Variables
    private int x = 1; // counter
    #endregion

    public bool core ( int x )
    {
    if (x==1)
    {
    if (Any comparison )
    {
    return true;
    }
    return false;
    }
    }

    Something is wrong cause any time I try to compile, it gives me an error message like:

    " Not every code path gives a value "

    - Could you tell what is my mistake ?
    - Where must I declare this method ? I couldn't find good enough info in help

    Thanks

    #2
    Hi Pstrusi,

    Thank you for your post.

    The error indicates that the method is not returning a value outside of any conditions otherwise the method would not return anything.

    I tested out on my end and changed the bracket after the return false; to above the line.

    Code:
    #region Variables
    private int x = 1; // counter
    #endregion
    
    public bool core ( int x )
    {
         if (x==1)
         {
             if (Any comparison )
             {
                  return true;
              }
         }
    return false;
    }
    After this change I compiled and no longer received the error.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank u Cal, it works, then I'm getting into developing all methods

      Regards
      Last edited by pstrusi; 09-11-2013, 11:19 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      157 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      91 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      143 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X