Announcement

Collapse
No announcement yet.

Updating indicator in Multi Time Frame mode using getSeries()

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

  • Updating indicator in Multi Time Frame mode using getSeries()

    There have been a number of posts concerning use of getSeries and displaying an indicator from one time frame in another.

    However I wish to display a histogram type indicator using assigned values for certain events and cannot see how to build a series so that the indicator is drawn properly without having to refresh it continually.

    Any help to a solution would be welcome.

    Robert

    PHP Code:
    /*************************************************************
    Title    : Donchian Channel Histogram
    By    : Robert Cameron
    Incept    : July 27, 2013
    Version : 0.0.0
    --------------------------------------------------------------
    **************************************************************
    Release History
    **************************************************************
    July 27, 2013 - Inception & Prototype 
    0.0.0
    ==============================================================
    */

    // Used in preMain() for user selection
    var fpArray = new Array();

    // ###########################################################
    function preMain(){
    // ###########################################################
    // STUDY FIXED PARAMETERS
     
     
    setPriceStudy(false);
     
    setStudyTitle("DCH");

    // VARIABLES
     
    var x=0;

    // USER SELECTION
    //-----------------------    
        
    // Donchian
         
    fpArray[x] = new FunctionParameter("nDCLengthP"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
             
    setDefault(10); //10
         
    }

         
    fpArray[x] = new FunctionParameter("sDCTriggerP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
             
    addOption("open"); 
             
    addOption("high");
             
    addOption("low");
             
    addOption("close");
             
    addOption("hl2");
             
    addOption("hlc3");
             
    addOption("ohlc4"); 
             
    setDefault("close"); //close 
         
    }
        
        
    fpArray[x] = new FunctionParameter"sOscStyP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
             
    setName("Oscillator Style");
            
    addOption("SOLID");
            
    addOption("DASH");
            
    addOption("DOT");
            
    addOption("DASHDOT");
            
    addOption("DASHDOTDOT");
            
    setDefault"SOLID" );
        }

        
    fpArray[x] = new FunctionParameter"nOscThckP"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
             
    setName("Oscillator Thickness");
            
    setLowerLimit);
            
    setUpperLimit10 );
            
    setDefault);
        }

        
    fpArray[x] = new FunctionParameter"sOscPltP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
             
    setName("Oscillator Plot");
            
    addOption("LINE");
            
    addOption("CIRCLE");
            
    addOption("DOT");
            
    addOption("SQUARE");
            
    addOption("SQUAREWAVE");
            
    addOption("HISTOGRAM");
            
    addOption("FLATLINES");
            
    addOption("INSTANTCOLORLINE");
            
    setDefault"HISTOGRAM" );
        }

    //Symbol & Interval    
         
    fpArray[x] = new FunctionParameter("sSymbolP"FunctionParameter.STRING);
         
    with(fpArray[x++]){
             
    setDefault();
         }

         
    fpArray[x] = new FunctionParameter("sIntervalP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
             
    setDefault();
         }

    // Base Line

        
    fpArray[x] = new FunctionParameter"cBLP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
             
    setName("BL Color");
            
    setDefaultColor.yellow); //yellow
        
    }

        
    fpArray[x] = new FunctionParameter"sBLStyP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
             
    setName("BL Style");
            
    addOption("SOLID");
            
    addOption("DASH");
            
    addOption("DOT");
            
    addOption("DASHDOT");
            
    addOption("DASHDOTDOT");
            
    setDefault"SOLID" );
        }

        
    fpArray[x] = new FunctionParameter"nBLThckP"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
             
    setName("BL Thickness");
            
    setLowerLimit);
            
    setUpperLimit);
            
    setDefault);
        }

    // Oscillator Colors

        
    fpArray[x] = new FunctionParameter"cTrEStUP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
             
    setName("Up");
            
    setDefaultColor.white); //white
        
    }

        
    fpArray[x] = new FunctionParameter"cTrEStDP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
             
    setName("Dn");
            
    setDefaultColor.magenta); //magenta
        
    }
            
        
    fpArray[x] = new FunctionParameter"cTrNTP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
             
    setName("No Trend");
            
    setDefaultColor.yellow); //yellow
        
    }
        
    // Points
    // MDC
        
    fpArray[x] = new FunctionParameter"nMDC_STL"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
             
    setName("MDC Limit");
            
    setLowerLimit);
            
    setDefault0.5 ); //0.5
        
    }
        
    // ==========================================================
    }    // END PreMain Function
    // ==========================================================

    // ##########################################################
    // MAIN
    function main(
    nDCLengthPsDCTriggerPsOscStyPnOscThckPsOscPltPsSymbolPsIntervalPcBLP

    sBLStyPnBLThckPcTrEStUPcTrEStDPcTrNTPnMDC_STL
    ){
    // ##########################################################

    // ****************************************
    if ( getBarState() == BARSTATE_ALLBARS ){
    // ----------------------------------------

    /////////////////////////////////////
    // Set up Line Drawing & Cursor Info
    setDefaultBarFgColor(cTrNTP0);
    setDefaultBarStyle(eval("PS_"+sOscStyP), 0);
    setDefaultBarThickness(nOscThckP0);
    setCursorLabelName("DCH"0);
    setPlotType(eval("PLOTTYPE_"+sOscPltP), 0);

    // SYMBOL & INTERVAL
    if(sSymbolP == nullsSymbolP getSymbol();
    if(
    sIntervalP == nullsIntervalP getInterval();
    vSymbol sSymbolP+","+sIntervalP;

    // STUDIES & VARIABLES
    xMDC middleDonchian(nDCLengthP,sym(vSymbol));
    var 
    vMDCm;

    xDCSource = eval(sDCTriggerP+"('" vSymbol "')"); //usually close('ES M3,1500T')
    var vDCSrcM;

    var 
    rMDCm;
        
    // Base Line        
    addBand(0, eval("PS_"+sBLStyP), nBLThckPcBLP"Center");
        
    // ----------------------------------------
    return null;
     } 
    // END ALLBARS
    // ========================================

    ////////////////////////////////////////////
    // This will return null if no data exists for the given symbol
    if (getOldestBarIndex() == null) return;


    //////////
    // CALCULATION AREA

    vMDCm getSeries(xMDC);
    vDCSrcM getSeries(xDCSource);

    // Mid Donchian Channel vs close
    if (vDCSrcM>vMDCm){
        
    rMDCm=nMDC_STL;
    }else if (
    vDCSrcM<vMDCm){
        
    rMDCm=-nMDC_STL;
    }else{
        
    rMDCm=0;
    }

    // ****************************************
    // COLORING AREA
    // ----------------------------------------

    if (rMDCm >=nMDC_STL){
     
    setDefaultBarFgColor(cTrEStUP0);

    }else if (
    rMDCm <=nMDC_STL){
     
    setDefaultBarFgColor(cTrEStDP0);

    }else{
     
    setDefaultBarFgColor(cTrNTP0);

    }
    // ----------------------------------------
    // END COLORING AREA
    // ========================================

    // ****************************************
    // DISPLAY RESULT
    // ----------------------------------------
     
    return rMDCm;
    // ----------------------------------------
    // END DISPLAY RESULT
    // ========================================

    // ========================================================
    // END Main Processing Function
    // ======================================================== 

  • #2
    Robert
    In briefly looking over the construct of your formula it seems to me that you are not doing this the proper way.
    You should calculate your indicator in a separate function [or formula] which you call from main using efsInternal() [or efsExternal()] and the context of which you control by passing the symbol and/or interval series as the last parameter of the call. At that point you return to the chart the series created by the efsInternal() [or efsExternal()] call
    I believe I have already shown you in the past how to do this so you may want to search through your own posts and refer to those examples. As to the coloring issue this topic has been covered before so search the forums as there are already examples available that illustrate how to do this
    Alex


    Originally posted by rcamrn123 View Post
    There have been a number of posts concerning use of getSeries and displaying an indicator from one time frame in another.

    However I wish to display a histogram type indicator using assigned values for certain events and cannot see how to build a series so that the indicator is drawn properly without having to refresh it continually.

    Any help to a solution would be welcome.

    Robert

    PHP Code:
    /*************************************************************
    Title    : Donchian Channel Histogram
    By    : Robert Cameron
    Incept    : July 27, 2013
    Version : 0.0.0
    --------------------------------------------------------------
    **************************************************************
    Release History
    **************************************************************
    July 27, 2013 - Inception & Prototype 
    0.0.0
    ==============================================================
    */

    // Used in preMain() for user selection
    var fpArray = new Array();

    // ###########################################################
    function preMain(){
    // ###########################################################
    // STUDY FIXED PARAMETERS

    setPriceStudy(false);
    setStudyTitle("DCH");

    // VARIABLES
    var x=0;

    // USER SELECTION
    //-----------------------    
        
    // Donchian
        
    fpArray[x] = new FunctionParameter("nDCLengthP"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(10); //10
        
    }

        
    fpArray[x] = new FunctionParameter("sDCTriggerP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("open"); 
             
    addOption("high");
            
    addOption("low");
            
    addOption("close");
            
    addOption("hl2");
            
    addOption("hlc3");
            
    addOption("ohlc4"); 
             
    setDefault("close"); //close 
         
    }
        
        
    fpArray[x] = new FunctionParameter"sOscStyP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setName("Oscillator Style");
            
    addOption("SOLID");
            
    addOption("DASH");
            
    addOption("DOT");
            
    addOption("DASHDOT");
            
    addOption("DASHDOTDOT");
            
    setDefault"SOLID" );
        }

        
    fpArray[x] = new FunctionParameter"nOscThckP"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Oscillator Thickness");
            
    setLowerLimit);
            
    setUpperLimit10 );
            
    setDefault);
        }

        
    fpArray[x] = new FunctionParameter"sOscPltP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setName("Oscillator Plot");
            
    addOption("LINE");
            
    addOption("CIRCLE");
            
    addOption("DOT");
            
    addOption("SQUARE");
            
    addOption("SQUAREWAVE");
            
    addOption("HISTOGRAM");
            
    addOption("FLATLINES");
            
    addOption("INSTANTCOLORLINE");
            
    setDefault"HISTOGRAM" );
        }

    //Symbol & Interval    
        
    fpArray[x] = new FunctionParameter("sSymbolP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setDefault();
        }

        
    fpArray[x] = new FunctionParameter("sIntervalP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setDefault();
        }

    // Base Line

        
    fpArray[x] = new FunctionParameter"cBLP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("BL Color");
            
    setDefaultColor.yellow); //yellow
        
    }

        
    fpArray[x] = new FunctionParameter"sBLStyP"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setName("BL Style");
            
    addOption("SOLID");
            
    addOption("DASH");
            
    addOption("DOT");
            
    addOption("DASHDOT");
            
    addOption("DASHDOTDOT");
            
    setDefault"SOLID" );
        }

        
    fpArray[x] = new FunctionParameter"nBLThckP"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("BL Thickness");
            
    setLowerLimit);
            
    setUpperLimit);
            
    setDefault);
        }

    // Oscillator Colors

        
    fpArray[x] = new FunctionParameter"cTrEStUP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Up");
            
    setDefaultColor.white); //white
        
    }

        
    fpArray[x] = new FunctionParameter"cTrEStDP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Dn");
            
    setDefaultColor.magenta); //magenta
        
    }
            
        
    fpArray[x] = new FunctionParameter"cTrNTP"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("No Trend");
            
    setDefaultColor.yellow); //yellow
        
    }
        
    // Points
    // MDC
        
    fpArray[x] = new FunctionParameter"nMDC_STL"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("MDC Limit");
            
    setLowerLimit);
            
    setDefault0.5 ); //0.5
        
    }
        
    // ==========================================================
    }    // END PreMain Function
    // ==========================================================

    // ##########################################################
    // MAIN
    function main(
    nDCLengthPsDCTriggerPsOscStyPnOscThckPsOscPltPsSymbolPsIntervalPcBLP

    sBLStyPnBLThckPcTrEStUPcTrEStDPcTrNTPnMDC_STL
    ){
    // ##########################################################

    // ****************************************
    if ( getBarState() == BARSTATE_ALLBARS ){
    // ----------------------------------------

    /////////////////////////////////////
    // Set up Line Drawing & Cursor Info
    setDefaultBarFgColor(cTrNTP0);
    setDefaultBarStyle(eval("PS_"+sOscStyP), 0);
    setDefaultBarThickness(nOscThckP0);
    setCursorLabelName("DCH"0);
    setPlotType(eval("PLOTTYPE_"+sOscPltP), 0);

    // SYMBOL & INTERVAL
    if(sSymbolP == nullsSymbolP getSymbol();
    if(
    sIntervalP == nullsIntervalP getInterval();
    vSymbol sSymbolP+","+sIntervalP;

    // STUDIES & VARIABLES
    xMDC middleDonchian(nDCLengthP,sym(vSymbol));
    var 
    vMDCm;

    xDCSource = eval(sDCTriggerP+"('" vSymbol "')"); //usually close('ES M3,1500T')
    var vDCSrcM;

    var 
    rMDCm;
        
    // Base Line        
    addBand(0, eval("PS_"+sBLStyP), nBLThckPcBLP"Center");
        
    // ----------------------------------------
    return null;
    // END ALLBARS
    // ========================================

    ////////////////////////////////////////////
    // This will return null if no data exists for the given symbol
    if (getOldestBarIndex() == null) return;


    //////////
    // CALCULATION AREA

    vMDCm getSeries(xMDC);
    vDCSrcM getSeries(xDCSource);

    // Mid Donchian Channel vs close
    if (vDCSrcM>vMDCm){
        
    rMDCm=nMDC_STL;
    }else if (
    vDCSrcM<vMDCm){
        
    rMDCm=-nMDC_STL;
    }else{
        
    rMDCm=0;
    }

    // ****************************************
    // COLORING AREA
    // ----------------------------------------

    if (rMDCm >=nMDC_STL){
    setDefaultBarFgColor(cTrEStUP0);

    }else if (
    rMDCm <=nMDC_STL){
    setDefaultBarFgColor(cTrEStDP0);

    }else{
    setDefaultBarFgColor(cTrNTP0);

    }
    // ----------------------------------------
    // END COLORING AREA
    // ========================================

    // ****************************************
    // DISPLAY RESULT
    // ----------------------------------------
    return rMDCm;
    // ----------------------------------------
    // END DISPLAY RESULT
    // ========================================

    // ========================================================
    // END Main Processing Function
    // ======================================================== 

    Comment


    • #3
      I have corrected the code so that the indicator works correctly in multi time frames as per following code:-

      PHP Code:
      /*************************************************************
      Title    : Donchian Channel Histogram
      By    : Robert Cameron
      Incept    : July 26, 2013
      Version : 0.0.1
      --------------------------------------------------------------
      **************************************************************
      Release History
      **************************************************************
      July 27, 2013 - added Function for efsInternal call to allow MTF to work properly
      0.0.1

      July 26, 2013 - Inception & Prototype 
      0.0.0
      ==============================================================
      */

      // Used in preMain() for user selection
      var fpArray = new Array();

      // ###########################################################
      function preMain(){
      // ###########################################################
      // STUDY FIXED PARAMETERS
       
       
      setPriceStudy(false);
       
      setStudyTitle("DCH");

      // VARIABLES
       
      var x=0;

      // USER SELECTION
      //-----------------------    
          
      // Donchian
           
      fpArray[x] = new FunctionParameter("nDCLengthP"FunctionParameter.NUMBER);
          
      with(fpArray[x++]){
              
      setLowerLimit(1);        
               
      setDefault(10); //10
           
      }

           
      fpArray[x] = new FunctionParameter("sDCTriggerP"FunctionParameter.STRING);
          
      with(fpArray[x++]){
               
      addOption("open"); 
               
      addOption("high");
               
      addOption("low");
               
      addOption("close");
               
      addOption("hl2");
               
      addOption("hlc3");
               
      addOption("ohlc4"); 
               
      setDefault("close"); //close 
           
      }
          
          
      fpArray[x] = new FunctionParameter"sOscStyP"FunctionParameter.STRING);
          
      with(fpArray[x++]){
               
      setName("Oscillator Style");
              
      addOption("SOLID");
              
      addOption("DASH");
              
      addOption("DOT");
              
      addOption("DASHDOT");
              
      addOption("DASHDOTDOT");
              
      setDefault"SOLID" );
          }

          
      fpArray[x] = new FunctionParameter"nOscThckP"FunctionParameter.NUMBER);
          
      with(fpArray[x++]){
               
      setName("Oscillator Thickness");
              
      setLowerLimit);
              
      setUpperLimit10 );
              
      setDefault);
          }

          
      fpArray[x] = new FunctionParameter"sOscPltP"FunctionParameter.STRING);
          
      with(fpArray[x++]){
               
      setName("Oscillator Plot");
              
      addOption("LINE");
              
      addOption("CIRCLE");
              
      addOption("DOT");
              
      addOption("SQUARE");
              
      addOption("SQUAREWAVE");
              
      addOption("HISTOGRAM");
              
      addOption("FLATLINES");
              
      addOption("INSTANTCOLORLINE");
              
      setDefault"HISTOGRAM" );
          }

      //Symbol & Interval    
           
      fpArray[x] = new FunctionParameter("sSymbolP"FunctionParameter.STRING);
           
      with(fpArray[x++]){
               
      setDefault();
           }

           
      fpArray[x] = new FunctionParameter("sIntervalP"FunctionParameter.STRING);
          
      with(fpArray[x++]){
               
      setDefault();
           }

      // Base Line

          
      fpArray[x] = new FunctionParameter"cBLP"FunctionParameter.COLOR);
          
      with(fpArray[x++]){
               
      setName("BL Color");
              
      setDefaultColor.yellow); //yellow
          
      }

          
      fpArray[x] = new FunctionParameter"sBLStyP"FunctionParameter.STRING);
          
      with(fpArray[x++]){
               
      setName("BL Style");
              
      addOption("SOLID");
              
      addOption("DASH");
              
      addOption("DOT");
              
      addOption("DASHDOT");
              
      addOption("DASHDOTDOT");
              
      setDefault"SOLID" );
          }

          
      fpArray[x] = new FunctionParameter"nBLThckP"FunctionParameter.NUMBER);
          
      with(fpArray[x++]){
               
      setName("BL Thickness");
              
      setLowerLimit);
              
      setUpperLimit);
              
      setDefault);
          }

      // Oscillator Colors

          
      fpArray[x] = new FunctionParameter"cTrEStUP"FunctionParameter.COLOR);
          
      with(fpArray[x++]){
               
      setName("Up");
              
      setDefaultColor.white); //white
          
      }

          
      fpArray[x] = new FunctionParameter"cTrEStDP"FunctionParameter.COLOR);
          
      with(fpArray[x++]){
               
      setName("Dn");
              
      setDefaultColor.magenta); //magenta
          
      }
              
          
      fpArray[x] = new FunctionParameter"cTrNTP"FunctionParameter.COLOR);
          
      with(fpArray[x++]){
               
      setName("No Trend");
              
      setDefaultColor.yellow); //yellow
          
      }
          
      // Points
      // MDC
          
      fpArray[x] = new FunctionParameter"nMDC_STL"FunctionParameter.NUMBER);
          
      with(fpArray[x++]){
               
      setName("MDC Limit");
              
      setLowerLimit);
              
      setDefault0.5 ); //0.5
          
      }
          
      // ==========================================================
      }    // END PreMain Function
      // ==========================================================

      // ##########################################################
      // MAIN
      function main(
      nDCLengthPsDCTriggerPsOscStyPnOscThckPsOscPltPsSymbolPsIntervalPcBLPsBLStyPnBLThckPcTrEStUPcTrEStDPcTrNTPnMDC_STL
      ){
      // ##########################################################

      // ****************************************
      if ( getBarState() == BARSTATE_ALLBARS ){
      // ----------------------------------------

      /////////////////////////////////////
      // Set up Line Drawing & Cursor Info
      setDefaultBarFgColor(cTrNTP0);
      setDefaultBarStyle(eval("PS_"+sOscStyP), 0);
      setDefaultBarThickness(nOscThckP0);
      setCursorLabelName("DCH"0);
      setPlotType(eval("PLOTTYPE_"+sOscPltP), 0);

      // SYMBOL & INTERVAL
      if(sSymbolP == nullsSymbolP getSymbol();
      if(
      sIntervalP == nullsIntervalP getInterval();
      vSymbol sSymbolP+","+sIntervalP;

      // STUDIES & VARIABLES
      xDC_R efsInternal("fnMDC"nDCLengthPsDCTriggerPnMDC_STLcTrEStUPcTrEStDPcTrNTPsym(vSymbol));
      nDC_M getSeries(xDC_R0); //indicator - this works in multi time frame (MTF) mode
      cDC_M getSeries(xDC_R1); //color - does not work fully in MTF mode when oscillator switches
      var vDC_M;
          
      // Base Line        
      addBand(0, eval("PS_"+sBLStyP), nBLThckPcBLP"Center");
          
      // ----------------------------------------
      return null;
       } 
      // END ALLBARS
      // ========================================

      ////////////////////////////////////////////
      // This will return null if no data exists for the given symbol
      if (getOldestBarIndex() == null) return;

      // ****************************************
      // COLORING AREA
      // ----------------------------------------

      //setDefaultBarFgColor(cDC_M, 0); // does not work fully in MTF mode when oscillator switching 
      var nDCC nDC_M.getValue(0);

      if (
      nDCC >=nMDC_STL){
       
      setDefaultBarFgColor(cTrEStUP0);

      }else if (
      nDCC <=nMDC_STL){
       
      setDefaultBarFgColor(cTrEStDP0);

      }else{
       
      setDefaultBarFgColor(cTrNTP0);

      }

      // ----------------------------------------
      // END COLORING AREA
      // ========================================

      // ****************************************
      // DISPLAY RESULT
      // ----------------------------------------

      return nDC_M //this works in multi time frame

      // ----------------------------------------
      // END DISPLAY RESULT
      // ========================================

      // ========================================================
      // END Main Processing Function
      // ========================================================


      // *******************************************************************
      function fnMDC(nDCLen_FsDCTrg_FnMDC_FcTrEStU_FcTrEStD_FcTrNT_F){
      // -----------------------------------------------------------------
      var rMDCfcCol_f;

      xMDCf middleDonchian(nDCLen_F);

      xDCSf = eval(sDCTrg_F+"(" ")"); //usually close('ES M3,1500T')

      // Mid Donchian Channel vs close
      if (xDCSf>xMDCf){
          
      rMDCf=nMDC_F;
          
      cCol_f=cTrEStU_F;
      }else if (
      xDCSf<xMDCf){
          
      rMDCf=-nMDC_F;
          
      cCol_f=cTrEStD_F;
      }else{
          
      rMDCf=0;
          
      cCol_f=cTrNT_F;
      }

      return new Array (
      rMDCfcCol_f);

      // -------------------------------------------------------------------
      }    // END function fnMDC
      // ------------------------------------------------------------------- 
      The main issue now is to get the bar color's right.

      I have tried 2 different methods:-

      Assigning the color inside the efsinternal function and assigning to a series - however this does not work when the oscillator indicator switches from one level to another. You have to refresh the chart to display correctly

      The other method is within main, however the result is the same that color does not change on the first bar in lower time frame when the oscillator switches in the higher time frame.

      Any help to resolve this will be much appreciated.

      Robert

      Comment


      • #4
        To show the problem in full I have done a couple of screen shots with before and after (indicator reload). The issues are highlighted with blue boxes. as can be seen the indicator works right but not the colors in multitime frame mode (the lower time frame here is 500T whilst the higher is 1500T on ES #F)

        BEFORE:
        Click image for larger version

Name:	Before.png
Views:	1
Size:	38.5 KB
ID:	242878

        AFTER:
        Click image for larger version

Name:	After.png
Views:	1
Size:	38.4 KB
ID:	242879

        Comment


        • #5
          I have tried to replace the coloring section

          PHP Code:
          // **************************************** 
          // COLORING AREA 
          // ---------------------------------------- 

          if (rMDCm >=nMDC_STL){ 
           
          setDefaultBarFgColor(cTrEStUP0); 

          }else if (
          rMDCm <=nMDC_STL){ 
           
          setDefaultBarFgColor(cTrEStDP0); 

          }else{ 
           
          setDefaultBarFgColor(cTrNTP0); 


          // ---------------------------------------- 
          // END COLORING AREA 
          // ======================================== 
          to:-

          PHP Code:
          // ****************************************
          // COLORING AREA
          // ----------------------------------------

          if (nDC_M >=nMDC_STL_P){
           
          setBarFgColor(cTrEStU_P0);

          }else if (
          nDC_M <=nMDC_STL_P){
           
          setBarFgColor(cTrEStD_P0);

          }else{
           
          setBarFgColor(cTrNT_P0);

          }

          // ----------------------------------------
          // END COLORING AREA
          // ======================================== 
          Does not make any difference in using setBarFgColor() when plotting a higher time frame in a lower time frame chart. I also changed the value to be checked with the Series "nDC_M" instead of "rMDCm" which is a getValue() variable of the Series. I am at a loss of how to get the bar color right using standard eSignal code functions in MTF mode.

          Robert

          Comment


          • #6
            I believe I have finally cracked the issue of bar coloring from a higher time frame into a lower one which required much coding gymnastics to achieve! I just can't believe why it cannot be handled by the efs engine without resorting to multiple lines of code.

            I have had to add the following pieces of code to ensure when MTF mode is enabled that every bar color is correctly painted from the start to finish and no stray colors left stranded as was happening before in the lower timeframe chart:-

            First had to create an efsInternal() function:-
            PHP Code:
            // ***********************************************************
            var nBrSymFnG 0
            var 
            nBrCurFnG 0
            // -----------------------------------------------------------
            function fnMTFBC(Symbol_F) {
            // Controls count from higher timeframe in lower timeframe
            // ***********************************************************
                
            if (getBarStateSymbol(Symbol_F) ==  BARSTATE_NEWBAR){ 
                    
            nBrSymFnG += 1
                    
            nBrCurFnG getCurrentBarCount(); 
                } 
                return new Array(
            nBrSymFnG,nBrCurFnG); 
            // -----------------------------------------------------------
            // END function fnMTFBC()
            // ----------------------------------------------------------- 
            This was called from within the (getBarState() == BARSTATE_ALLBARS) section thus:-
            PHP Code:
            // MTF BAR COUNTS in higher & lower time frames 
            xMTFBC efsInternal("fnMTFBC"vSymbol_M); 
            xBCSym getSeries(xMTFBC0);  //Symbol Bar Count
            xBCCur getSeries(xMTFBC1); // Lower TF Bar Count 
            I had to also set up some global variables outside of main():-
            PHP Code:
            // MTF Variables
            var oMTFBC_G = new Object(); //Holds 
            var vMTFTmp1_GvMTFTmp2_GvMTFTmp3_G
            Then from main() set up the adjustment parameters from the bar series above:-
            PHP Code:
            // ****************************************
            // MTF COLOR & GRAPHICS ADJUSTMENT
            // ----------------------------------------
            // Adjustment to redraw period
                
            vMTFTmp1_G xBCSym.getValue(0); //Counts each MTF bar
                
                
            vMTFTmp3_G xBCCur.getValue(0); //Total Bar Count by Current Chart to date
                
                
            vMTFTmp2_G vMTFTmp3_G getCurrentBarCount(); 
            //counts the # of current interval bars in each MTF bar. If no MTF used then will always be zero

            // assigns chart bar index to MTF Object from MTF Bar
                
            if (getBarStateSymbol(vSymbol_M) == BARSTATE_NEWBAR){ 
                    
            oMTFBC_G[vMTFTmp1_G] = getCurrentBarIndex(); 
                } 
            // ---------------------------------------- 
            Now had the variables ready to make bar color adjustments:-
            PHP Code:
            // ****************************************
            // COLORING AREA
            // ----------------------------------------
             
            if (nDC_M >=nMDC_STL_P){
                
            setBarFgColor(cTrEStU_P0); // current bar
                
            fnAdjBrCol(vMTFTmp2_GcTrEStU_P0); //adjust any color errors in MTF mode

            }else if (nDC_M <=-nMDC_STL_P){
                
            setBarFgColor(cTrEStD_P0);
                
            fnAdjBrCol(vMTFTmp2_GcTrEStD_P0);


            which called a new function fnAdjBrCol():-
            PHP Code:
            // ***********************************************************
            function fnAdjBrCol(nBrLookbk_FcCol_FnIdx_F) {
            // Adjusts Bar Color in current chart from higher timeframe
            // ***********************************************************
            // When not in MTF mode setBar will essentially do nothing
            // When in MTF mode setBar checks backwards to ensure all bars
            // in current chart get painted correctly 
            // nBrLookbk_F starts at 0 then increases by -1 until 0 again

               
            for(i=0<= -nBrLookbk_Fi++) {
                 
            setBar(Bar.FgColor, -inIdx_FcCol_F); 
               } 
            // -----------------------------------------------------------
            // END function fnAdjBrCol()
            // ----------------------------------------------------------- 
            I have tested and seems all ok to me both the indicator in current chart time frame and when using the higher time frame plus the bar painting for actual chart timeframe and from a higher one.

            If anyone tries it and sees any problems let me know.

            Robert

            Here is the complete code:-

            PHP Code:
            /*************************************************************
            Title    : Donchian Channel Histogram
            By    : Robert Cameron
            Incept    : July 26, 2013
            Version : 0.0.2
            --------------------------------------------------------------
            **************************************************************
            Release History
            **************************************************************
            July 29, 2013 - Ensured coloring works in MTF mode with setBarFgColor() in main()
            0.0.2

            July 27, 2013 - Added Function for efsInternal call to allow MTF to work properly
            0.0.1

            July 26, 2013 - Inception & Prototype 
            0.0.0
            ============================================================
            */
            // MTF Variables
            var oMTFBC_G = new Object(); //Holds 
            var vMTFTmp1_GvMTFTmp2_GvMTFTmp3_G

            // Used in preMain() for user selection
            var fpArray = new Array();

            // ###########################################################
            function preMain(){
            // ###########################################################
            // STUDY FIXED PARAMETERS
             
             
            setPriceStudy(false);
             
            setStudyTitle("DCH");

            // VARIABLES
             
            var x=0;

            // USER SELECTION
            //-----------------------    
                
            // Donchian Study
                 
            fpArray[x] = new FunctionParameter("nDCPer_P"FunctionParameter.NUMBER);
                
            with(fpArray[x++]){
                    
            setLowerLimit(1);        
                     
            setDefault(10); //10
                 
            }

                 
            fpArray[x] = new FunctionParameter("sDCTrg_P"FunctionParameter.STRING);
                
            with(fpArray[x++]){
                     
            addOption("open"); 
                     
            addOption("high");
                     
            addOption("low");
                     
            addOption("close");
                     
            addOption("hl2");
                     
            addOption("hlc3");
                     
            addOption("ohlc4"); 
                     
            setDefault("close"); //close 
                 
            }
                
                
            fpArray[x] = new FunctionParameter"sOscSty_P"FunctionParameter.STRING);
                
            with(fpArray[x++]){
                     
            setName("Oscillator Style");
                    
            addOption("SOLID");
                    
            addOption("DASH");
                    
            addOption("DOT");
                    
            addOption("DASHDOT");
                    
            addOption("DASHDOTDOT");
                    
            setDefault"SOLID" );
                }

                
            fpArray[x] = new FunctionParameter"nOscThk_P"FunctionParameter.NUMBER);
                
            with(fpArray[x++]){
                     
            setName("Oscillator Thickness");
                    
            setLowerLimit);
                    
            setUpperLimit10 );
                    
            setDefault);
                }

                
            fpArray[x] = new FunctionParameter"sOscPlt_P"FunctionParameter.STRING);
                
            with(fpArray[x++]){
                     
            setName("Oscillator Plot");
                    
            addOption("LINE");
                    
            addOption("CIRCLE");
                    
            addOption("DOT");
                    
            addOption("SQUARE");
                    
            addOption("SQUAREWAVE");
                    
            addOption("HISTOGRAM");
                    
            addOption("FLATLINES");
                    
            addOption("INSTANTCOLORLINE");
                    
            setDefault"HISTOGRAM" );
                }

            //Symbol & Interval    
                 
            fpArray[x] = new FunctionParameter("sSymbol_P"FunctionParameter.STRING);
                 
            with(fpArray[x++]){
                     
            setDefault();
                 }

                 
            fpArray[x] = new FunctionParameter("sInterval_P"FunctionParameter.STRING);
                
            with(fpArray[x++]){
                     
            setDefault();
                 }

            // Base Line
                
            fpArray[x] = new FunctionParameter"cBL_P"FunctionParameter.COLOR);
                
            with(fpArray[x++]){
                     
            setName("BL Color");
                    
            setDefaultColor.yellow); //yellow
                
            }

                
            fpArray[x] = new FunctionParameter"sBLSty_P"FunctionParameter.STRING);
                
            with(fpArray[x++]){
                     
            setName("BL Style");
                    
            addOption("SOLID");
                    
            addOption("DASH");
                    
            addOption("DOT");
                    
            addOption("DASHDOT");
                    
            addOption("DASHDOTDOT");
                    
            setDefault"SOLID" );
                }

                
            fpArray[x] = new FunctionParameter"nBLThk_P"FunctionParameter.NUMBER);
                
            with(fpArray[x++]){
                     
            setName("BL Thickness");
                    
            setLowerLimit);
                    
            setUpperLimit);
                    
            setDefault);
                }

            // Oscillator Colors
                
            fpArray[x] = new FunctionParameter"cTrEStU_P"FunctionParameter.COLOR);
                
            with(fpArray[x++]){
                     
            setName("Up");
                    
            setDefaultColor.white); //white
                
            }

                
            fpArray[x] = new FunctionParameter"cTrEStD_P"FunctionParameter.COLOR);
                
            with(fpArray[x++]){
                     
            setName("Dn");
                    
            setDefaultColor.magenta); //magenta
                
            }
                    
                
            fpArray[x] = new FunctionParameter"cTrNT_P"FunctionParameter.COLOR);
                
            with(fpArray[x++]){
                     
            setName("No Trend");
                    
            setDefaultColor.yellow); //yellow
                
            }
                
            // Points
            // MDC
                
            fpArray[x] = new FunctionParameter"nMDC_STL_P"FunctionParameter.NUMBER);
                
            with(fpArray[x++]){
                     
            setName("MDC Limit");
                    
            setLowerLimit);
                    
            setDefault0.5 ); //0.5
                
            }
                
            // ==========================================================
            }    // END PreMain Function
            // ==========================================================

            // ##########################################################
            // MAIN
            function main(
            nDCPer_PsDCTrg_PsOscSty_PnOscThk_PsOscPlt_PsSymbol_PsInterval_PcBL_P

            sBLSty_PnBLThk_PcTrEStU_PcTrEStD_PcTrNT_PnMDC_STL_P
            ){
            // ##########################################################

            // ****************************************
            if ( getBarState() == BARSTATE_ALLBARS ){
            // ----------------------------------------

            /////////////////////////////////////
            // Set up Line Drawing & Cursor Info
            setDefaultBarFgColor(cTrNT_P0); //use in premain
            setDefaultBarStyle(eval("PS_"+sOscSty_P), 0);
            setDefaultBarThickness(nOscThk_P0);
            setCursorLabelName("DCH"0);
            setPlotType(eval("PLOTTYPE_"+sOscPlt_P), 0);

            // SYMBOL & INTERVAL
            if(sSymbol_P == nullsSymbol_P getSymbol();
            if(
            sInterval_P == nullsInterval_P getInterval();
            vSymbol_M sSymbol_P+","+sInterval_P;

            // STUDIES & VARIABLES
            xDC_R efsInternal("fnMDC"nDCPer_PsDCTrg_PnMDC_STL_Psym(vSymbol_M));
            nDC_M getSeries(xDC_R); //indicator

            // MTF BAR COUNTS in higher & lower time frames 
            xMTFBC efsInternal("fnMTFBC"vSymbol_M); 
            xBCSym getSeries(xMTFBC0);  //Symbol Bar Count
            xBCCur getSeries(xMTFBC1); // Lower TF Bar Count 

            // Base Line        
            addBand(0, eval("PS_"+sBLSty_P), nBLThk_PcBL_P"Center");
                
            // ----------------------------------------
            return null;
             } 
            // END ALLBARS
            // ========================================

            ////////////////////////////////////////////
            // This will return null if no data exists for the given symbol
            if (getOldestBarIndex() == null) return;

            //////////
            // CALCULATION AREA
            // ****************************************
            // MTF COLOR & GRAPHICS ADJUSTMENT
            // ----------------------------------------
            // Adjustment to redraw period
                
            vMTFTmp1_G xBCSym.getValue(0); //Counts each MTF bar
                
                
            vMTFTmp3_G xBCCur.getValue(0); //Total Bar Count by Current Chart to date
                
                
            vMTFTmp2_G vMTFTmp3_G getCurrentBarCount(); //counts the # of current interval 

            bars in each MTF bar. If no MTF used then will always be zero

            // assigns chart bar index to MTF Object from MTF Bar
                
            if (getBarStateSymbol(vSymbol_M) == BARSTATE_NEWBAR){ 
                    
            oMTFBC_G[vMTFTmp1_G] = getCurrentBarIndex(); 
                } 
            // ----------------------------------------

            // ****************************************
            // COLORING AREA
            // ----------------------------------------
             
            if (nDC_M >=nMDC_STL_P){
                
            setBarFgColor(cTrEStU_P0); // current bar
                
            fnAdjBrCol(vMTFTmp2_GcTrEStU_P0); //adjust any color errors in MTF mode

            }else if (nDC_M <=-nMDC_STL_P){
                
            setBarFgColor(cTrEStD_P0);
                
            fnAdjBrCol(vMTFTmp2_GcTrEStD_P0);

            }
            // ----------------------------------------

            // ****************************************
            // DISPLAY RESULT
            // ----------------------------------------
            return nDC_M //return as Series in case MTF mode chosen
            // ----------------------------------------

            // ===========================================================
            // END Main Processing Function
            // ===========================================================

            // ***********************************************************
            function fnAdjBrCol(nBrLookbk_FcCol_FnIdx_F) {
            // Adjusts Bar Color in current chart from higher timeframe
            // ***********************************************************
            // When not in MTF mode setBar will essentially do nothing
            // When in MTF mode setBar checks backwards to ensure all bars
            // in current chart get painted correctly 
            // nBrLookbk_F starts at 0 then increases by -1 until 0 again

               
            for(i=0<= -nBrLookbk_Fi++) {
                 
            setBar(Bar.FgColor, -inIdx_FcCol_F); 
               } 
            // -----------------------------------------------------------
            // END function fnAdjBrCol()
            // -----------------------------------------------------------

            // ***********************************************************
            var nBrSymFnG 0
            var 
            nBrCurFnG 0
            // -----------------------------------------------------------
            function fnMTFBC(Symbol_F) {
            // Controls count from higher timeframe in lower timeframe
            // ***********************************************************
                
            if (getBarStateSymbol(Symbol_F) ==  BARSTATE_NEWBAR){ 
                    
            nBrSymFnG += 1
                    
            nBrCurFnG getCurrentBarCount(); 
                } 
                return new Array(
            nBrSymFnG,nBrCurFnG); 
            // -----------------------------------------------------------
            // END function fnMTFBC()
            // -----------------------------------------------------------

            // ***********************************************************
            function fnMDC(nDCLen_FsDCTrg_FnMDC_F){
            // -----------------------------------------------------------
            var rMDCf;

            xMDCf middleDonchian(nDCLen_F);
            xDCSf = eval(sDCTrg_F+"(" ")"); //usually close('ES M3,1500T')

            // Mid Donchian Channel vs DC Trigger (ie close)
            if (xDCSf>xMDCf){
                
            rMDCf=nMDC_F;
            }else if (
            xDCSf<xMDCf){
                
            rMDCf=-nMDC_F;
            }else{
                
            rMDCf=0;
            }

            return 
            rMDCf;
            // -----------------------------------------------------------
            }    // END function fnMDC()
            // ----------------------------------------------------------- 

            Comment


            • #7
              Question to Esignal Development Group (as per request):-

              What is the correct coding to use to paint lines using an indicator from an external interval (ie higher time frame) onto a chart (ie with a lower time frame) that will be correctly represented in the current chart.

              I have shown what I had to do in this forum post to achieve this which involved many lines of code. Surely the efs engine should take of this as use of efsInternal() and getSeries() functions takes care fairly simply of synchronizaing the value of a single symbol from an external interval. So I would be interested in seeing a much simpler coding solution.

              Robert

              Comment


              • #8
                Robert
                I am not with the eSignal Development Group, but from past experience I suspect their answer would be no different.
                There is no "correct way" to do what you are trying to accomplish. You have to determine and manage the data points of the external intervals and maintain the synchronization yourself similarly to what you have already done.
                Also as I already told you in a previous reply earlier in this same thread search the forum as this topic [and the others you brought up] have already been covered before
                Alex


                Originally posted by rcamrn123 View Post
                Question to Esignal Development Group (as per request):-

                What is the correct coding to use to paint lines using an indicator from an external interval (ie higher time frame) onto a chart (ie with a lower time frame) that will be correctly represented in the current chart.

                I have shown what I had to do in this forum post to achieve this which involved many lines of code. Surely the efs engine should take of this as use of efsInternal() and getSeries() functions takes care fairly simply of synchronizaing the value of a single symbol from an external interval. So I would be interested in seeing a much simpler coding solution.

                Robert

                Comment


                • #9
                  Dear Alexis,

                  Thank you for your response.

                  I don't understand why it is necessary to do so much coding just to paint an indicator correctly from an external timeframe, when eSignal have already developed built in functions simply to display the value correctly synchronized using efsInternal and getSeries.

                  The same issues also relate to all graphics functions such as drawing lines. you have to jump through a number of coding hoops just to get everything to display right. I could understand this if there was no built in synch capability but it just covers one part of what is needed.

                  There should be similar built in functions using a call to external Interval/Symbol as used in efsInternal so that every graphics function is also synchronized without resorting to complex coding. So if esfInternal is used and that user function includes any graphics it automatically gets synched.

                  I could not find anything from multiple searches in forum posts and library that related to any of the grpahics issues I was having. If there are such specific posts/library resources then I would appreciate the urls to review. It would be even better if eSignal to write a comprehensive help resource located in one place covering use of graphics in multi time frame mode so it would be a one stop access.

                  Robert

                  Comment

                  Working...
                  X