Jump to content
Medved Trader Forums
Sign in to follow this  
Mike Medved

Sample scan/paintbar - price at last 15 candle's high

Recommended Posts

I just sent this to one of the clients, posting it here as an example:
 

 

/// Note that some functions are empty as is the PaintbarState - that's because they
/// are automatically put in by the Advanced paintbar generators and are just
/// placeholders if they are not needed

FIFOQueue SavedCandleHigh;

FIFOQueue CandleHigh;

/// <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

{

}

/// <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();

   SavedCandleHigh = new FIFOQueue(15);

   CandleHigh      = new FIFOQueue(15);

}

/// <summary>

/// Saves paintbar state (called internally).

/// </summary>

private void PaintbarSaveState()

{

   SavedState = CurrentState;

   CandleHigh.CopyTo(SavedCandleHigh);

}

/// <summary>

/// Restores paintbar state (called internally).

/// </summary>

private void PaintbarRestoreState()

{

   CurrentState = SavedState;

   SavedCandleHigh.CopyTo(CandleHigh);

}

public void MainCalculation()

{

  CandleHigh.Add(High);

  double high, low;

  CandleHigh.GetHighLow(out high, out low);

  //
Can instead do if (High >= high) depending on what functionality you want

  if (Close >= high)  // if current candle's close is at 15-candle high.

  {

        SetColor(SysColor.MainIndicator);

        TriggerAlert("at 15 candle high", "15 hi");

        SetScanResult(true);

  }

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×