Here's the update... basically I added some code to the reset area to store the previous price change for comparison. Right before the data is returned to the chart, there's a check to see if the current number of price changes are less than the previous number, and if so turn the histogram red. Once it is higher then the previous it should revert back to blue.
PHP Code:
/********************************************************************
Copyright © eSignal, 2003
Title: Price Change Count
Version: 1.1
=====================================================================
Fix History:
1.1 - Added red color if current price change is less then previous
=====================================================================
Project Description: This displays a histogram of the number of price
changes for each bar
**********************************************************************/
function preMain () {
setPriceStudy(false);
setStudyTitle("Price Change Count");
setCursorLabelName("Price Changes", 0);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarThickness(1, 0);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
}
var vPriceChanges = 0;
var vPrevPC = 0;
var vPreviousPrice = 0.00;
function main() {
if (getCurrentBarIndex() != 0) return;
var vBarState = getBarState();
var vCurrentPrice = close();
if (vCurrentPrice == null) return;
if (vBarState == BARSTATE_NEWBAR) {
vPrevPC = vPriceChanges; // Store Previous Bar's Price Changes
vPriceChanges = 0; // reset # of Price Changes
}
if (vCurrentPrice != vPreviousPrice) vPriceChanges++; // increment if there's a price change
vPreviousPrice = vCurrentPrice;
// Color Change code
if (vPriceChanges < vPrevPC)
setBarFgColor(Color.red, 0);
return vPriceChanges;
}
Comment