• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Appling Text to non price panel

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

    Appling Text to non price panel

    I have several questions with respect to the following screen shot:


    Click image for larger version  Name:	q2.png Views:	1 Size:	54.6 KB ID:	1052033

    Question One:

    Code Snippet:

    private SessionIterator mcSessionI;
    private DateTime sesEndTime;

    mcSessionI.GetNextSession(Time[0], true);
    sesEndTime = mcSessionI.ActualSessionEnd;

    TimeSpan span = sesEndTime.Subtract(Time[0])
    In the upper left corner of the chart, you will see a timer that I am using to count down on when the session closes. The idea is to create a timer when margin switches from day trade rate per ES contract to the margin to hold the contract over that time ($500 vs 5Kish). Its my understanding that the last executable trade in the ES is at 3:15PM central time. from 3:15 to 4PM trade activity goes on, but nothing I can execute on my side. If a trade is held past 3:15, my margin is pretty much ten times the day margin. I want to create a winding down clock to hit zero when this event occurs. The idea is to be out of the market 15 mins before this event happens - to avoid margin call. I trade multiple markets were this occurs at different times, so I would like this on each chart. I have it color coded to turn yellow at 30mins and red at 15mins. However, the time that comes from the code above is 4:00PM CST and not 3:15PM cst. Other than creating a user input variable, is there away to obtain this value programmatically?


    Question Two:

    IsOverlay = false;

    Draw.TextFixed(this, tag, xtext, TextPosition.TopLeft, xBrush, myFont, outLineBrush, areaBrush, 255);
    Draw.TextFixed(this, tag + "2", "Roll Over " + tDay, TextPosition.BottomLeft, xBrush, myFont, outLineBrush, areaBrush, 255);
    I am using the above code snippet to display the results of my code in text form. I have set the isOverlay to false because I don't want the text to appear in price action panel. How do I get it to appear in the panel below the price panel on the chart? I still want to maintain my color coding scheme, green, yellow, and red for each text block as the timers approach zero.

    #2
    Hello MarthaClines,

    Thanks for your post.

    Regarding this line: TimeSpan span = sesEndTime.Subtract(Time[0]), you might try instead: TimeSpan span = sesEndTime - Core.Globals.Now

    Another way to protect yourself would be to add a time filter so that if the time is when you want to be flat, that you simply call ExitLong() and ExitShort(), these are market orders so they get executed immediately and if no position exists then they do nothing, for example:

    if (Times[0][0].TimeOfDay >= new TimeSpan(15, 0, 0))
    {
    ExitLong();
    ExitShort();
    }

    Also, in the strategy parameters you can enable "Exit On Session Close" and set the "Exit on session close seconds" to a value that automatically meets your time needs.
    Reference:
    https://ninjatrader.com/support/help...oseseconds.htm
    https://ninjatrader.com/support/help...sestrategy.htm

    In your screenshot you are using non-time based bars and if your code runs with Calculate.OnBarClose, you may want to either change that to Calculate.OnPriceChange or Calculate.OneEachTick to ensure any time filters used will function when you expect. Alternatively, you could simply add a faster time frame such as 1-second bars to provide a barclose (to trigger OnbarUpdate) every second that you could check your timing against that known time data series.

    Regarding the DrawText(), while IsOverlay will create an indicator panel and any plots or lines in your code will be drawn in that panel, by default, all draw objects would still be drawn in the price panel. You can change this setting through DrawOnPricePanel = false; that you set in OnStateChange's SetDefaults.
    Reference:
    https://ninjatrader.com/support/help...pricepanel.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Mr Paul: I have the chart plotting the text in an indicator panel just like I want it.

      However, the session end time using
      TimeSpan span = sesEndTime - Core.Globals.Now
      is still calculating based on 4PM CST and not the needed 3:15PM cst when the margin even takes place. I am aware of the feature that can auto exit trades on market close - but that's not exactly what I want to do. I trade different I trade different markets and I want to keep track of when the margin increase occurs. For example: ES is 3:15 CST and Corn is 1:20CST. I need to make sure I don't execute trades in the first place near the end of a trading day, but I need to know when that flip occurs. mcSessionI.ActualSessionEnd from the SessionIterator isn't the value I need.

      Comment


        #4
        Hello MarthaClines,

        Thanks for your reply.

        If you want to use the session end time as the reference and you do not want to exit at the end of the session, then you would want to set the Exit on session close seconds to meet your specific needs. Using the ES example, if the session end is 4:00 PM EST and you want to actually exit at 3:00 PM CST then you would set the Exit on session close seconds to: 60 minutes times 60 seconds per minute = 3600 seconds. If you want to exit at 3:15 PM CST then 45 minutes times 60 seconds per minute = 2700 seconds.

        If you are using the default <use instrument settings> for the trading hours, then your charts will reflect the actual session closes as specified by the exchanges and the exitoncloseseconds will adjust to each session accordingly, so for example with corn and seconds set to 3600 the strategy would exit at 12:20 PM. CST.

        If this solution does not meet your needs you can use the previously advised time filter but using the end of session time minus the preferred exit time, for example:

        if (Times[0][0] >= sesEndTime.AddHours(-1))
        {
        ExitLong();
        ExitShort();
        }

        Both of these solutions are relatively the same.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Mr Paul for the reply.

          I am having a hard time conveying what I am trying to do. I am not interested in NT executing any orders. Lets say at 12noon CST I am flat and have no open positions in the market and I decide to go down the Bayou for some crawfish etouffee. I return home to my computer at 2PM cst and look at the ES 06-19 range bar chart. The countdown time that I want to see is 01:15:00 and not 02:00:00. Regardless if I decide to take a trade. I want to be able to quickly glace at a chart and know how much time I have left for the margin flip. So, if I am returning to my computer at 2PM and the margin flip happens at 3:15CST for ES, it should show 01:15:00. However, it shows 02:00:00, meaning its using 4PM instead of 3:15PM CST. My timer is 45 mins off. I am looking for the correct time value to display the calculation. What I am asking is if that exists anyplace where I can access it programmatically, or do I need to create a user defined field in my indicator so the user can input that data and calculate from that? I would prefer not to use a user defined field.

          I have another questions... is there a way to print text in the center of the panel, for example between the ES counter and Roll Over counter at the bottom of the screen in the image below. I am using Draw.TextFixed with TextPosition to place the text in the current place. However, there isn't a TextPosition.Center available

          Click image for larger version

