Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Region Color Changing

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

    Region Color Changing


    Hello.

    I am having some difficulties with Draw.Region. Attached is an image containing three lines. The three lines are plotting correctly. When the Close is above the green line (upper) I want the region to be green, when its below the red line, I want it red and when its in between, yellow. It seems to be plotting yellow for the whole thing - see image.

    This is the line of code that is supposed to be changing the color:



    MarketState = 0;

    if (Close[0] > Upper[0]) MarketState = 1;
    if (Close[0] < Lower[0]) MarketState = -1;


    if (MarketState == 0)
    {
    Draw.Region(this, "pbn", CurrentBar, 0, Upper, Lower, null, _neutColor, neutOpacity, 0);
    Print("MarketState: " + MarketState.ToString() + " Neutral");
    }

    if (MarketState == 1)
    {
    Draw.Region(this, "pbu", CurrentBar, 0, Upper, Lower, null, _upColor, upOpacity, 0);
    Print("MarketState: " + MarketState.ToString() + " Up");
    }

    if (MarketState == -1)
    {
    Draw.Region(this, "pbd", CurrentBar, 0, Upper, Lower, null, _dnColor, dnOpacity, 0);
    Print("MarketState: " + MarketState.ToString() + " Down");
    }
    The Print statements seem to have the correct values as well, the region color isn't correct though

    Output Window:

    MarketState: 0 Neutral
    MarketState: 1 Up
    MarketState: 1 Up
    MarketState: 1 Up
    MarketState: 1 Up
    MarketState: 1 Up
    MarketState: 0 Neutral
    MarketState: 0 Neutral
    MarketState: 0 Neutral
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: 0 Neutral
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: 0 Neutral
    MarketState: 0 Neutral
    MarketState: 0 Neutral
    MarketState: 1 Up
    MarketState: 0 Neutral
    MarketState: -1 Down
    MarketState: -1 Down
    MarketState: -1 Down
    Click image for larger version

