Announcement

Collapse
No announcement yet.

setPriceStudy not working with this study

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • setPriceStudy not working with this study

    I created this channel break out formula with a desire to plot it over the price bars and color the bars green for up moves and red for down moves. The price bars are coloring properly and the channel seems to be correct, but it keeps showing up in a separate window despite my use of the setPriceStudy(true) in the premain() section.

    It must be simple, but I can't for the life of me figure it out.

    Thanks,

    Mon_Trader


    /* Channel Break Out Study
    Uses a X bar Highest High (HH) and X Bar Lowest Low (LL) to create channels above and below
    the market action. Buy when market breaks through the HH channel, sell when market
    action breaks down through the LL channel*/

    /* First declare global variables */
    var nBarIndex;
    var Slippage = .02;
    var MinTick = .01;
    var OnBorS = 0;


    function premain() {
    setStudyTitle("TCM - Channel B/O");
    setPriceStudy(true);
    setCursorLabelName("TCM - Channel B/O");
    setColorPriceBars(true);
    setPriceBarColor(Color.black);
    }

    function main(nInputLength) {
    if(nInputLength == null) {
    nInputLength = 20;
    }
    HHValue = HHStudy(50);
    LLValue = LLStudy(50);
    nBarIndex = getCurrentBarIndex

    if(HHValue == null) {
    setPriceBarColor(Color.fuscia); //Somethings wrong or beginning of chart, on OnBorS yet.
    return;
    }
    if(LLValue == null) {
    setPriceBarColor(Color.olive ); //Somethings wrong or beginning of chart, on OnBorS yet.
    return;
    }

    /*check close of this bar against the Channels for a getting out of existing positions*/
    /*Check for a Reversal Buy*/
    if (high() > HHValue && Strategy.isShort()) {
    /* in a Short, so reverse to Buy*/
    Strategy.doCover("Crossing Up", Strategy.MARKET, Strategy.NEXTBAR);
    Strategy.doLong("Crossing Up",Strategy.MARKET,Strategy.NEXTBAR);
    OnBorS = 1;
    }
    else {
    if (low() < LLValue && Strategy.isLong()) {
    /*Check for a Reversal Sell*/
    Strategy.doSell("Crossing Down", Strategy.MARKET, Strategy.NEXTBAR);
    Strategy.doShort("Crossing Down", Strategy.MARKET, Strategy.NEXTBAR);
    OnBorS = -1;
    }
    }

    /*Not in a long, go long*/
    if (high() > HHValue && !Strategy.isLong()) {
    Strategy.doLong("Crossing Up",Strategy.MARKET,Strategy.NEXTBAR);
    OnBorS = 1;
    }
    else {
    /* Check for a new Short*/
    if (low() < LLValue && !Strategy.isShort()) {
    Strategy.doShort("Crossing Down", Strategy.MARKET, Strategy.NEXTBAR);
    OnBorS = -1;
    }
    }

    /*Next Color the Bars Lime for when on a Buy, Red for a Sell*/
    if (OnBorS == 1) {
    setPriceBarColor(Color.lime); //On Buy Signal
    }

    if (OnBorS == -1) {
    setPriceBarColor(Color.red); //On Sell Signal
    }

    if (OnBorS == 0) {
    setPriceBarColor(Color.yellow); //Somethings wrong or beginning of chart, on OnBorS yet.
    }

    return new Array(HHValue, LLValue)
    }

    function HHStudy(nInputLength) {
    if(nInputLength == null) {
    nInputLength = 20;
    }
    var nLength = nInputLength;
    var i;
    var highesthHi= 100;

    var vValues = high(-1, -nLength);
    if(vValues == null) {
    return null;
    }
    for(i = 0; i < nLength; i++) {
    if(i == 0) {
    highestHi = vValues[i];
    }
    else {
    highestHi = Math.max(highestHi, vValues[i]);
    }
    }
    return highestHi;
    }

    function LLStudy(nInputLength) {
    if(nInputLength == null) {
    nInputLength = 20;
    }
    var nLength = nInputLength;
    var i;
    var lowestLo = 0;

    var vValues = low(-1, -nLength);
    if(vValues == null) {
    return null;
    }

    for(i = 0; i < nLength; i++) {
    if(i == 0) {
    lowestLo = vValues[i];
    }
    else {
    lowestLo = Math.min(lowestLo, vValues[i]);
    }
    }
    return lowestLo;
    }

  • #2
    Hello Mon_Trader,

    You have two small problems to correct that will get you going. First, function names are case sensitive. Capitalize the "m" in your preMain() function. The next thing you need to change in preMain() is setPriceBarColor(Color.black). That particular function can't be used in preMain(). Try changing it to setDefaultPriceBarColor(Color.black).

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("TCM - Channel B/O");
        
    setCursorLabelName("TCM - Channel B/O");
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.black);

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Thanks for the quick fix

      Thanks JasonK, the super moderator,

      Haven't programmed in Java Script before and didn't know it was so case sensitive!

      Made the changes and works perfectly.
      Thanks for getting me on track,

      Mon_Trader

      Comment

      Working...
      X