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

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 AttiM, 02-14-2024, 05:20 PM
        11 responses
        184 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by fernandobr, Today, 09:11 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by timmbbo, Today, 08:59 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by KennyK, 05-29-2017, 02:02 AM
        2 responses
        1,281 views
        0 likes
        Last Post marcus2300  
        Started by itrader46, Today, 09:04 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X