• 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

change opacity by time

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

    change opacity by time

    Hello,

    Why is this not working?



    periodStartDate = DateTime.Parse("00:01", System.Globalization.CultureInfo.InvariantCulture) ;
    periodEndDate = DateTime.Parse("09:00", System.Globalization.CultureInfo.InvariantCulture) ;

    DateTime refDate = Time[0];

    Brush newBrushHigh = SpHighColor.Clone();
    newBrushHigh.Opacity = refDate > periodEndDate ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;

    Brush newBrushLow = SpLowColor.Clone();
    newBrushLow.Opacity = refDate > periodEndDate ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;

    i need logic

    If the current time refDate is longer > than the end time periodEndDate
    = true,
    InstrumenPrevDaytBrushOpacity
    = false, InstrumentBrushOpacity
    Last edited by memonolog; 05-29-2020, 02:47 AM.

    #2
    Hello memonolog,

    Without printing the information it would be hard to say what specifically is happening, have you tried using Prints to see what the values you are using are?

    You could try something like the following to better understand how the script is executing this code:

    Print(refDate + " " + periodEndDate + " " + InstrumenPrevDaytBrushOpacity + " " + InstrumentBrushOpacity);
    newBrushHigh.Opacity = refDate > periodEndDate ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;

    This would give a better idea of what actual values are being used so you could change the conditions or values if needed.

    If you otherwise use the Strategy Builder to generate the time conditions that may be easier. It creates conditions like the following:

    Code:
    if (Times[0][0].TimeOfDay > new TimeSpan(9, 0, 0))
    {
    }
    You can generate this in the builder by creating a condition:
    Left: Time -> Time Series
    Center: Greater
    Right: Time -> Time value



    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello memonolog,

      Without printing the information it would be hard to say what specifically is happening, have you tried using Prints to see what the values you are using are?

      You could try something like the following to better understand how the script is executing this code:

      Print(refDate + " " + periodEndDate + " " + InstrumenPrevDaytBrushOpacity + " " + InstrumentBrushOpacity);
      newBrushHigh.Opacity = refDate > periodEndDate ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;

      This would give a better idea of what actual values are being used so you could change the conditions or values if needed.

      If you otherwise use the Strategy Builder to generate the time conditions that may be easier. It creates conditions like the following:

      Code:
      if (Times[0][0].TimeOfDay > new TimeSpan(9, 0, 0))
      {
      }
      You can generate this in the builder by creating a condition:
      Left: Time -> Time Series
      Center: Greater
      Right: Time -> Time value



      I look forward to being of further assistance.
      everything seems to be correct, but transparency does not change

      5/29/2020 4:26:00 PM refDate 5/29/2020 4:30:00 PM periodEndDate 0.3 InstrumenPrevDaytBrushOpacity 1 InstrumentBrushOpacity
      5/29/2020 4:27:00 PM refDate 5/29/2020 4:30:00 PM periodEndDate 0.3 InstrumenPrevDaytBrushOpacity 1 InstrumentBrushOpacity
      5/29/2020 4:28:00 PM refDate 5/29/2020 4:30:00 PM periodEndDate 0.3 InstrumenPrevDaytBrushOpacity 1 InstrumentBrushOpacity
      5/29/2020 4:29:00 PM refDate 5/29/2020 4:30:00 PM periodEndDate 0.3 InstrumenPrevDaytBrushOpacity 1 InstrumentBrushOpacity
      5/29/2020 4:30:00 PM refDate 5/29/2020 4:30:00 PM periodEndDate 0.3 InstrumenPrevDaytBrushOpacity 1 InstrumentBrushOpacity
      Last edited by memonolog; 05-29-2020, 07:46 AM.

      Comment


        #4
        Hello memonolog,

        Does the opacity get set correctly if you do not use any conditions and just draw whatever it is this controls? Can you test that overall you can set the opacity?

        One item I don't see is freezing the brush, do you have that logic anywhere later in the script before drawing?

        newBrushHigh.Freeze();

        https://ninjatrader.com/support/help...ightsub=freeze
        JesseNinjaTrader Customer Service

        Comment


          #5
          Does the opacity get set correctly if you do not use any conditions and just draw whatever it is this controls? Can you test that overall you can set the opacity?
          Yes everything works fine without condition

          One item I don't see is freezing the brush, do you have that logic anywhere later in the script before drawing?
          this was not, just added but nothing has changed. Does not work

          Comment


            #6
            here is a piece of code


            Code:
                           Brush newBrushHigh = SpHighColor.Clone();
                            newBrushHigh.Opacity = refDate > periodEndDate ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;
            
                            Brush newBrushLow = SpLowColor.Clone();
                            newBrushLow.Opacity = refDate > periodEndDate ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;
            
            
                            Print(refDate + "  refDate  " + periodEndDate + "  periodEndDate " + InstrumenPrevDaytBrushOpacity + "                                                                 InstrumenPrevDaytBrushOpacity " + InstrumentBrushOpacity + "  InstrumentBrushOpacity ");
                            newBrushHigh.Opacity = refDate > periodEndDate ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;
            
                                       if (Condition1)
                                        {
            
                                            newBrushHigh.Freeze();
            
                                            DateTime oldPriceTime = Time[0]; // Start Time Condition
            
                                            Draw.Line(this, "Test" + Price1, false, oldPriceTime, Price1, periodEndDate, highestHigh, newBrushHigh, SetStyleBrokeLine, SetWidthBrokeLine);
            
                                        }

            I’ve created a line for verification, it changes transparency in the last few days, everything works.

            Code:
            Time[0].Day != DateTime.Now.Day ? InstrumenPrevDaytBrushOpacity : InstrumentBrushOpacity;

            But the time does not work, I do not understand why?
            Last edited by memonolog; 05-29-2020, 08:14 AM.

            Comment


              #7
              Hello memonolog,

              If you can set the opacity without the condition we can confirm this is somehow related to that condition.

              You can try to further debug the condition you made however I provided a sample of how we suggest to compare times in post #2, have you tried that? I would likely suggest to just make this time condition using the strategy builder and then click View Code to copy/paste what gets generated. That is the easiest way to form time conditions and have the times generated correctly.

              After doing that you could recreate the variables you have as TimeSpans to hold the times similar to what gets made with the builder. Alternatively you can also generate user inputs and use those in the builder, it has Time inputs as an option.

              I look forward to being of further assistance.




              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rafaelabe1977, Today, 03:51 AM
              1 response
              8 views
              0 likes
              Last Post sledge
              by sledge
               
              Started by jenifeery79, Today, 05:03 AM
              0 responses
              4 views
              0 likes
              Last Post jenifeery79  
              Started by rexmie888, Today, 04:00 AM
              0 responses
              6 views
              0 likes
              Last Post rexmie888  
              Started by terminatorT1000, Yesterday, 06:40 PM
              1 response
              16 views
              0 likes
              Last Post NT-Roland  
              Started by cmarkb, Today, 02:15 AM
              4 responses
              16 views
              0 likes
              Last Post cmarkb
              by cmarkb
               
              Working...
              X