Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Declaring a class in UserdefinedMethods

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

    Declaring a class in UserdefinedMethods

    Sorry if this is newbie question but:

    Im declaring a class in userdefinedmethods.cs for strategies that is this one:

    public class Candle:Strategy
    {
    //Atributos
    private double size;
    private double bodysize;
    private int direction;
    private double uppershadowsize;
    private double lowershadowsize;
    private double shadowsize;
    private double percentagebody;
    private double percentageshadow;
    //Metodos

    // Direction: Devuelve +1 la vela es Bullish, 0 si es Neutra, -1 si es Bearish
    public int Direction(int vela)
    {
    if (Open[vela]>Close[vela])
    {
    direction=-1;
    return -1;
    }
    if (Open[vela]==Close[vela])
    {
    direction=0;
    return 0;
    }
    if (Open[vela]<Close[vela])
    {
    direction=0;
    return 1;
    }
    return -99;
    }//Fin Direction
    }//Fin Candle

    When I try to access to Direction from an Strategy it will get access to it but it will always return 0, I dont understand why. I know that Open[x] and Close[x] will return 0 everytime. Here is the code for accesing the Method Direction from one strategy:


    public class AAA : Strategy
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    #endregion
    public Candle C;
    public AAA()
    {
    C=new Candle();
    }
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    Print(C.Direction(0));
    }

    #region Properties
    #endregion
    }


    Someone Could help with this? Im blocked

    Belikewater

    #2
    BelikeWater,

    The best use of the UserDefinedMethod.cs is use the Partial class and create the method in there.

    This is because you were essentially creating another strategy base that wasn't being inherited from the test script.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I want to make new classes because I will use a lot of functions for sake of organization etc..

      The class I created is this: public class Candle:Strategy {}

      Seems like I cannot read Open[x] from there I have inherited from strategy, Open[x] is a method from strategy? I should be able to read it good?

      Could you help me I didnt understand your answer, what Im missing to make it work?

      Thank you

      Belikewater

      Comment


        #4
        BelikeWater,

        You would need to inherit the Test script to the Candle.

        public class AAA : Candle

        However, this kind of programming is not support with NinjaTrader and would not be able to assist in debugging.

        Below is a provided link on inheritance -
        http://www.dotnetperls.com/inheritance
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X