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

Weekdays Charting

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

    Weekdays Charting

    Hallo,
    I have created a userdefinedmethod indicator for checking the trading Day.
    In addition I have created a second general indicator where all kind of Parameters can be set. So I can easily add the Indicator and define the parameter as I like. For example only Mo and Tu are trading Days "1100000" 1 set the trading day to true and 0 to false.

    1) Userdefinedindicator
    #region Variables
    // variables
    // User defined variables (add any user defined variables below)
    //

    private DayOfWeek WeekDay1;
    private DayOfWeek WeekDay2;
    private DayOfWeek WeekDay3;
    private DayOfWeek WeekDay4;
    private DayOfWeek WeekDay5;
    private DayOfWeek WeekDay6;
    private DayOfWeek WeekDay7;
    #endregion

    public bool IsTradingDay(DateTime barTime, string WeekDays)
    {
    // Rule 1 check for valid trade day
    //String Weekdays "MoDiMiDoFrSaSo" "1001000" Mo und Do Example
    //Weekday1 = WeekDays.Substring(1,1);
    if (WeekDays.Substring(0,1) == "Mo")
    { WeekDay1 = DayOfWeek.Monday;}
    if (WeekDays.Substring(1,1) == "Di")
    { WeekDay1 = DayOfWeek.Tuesday;}
    if (WeekDays.Substring(2,1) == "Mi")
    { WeekDay1 = DayOfWeek.Wednesday;}
    if (WeekDays.Substring(3,1) == "Do")
    { WeekDay1 = DayOfWeek.Thursday;}
    if (WeekDays.Substring(4,1) == "Fr")
    { WeekDay1 = DayOfWeek.Friday;}
    if (WeekDays.Substring(5,1) == "Sa")
    { WeekDay1 = DayOfWeek.Saturday;}
    if (WeekDays.Substring(6,1) == "So")
    { WeekDay1 = DayOfWeek.Sunday;}

    if (barTime.DayOfWeek == WeekDay1 || barTime.DayOfWeek == WeekDay2 || barTime.DayOfWeek == WeekDay3
    || barTime.DayOfWeek == WeekDay4 || barTime.DayOfWeek == WeekDay5 || barTime.DayOfWeek == WeekDay6
    || barTime.DayOfWeek == WeekDay7)
    return true;

    return false;

    2) the general indicator
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if ( sma20 == true)
    {SMA20.Set(SMA(20)[0]);}
    if ( sma50 == true)
    {SMA50.Set(SMA(50)[0]);}
    if(sma100 == true)
    {SMA100.Set(SMA(100)[0]);}
    //if (ToTime(Time[0]) >= 93000 && ToTime(Time[0]) <= 153000)
    // {//DrawVerticalLine("myTime" + CurrentBar, 0, Color.Blue);
    //BackColor = Color.LightGray;
    // }
    if (tradingDay == true)
    { Ruleset1 = IsTradingDay(Time[0], "1100000");}
    //Print(Ruleset1);
    if (IsSessionTime(Time[0], DateTime.Parse("11:30"),DateTime.Parse("16:00")) == true && Ruleset1 == true)
    {BackColor = Color.LightGray;}

    The Background of the chart should be lightGray when the conditions are met.
    Any Idea why this doesnt work?
    Thakrs

    #2
    Hello Sailor,

    You will have to simplify and debug this.

    Your bool class is declared as public. For exposing indicator values from other indicators please see this sample, which offers one implementation.


    For help with the UserDefinedMethods implementation, please see here:
    Last edited by NinjaTrader_RyanM1; 01-13-2011, 04:19 PM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello Ryan,
      Thanks for your support.
      So there is no need to define a userdefinedmethod if you can expose all kind of indicator for reuse. Right?

      Thanks
      Regards
      Lars

      Comment


        #4
        Both should work in this case, but you should first get your method working within the context of one indicator, and then try calling it from another only when you verify everything is working as you expect.

        I edited my first reply because this is a good use of userdefined methods, and you will just need to simplify to track down behavior.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Looking for the same

          Mate i am kinda loking for smthng similar. Did you finish your indicator? Could you share? i am total knob in pragramming)

          thx in advance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          8 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X