Name:	q3.png
Views:	1
Size:	106.8 KB
ID:	1052306

          Comment


            #6
            Hello MarthaClines,

            Thanks for your reply.

            Regarding your session timer, all you need to do is to adjust the session end time as you want, for example, TimeSpan span = sesEndTime.AddMinutes(-45) - Core.Globals.Now

            If the session ends at 4:00 PM, this would adjust the time to reference 3:15 PM and provide the time remaining from there.

            Regarding the DrawTextFixed(), there is not a direct way using the method (there is no overload for bottom center). You can indirectly accomplish this by using C# escape codes in your actual text. For example, if you use "\t", this will place a tab. You would likely have to give up using either the lower left or the lower right to accomplish this or combine the text in one string that would include the \t in the center, for example: Draw.TextFixed(this, "mytext1", "CenterLocation\t\t\t\t\t\t\tRight Location", TextPosition.BottomRight); To be clear this may not be a good solution because the number of tabs depends on the chart width and if you change the chart width the text will remain in the same relationship to the other text but would not be in the center. I've attached a screenshot of what the draw text example looks like:

            Click image for larger version

Name:	marthaClines-1.PNG
Views:	1
Size:	28.6 KB
ID:	1052346

            To be sure this is a "work around" to accomplish your goal using the provided Draw.TextFixed() method.

            A better solution that would be more difficult to implement would be to use the OnRender() method to draw custom graphics with complete control. An example of this is in your NinjaTrader and is it called SampleCustomRender.

            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by uiwislth, Yesterday, 11:25 PM
            0 responses
            4 views
            0 likes
            Last Post uiwislth  
            Started by Steve L, Yesterday, 10:04 PM
            0 responses
            3 views
            0 likes
            Last Post Steve L
            by Steve L
             
            Started by marianfed, Yesterday, 09:47 PM
            0 responses
            4 views
            0 likes
            Last Post marianfed  
            Started by hir04068, Yesterday, 09:29 PM
            0 responses
            2 views
            0 likes
            Last Post hir04068  
            Started by iq200, 03-11-2018, 07:49 PM
            24 responses
            1,017 views
            0 likes
            Last Post mrlucky1x  
            Working...
            X