# Hi-Lo Plot and scan

## Recommended Posts

Hi friends,

Having read Yuri Shramenko's X Factor Day trading course,  I am interested  to code the following  as a single  paintbar ( indicator)  to display the following three conditions combined into one single line plot.

• If the closing price of the current bar is above a 8-period simple moving-average of the high, display an 8-prd moving-average of the low

• If the closing price of the current bar is below a 8-period simple moving-average of the low, display an 8-prd moving-average of the high

• If the closing price of the current bar is between the high and low moving averages, continue to display the current plot

Programming is NOT my forte, and may I request some kind soul to help me out? Here is the code that is found in metastock format:

The formula:
prd:=8;
HLd:=If(CLOSE>Ref(Mov(HIGH,prd,SIMPLE), -1), 1, If(CLOSE<Ref(Mov(LOW,prd,SIMPLE),-1), -1, 0));
HLv:=ValueWhen(1,HLd<>0,HLd);
If(HLv=-1, Mov(HIGH,prd,SIMPLE), Mov(LOW,prd,SIMPLE))

Thank you.

##### Share on other sites

This has to be done with an Advanced paintbar. I will post the code of it here, and also attach the .pbexport file. Take the file, save it somewhere, go to the Scan/Paintbar Manager and import it.

1. Define SMAHigh to be an SMA of period 8 based on High.

2. Defne SMALow to be an SMA of period 8 based on Low.

3. Code of paintbar:

```.fctbNone{ color:#000000; }
.fctbStyle5{ color:#0000ff; }
.fctbStyle6{ color:#808080; }
.fctbStyle2{ color:#008000; }
.fctbStyle4{ color:#000000;font-weight:bold;text-decoration:underline; }public void MainCalculation()
{
SetColor(Color.Yellow);
if (Close>SMAHigh)
{
SetYValue(SMALow);
CurrentState.DisplayingLow = true;
}
else if (Close<SMALow)
{
SetYValue(SMAHigh);
CurrentState.DisplayingLow = false;
}
else if (CurrentState.DisplayingLow)
SetYValue(SMALow);
else
SetYValue(SMAHigh);
}

/// <summary>
/// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar
/// </summary>
private void PaintbarInitialize(){}

/// <summary>
/// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc
/// </summary>
private struct PaintbarState
{
public Boolean DisplayingLow;
}

/// <summary>
/// Holds current PB state - use to calc PB, changes to it carry over to next PB calc
/// </summary>
private PaintbarState CurrentState;

/// <summary>
/// Holds saved PB state - internal
/// </summary>
private PaintbarState SavedState;

/// <summary>
/// Is called at start of paintbar calculation, should be used to clear the paintbar state
/// </summary>
private void PaintbarClearState()
{
CurrentState = new PaintbarState();
}

/// <summary>
/// Saves paintbar state (called internally).
/// </summary>
private void PaintbarSaveState()
{
SavedState = CurrentState;
}

/// <summary>
/// Restores paintbar state (called internally).
/// </summary>
private void PaintbarRestoreState()
{
CurrentState = SavedState;
}```
```
```

##### Share on other sites

Hi Mike,

Thanks for the code. Is there a way to thicken the part of the indicator joining the hi line to the lo line during the switchover process from hi to lo and lo to high to the same thickness as the hi and lo line to provide more visual clarity?

##### Share on other sites

Currently - no cannot thicken it. Will see.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.