dascore Posted April 9, 2019 Report Share Posted April 9, 2019 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. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted April 9, 2019 Report Share Posted April 9, 2019 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: 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; } highlowsma.PBExport Quote Link to comment Share on other sites More sharing options...
dascore Posted April 13, 2019 Author Report Share Posted April 13, 2019 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? Thanks again for the help you are providing. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted April 13, 2019 Report Share Posted April 13, 2019 Currently - no cannot thicken it. Will see. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.