Name:	jelBand.png
Views:	563
Size:	418.1 KB
ID:	1130938


    #2
    the issue is when the the state changes you have to start at that current bar. You are using 0 to Currentbar. All your regions are 0 to Current bar. You can use "pbn"+Currentbar.ToString() for a unique valuein your tag. Use the same tag until the MarketStateChanges.
    Secondly use StartTime and EndTime. Record your StartTime as a global parameter and your EndTime will Always be Time[0]

    Comment


      #3
      Originally posted by ballboy11 View Post
      the issue is when the the state changes you have to start at that current bar. You are using 0 to Currentbar. All your regions are 0 to Current bar. You can use "pbn"+Currentbar.ToString() for a unique valuein your tag. Use the same tag until the MarketStateChanges.
      Secondly use StartTime and EndTime. Record your StartTime as a global parameter and your EndTime will Always be Time[0]
      Thanks for the input. I have modified that section of code as follows:

      prevMS = MarketState;

      MarketState = 0;

      if (Close[0] > Upper[0]) MarketState = 1;
      if (Close[0] < Lower[0]) MarketState = -1;

      if (MarketState != prevMS)
      {
      myTag = "paPressureBand_" + CurrentBar.ToString();
      Print(myTag.ToString());
      sBar = CurrentBar;
      sTime = Time[0];
      }


      if (MarketState == 0)
      {
      //Draw.Region(this, myTag, sTime, Time[0], Upper, Lower, null, _neutColor, neutOpacity, 0);
      //Draw.Region(this, myTag, sTime, Time[0], Upper, Lower, null, _neutColor, neutOpacity);
      Draw.Region(this, myTag, sBar, CurrentBar, Upper, Lower, null, _neutColor, neutOpacity);
      Print("MarketState: " + MarketState.ToString() + " Neutral" +" sBar: " + sBar.ToString() + " CurrentBar: " + CurrentBar.ToString());
      }

      if (MarketState == 1)
      {
      //Draw.Region(this, myTag, sTime, Time[0], Upper, Lower, null, _upColor, upOpacity);
      Draw.Region(this, myTag, sBar, CurrentBar, Upper, Lower, null, _upColor, upOpacity);
      Print("MarketState: " + MarketState.ToString() + " Up" +" sBar: " + sBar.ToString() + " CurrentBar: " + CurrentBar.ToString());
      }

      if (MarketState == -1)
      {
      //Draw.Region(this, myTag, sTime, Time[0], Upper, Lower, null, _dnColor, dnOpacity);
      Draw.Region(this, myTag, sBar, CurrentBar, Upper, Lower, null, _dnColor, dnOpacity);
      Print("MarketState: " + MarketState.ToString() + " Down" +" sBar: " + sBar.ToString() + " CurrentBar: " + CurrentBar.ToString());
      }
      values of the print statements appears correct as follows:

      paPressureBand_12081
      MarketState: -1 Down sBar: 12081 CurrentBar: 12081
      MarketState: -1 Down sBar: 12081 CurrentBar: 12082
      MarketState: -1 Down sBar: 12081 CurrentBar: 12083
      paPressureBand_12084
      MarketState: 0 Neutral sBar: 12084 CurrentBar: 12084
      MarketState: 0 Neutral sBar: 12084 CurrentBar: 12085
      paPressureBand_12086
      MarketState: 1 Up sBar: 12086 CurrentBar: 12086
      MarketState: 1 Up sBar: 12086 CurrentBar: 12087
      paPressureBand_12088
      MarketState: 0 Neutral sBar: 12088 CurrentBar: 12088
      MarketState: 0 Neutral sBar: 12088 CurrentBar: 12089
      paPressureBand_12090
      MarketState: 1 Up sBar: 12090 CurrentBar: 12090
      MarketState: 1 Up sBar: 12090 CurrentBar: 12091
      paPressureBand_12092
      MarketState: 0 Neutral sBar: 12092 CurrentBar: 12092
      paPressureBand_12093
      MarketState: 1 Up sBar: 12093 CurrentBar: 12093
      MarketState: 1 Up sBar: 12093 CurrentBar: 12094
      MarketState: 1 Up sBar: 12093 CurrentBar: 12095
      MarketState: 1 Up sBar: 12093 CurrentBar: 12096
      MarketState: 1 Up sBar: 12093 CurrentBar: 12097
      MarketState: 1 Up sBar: 12093 CurrentBar: 12098
      MarketState: 1 Up sBar: 12093 CurrentBar: 12099
      paPressureBand_12100
      MarketState: 0 Neutral sBar: 12100 CurrentBar: 12100
      MarketState: 0 Neutral sBar: 12100 CurrentBar: 12101
      MarketState: 0 Neutral sBar: 12100 CurrentBar: 12102
      paPressureBand_12103
      MarketState: -1 Down sBar: 12103 CurrentBar: 12103
      MarketState: -1 Down sBar: 12103 CurrentBar: 12104
      paPressureBand_12105
      MarketState: 0 Neutral sBar: 12105 CurrentBar: 12105
      MarketState: 0 Neutral sBar: 12105 CurrentBar: 12106
      paPressureBand_12107
      MarketState: 1 Up sBar: 12107 CurrentBar: 12107
      MarketState: 1 Up sBar: 12107 CurrentBar: 12108
      MarketState: 1 Up sBar: 12107 CurrentBar: 12109
      paPressureBand_12110
      MarketState: 0 Neutral sBar: 12110 CurrentBar: 12110
      MarketState: 0 Neutral sBar: 12110 CurrentBar: 12111
      paPressureBand_12112
      MarketState: -1 Down sBar: 12112 CurrentBar: 12112
      When I use sTime and Time[0] there is a gap between regions and the final bars are not shading the region. I tried using the same concept by recording the currentbar at the time of the change and painting the region from that value to the CurrentBar and its not painting a thing. The tags are different now.

      Comment


        #4
        Try start time as Time[1]

        Comment


          #5
          Originally posted by ballboy11 View Post
          Try start time as Time[1]
          bingo! That was it. Its working. THanks

          Click image for larger version

Name:	jelBand.png
Views:	507
Size:	477.0 KB
ID:	1130969

          Comment

          Latest Posts

          Collapse

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