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");
}
Output Window:
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

Comment