Announcement

Collapse
No announcement yet.

Trading Session volume indicator exporting values for last 20 days using DDE links

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

  • Trading Session volume indicator exporting values for last 20 days using DDE links

    Hi guys,

    I have created an indicator that will sum the volume from a custom time session. The indicator is running on a 24 hour time template on CME futures. Indicator is using DDE links to export the value to the excel. Here is my code working as it should:

    Code:
    function preMain() {
    
        setPriceStudy(false);
    
        setStudyTitle("CME US Vol");
    
        setCursorLabelName("CME US Vol");
    
        setDefaultBarStyle(PS_SOLID, 0);
    
        setDefaultBarFgColor(Color.blue, 0);
    
        setDefaultBarThickness(1, 0);
    
        setPlotType(PLOTTYPE_HISTOGRAM, 0);
    
    }
    
    var USVol=0;
    
    function main()
    
    {
    
     
    
    if (getHour(0) >= 18 || getHour(0) <7 || day(0) != day(-1))
    
    {
    
    USVol=0;
    
    }else{
    
    if(getBarState()==BARSTATE_NEWBAR && day(0) == day(-1)){
    
    USVol+=volume(-1);
    
     
    
        if (USVol != null){
    
        var sName = "USVol" + getSymbol() + getInterval();
    
             sName = sName.replace(/\$/g, "");
    
            sName = sName.replace(/\#/g, "");
    
            sName = sName.replace(/\-/g, "");
    
            sName = sName.replace(/\(/g, "");
    
            sName = sName.replace(/\!/g, "");        
    
            sName = sName.replace(/\=/g, "");
    
            sName = sName.replace(/\:/g, "");
    
            sName = sName.replace(/\)/g, "");
    
            sName = sName.replace(/\ /g, "_")
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
    
            ddeUSVol = new DDEOutput(sName);
    
            }
    
       ddeUSVol.set(USVol);
    
    }
    
    }
    
    return USVol;
    
    }


    Thing is that I need to export highest values from the session for last 20 days. Here is the code I came up with:

    Code:
      
    
    var ddeAHH=null;
    
    var avg=null
    
    var tvol = null;
    
    var tvolf = null;
    
    function preMain() {
    
        setPriceStudy(false);
    
        setStudyTitle("CME Tokyo Vol 20");
    
        setCursorLabelName("CME Tokyo Vol 20");
    
        setDefaultBarStyle(PS_SOLID, 0);
    
        setDefaultBarFgColor(Color.blue, 0);
    
        setDefaultBarThickness(1, 0);
    
        setPlotType(PLOTTYPE_HISTOGRAM, 0);
    
    }
    
    function main()
    
    {
    
    tvol = efsInternal("TVol");
    
    tvolf = highest(250,tvol);
    
     
    
         avg = tvolf.getValue(0)
    
         avg1 = tvolf.getValue(-100)
    
         avg2 = tvolf.getValue(-200)
    
         avg3 = tvolf.getValue(-300)
    
         avg4 = tvolf.getValue(-400)
    
         avg5 = tvolf.getValue(-500)
    
         avg6 = tvolf.getValue(-600)
    
         avg7 = tvolf.getValue(-700)
    
         avg8 = tvolf.getValue(-800)
    
         avg9 = tvolf.getValue(-900)
    
         avg10 = tvolf.getValue(-1000)
    
         avg11 = tvolf.getValue(-1100)
    
         avg12 = tvolf.getValue(-1200)
    
         avg13 = tvolf.getValue(-1300)
    
         avg14 = tvolf.getValue(-1400)
    
         avg15 = tvolf.getValue(-1500)
    
         avg16 = tvolf.getValue(-1600)
    
         avg17 = tvolf.getValue(-1700)
    
         avg18 = tvolf.getValue(-1800)
    
         avg19 = tvolf.getValue(-1900)
    
     
    
            if (ddeAHH == null) {
    
            var sName = "AHH" + getSymbol() + getInterval();
    
            sName = sName.replace(/\$/g, ""); // remove $ from string
    
            sName = sName.replace(/\#/g, ""); // remove # from string
    
            sName = sName.replace(/\-/g, "");
    
            sName = sName.replace(/\(/g, "");
    
            sName = sName.replace(/\)/g, "");
    
            sName = sName.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
    
            ddeAHH = new DDEOutput(sName);
    
           
    
             var sName1 = "avg1" + getSymbol() + getInterval();
    
            sName1 = sName1.replace(/\$/g, ""); // remove $ from string
    
            sName1 = sName1.replace(/\#/g, ""); // remove # from string
    
            sName1 = sName1.replace(/\-/g, "");
    
            sName1 = sName1.replace(/\(/g, "");
    
            sName1 = sName1.replace(/\)/g, "");
    
            sName1 = sName1.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName1);
    
            ddeavg1 = new DDEOutput(sName1);
    
           
    
             var sName2 = "avg2" + getSymbol() + getInterval();
    
            sName2 = sName2.replace(/\$/g, ""); // remove $ from string
    
            sName2 = sName2.replace(/\#/g, ""); // remove # from string
    
            sName2 = sName2.replace(/\-/g, "");
    
            sName2 = sName2.replace(/\(/g, "");
    
            sName2 = sName2.replace(/\)/g, "");
    
            sName2 = sName2.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName2);
    
            ddeavg2 = new DDEOutput(sName2);
    
           
    
             var sName3 = "avg3" + getSymbol() + getInterval();
    
            sName3 = sName3.replace(/\$/g, ""); // remove $ from string
    
            sName3 = sName3.replace(/\#/g, ""); // remove # from string
    
            sName3 = sName3.replace(/\-/g, "");
    
            sName3 = sName3.replace(/\(/g, "");
    
            sName3 = sName3.replace(/\)/g, "");
    
            sName3 = sName3.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName3);
    
            ddeavg3 = new DDEOutput(sName3);
    
        REST OF THE DDE LINKS FORMULA WAS CUT OUT AS THE CODE WAS TOO LONG FOR POSTING!!!
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
    
    
    
           
    
        }
    
            ddeAHH.set(avg);
            ddeavg1.set(avg1);
            ddeavg2.set(avg2);
            ddeavg3.set(avg3);
            ddeavg4.set(avg4);
            ddeavg5.set(avg5);
            ddeavg6.set(avg6);
            ddeavg7.set(avg7);
            ddeavg8.set(avg8);
            ddeavg9.set(avg9);
            ddeavg10.set(avg10);
            ddeavg11.set(avg11);
            ddeavg12.set(avg12);
            ddeavg13.set(avg13);
            ddeavg14.set(avg14);
            ddeavg15.set(avg15);
            ddeavg16.set(avg16);
            ddeavg17.set(avg17);
            ddeavg18.set(avg18);
            ddeavg19.set(avg19);
    
           
    
    return tvolf;
    
    }
    
     
    
     
    
     
    
    var TokyoVol = null;
    
    function TVol(){
    
    if (getHour(0) >= 3 && getHour(0) <18)
    
    {
    
    TokyoVol=0;
    
     
    
    }else{
    
    if(getBarState()==BARSTATE_NEWBAR){
    
    TokyoVol+=volume(-1);
    
     
    
    }
    
    }
    
    return TokyoVol;
    
    }


    Problem is that the indicator needs to run on 24 hour time template and I have a problem with getting the correct values for the previous days (number of bars back). Number of bars for each day is changing so the hard numbers are not really helping here:

    Code:
         avg = tvolf.getValue(0)
         avg1 = tvolf.getValue(-100)
         avg2 = tvolf.getValue(-200)
         avg3 = tvolf.getValue(-300)
         avg4 = tvolf.getValue(-400)
         avg5 = tvolf.getValue(-500)
         avg6 = tvolf.getValue(-600)
         avg7 = tvolf.getValue(-700)
         avg8 = tvolf.getValue(-800)
         avg9 = tvolf.getValue(-900)
         avg10 = tvolf.getValue(-1000)
         avg11 = tvolf.getValue(-1100)
         avg12 = tvolf.getValue(-1200)
         avg13 = tvolf.getValue(-1300)
         avg14 = tvolf.getValue(-1400)
         avg15 = tvolf.getValue(-1500)
         avg16 = tvolf.getValue(-1600)
         avg17 = tvolf.getValue(-1700)
         avg18 = tvolf.getValue(-1800)
         avg19 = tvolf.getValue(-1900)
    Is there a way that I can get it working properly?

    Any help would be greatly appreciated.

    Thank you.

  • #2
    tokyoSA
    Assuming I am correctly understanding what you are trying to do see the image enclosed below which illustrates (together with comments) one way you could accomplish it using an Array in which you store the values of the accumulated Volume at the end of each session.
    For more information on the use of arrays see this article in the EFS KnowledgeBase
    BTW you may want to contact a user called maninjapan since you seem to be doing exactly the same things using very similar (if not the same) code set and you are both - presumably by your handles - in Japan
    Alex




    Originally posted by tokyoSA View Post
    Hi guys,

    I have created an indicator that will sum the volume from a custom time session. The indicator is running on a 24 hour time template on CME futures. Indicator is using DDE links to export the value to the excel. Here is my code working as it should:

    Code:
    function preMain() {
    
        setPriceStudy(false);
    
        setStudyTitle("CME US Vol");
    
        setCursorLabelName("CME US Vol");
    
        setDefaultBarStyle(PS_SOLID, 0);
    
        setDefaultBarFgColor(Color.blue, 0);
    
        setDefaultBarThickness(1, 0);
    
        setPlotType(PLOTTYPE_HISTOGRAM, 0);
    
    }
    
    var USVol=0;
    
    function main()
    
    {
    
    
    
    if (getHour(0) >= 18 || getHour(0) <7 || day(0) != day(-1))
    
    {
    
    USVol=0;
    
    }else{
    
    if(getBarState()==BARSTATE_NEWBAR && day(0) == day(-1)){
    
    USVol+=volume(-1);
    
    
    
        if (USVol != null){
    
        var sName = "USVol" + getSymbol() + getInterval();
    
             sName = sName.replace(/\$/g, "");
    
            sName = sName.replace(/\#/g, "");
    
            sName = sName.replace(/\-/g, "");
    
            sName = sName.replace(/\(/g, "");
    
            sName = sName.replace(/\!/g, "");        
    
            sName = sName.replace(/\=/g, "");
    
            sName = sName.replace(/\:/g, "");
    
            sName = sName.replace(/\)/g, "");
    
            sName = sName.replace(/\ /g, "_")
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
    
            ddeUSVol = new DDEOutput(sName);
    
            }
    
       ddeUSVol.set(USVol);
    
    }
    
    }
    
    return USVol;
    
    }


    Thing is that I need to export highest values from the session for last 20 days. Here is the code I came up with:

    Code:
      
    
    var ddeAHH=null;
    
    var avg=null
    
    var tvol = null;
    
    var tvolf = null;
    
    function preMain() {
    
        setPriceStudy(false);
    
       setStudyTitle("CME Tokyo Vol 20");
    
        setCursorLabelName("CME Tokyo Vol 20");
    
        setDefaultBarStyle(PS_SOLID, 0);
    
        setDefaultBarFgColor(Color.blue, 0);
    
        setDefaultBarThickness(1, 0);
    
        setPlotType(PLOTTYPE_HISTOGRAM, 0);
    
    }
    
    function main()
    
    {
    
    tvol = efsInternal("TVol");
    
    tvolf = highest(250,tvol);
    
    
    
         avg = tvolf.getValue(0)
    
         avg1 = tvolf.getValue(-100)
    
         avg2 = tvolf.getValue(-200)
    
         avg3 = tvolf.getValue(-300)
    
         avg4 = tvolf.getValue(-400)
    
         avg5 = tvolf.getValue(-500)
    
         avg6 = tvolf.getValue(-600)
    
         avg7 = tvolf.getValue(-700)
    
         avg8 = tvolf.getValue(-800)
    
         avg9 = tvolf.getValue(-900)
    
         avg10 = tvolf.getValue(-1000)
    
         avg11 = tvolf.getValue(-1100)
    
         avg12 = tvolf.getValue(-1200)
    
         avg13 = tvolf.getValue(-1300)
    
         avg14 = tvolf.getValue(-1400)
    
         avg15 = tvolf.getValue(-1500)
    
         avg16 = tvolf.getValue(-1600)
    
         avg17 = tvolf.getValue(-1700)
    
         avg18 = tvolf.getValue(-1800)
    
         avg19 = tvolf.getValue(-1900)
    
    
    
            if (ddeAHH == null) {
    
            var sName = "AHH" + getSymbol() + getInterval();
    
            sName = sName.replace(/\$/g, ""); // remove $ from string
    
            sName = sName.replace(/\#/g, ""); // remove # from string
    
            sName = sName.replace(/\-/g, "");
    
            sName = sName.replace(/\(/g, "");
    
            sName = sName.replace(/\)/g, "");
    
            sName = sName.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
    
            ddeAHH = new DDEOutput(sName);
    
           
    
             var sName1 = "avg1" + getSymbol() + getInterval();
    
            sName1 = sName1.replace(/\$/g, ""); // remove $ from string
    
            sName1 = sName1.replace(/\#/g, ""); // remove # from string
    
            sName1 = sName1.replace(/\-/g, "");
    
            sName1 = sName1.replace(/\(/g, "");
    
            sName1 = sName1.replace(/\)/g, "");
    
            sName1 = sName1.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName1);
    
            ddeavg1 = new DDEOutput(sName1);
    
           
    
             var sName2 = "avg2" + getSymbol() + getInterval();
    
            sName2 = sName2.replace(/\$/g, ""); // remove $ from string
    
            sName2 = sName2.replace(/\#/g, ""); // remove # from string
    
            sName2 = sName2.replace(/\-/g, "");
    
            sName2 = sName2.replace(/\(/g, "");
    
            sName2 = sName2.replace(/\)/g, "");
    
            sName2 = sName2.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName2);
    
            ddeavg2 = new DDEOutput(sName2);
    
           
    
             var sName3 = "avg3" + getSymbol() + getInterval();
    
            sName3 = sName3.replace(/\$/g, ""); // remove $ from string
    
            sName3 = sName3.replace(/\#/g, ""); // remove # from string
    
            sName3 = sName3.replace(/\-/g, "");
    
            sName3 = sName3.replace(/\(/g, "");
    
            sName3 = sName3.replace(/\)/g, "");
    
            sName3 = sName3.replace(/\ /g, "_") // replace space with underscore
    
            debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName3);
    
            ddeavg3 = new DDEOutput(sName3);
    
        REST OF THE DDE LINKS FORMULA WAS CUT OUT AS THE CODE WAS TOO LONG FOR POSTING!!!
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  
    
    
    
           
    
        }
    
            ddeAHH.set(avg);
            ddeavg1.set(avg1);
            ddeavg2.set(avg2);
            ddeavg3.set(avg3);
            ddeavg4.set(avg4);
            ddeavg5.set(avg5);
            ddeavg6.set(avg6);
            ddeavg7.set(avg7);
            ddeavg8.set(avg8);
            ddeavg9.set(avg9);
            ddeavg10.set(avg10);
            ddeavg11.set(avg11);
            ddeavg12.set(avg12);
            ddeavg13.set(avg13);
            ddeavg14.set(avg14);
            ddeavg15.set(avg15);
            ddeavg16.set(avg16);
            ddeavg17.set(avg17);
            ddeavg18.set(avg18);
            ddeavg19.set(avg19);
    
           
    
    return tvolf;
    
    }
    
    
    
    
    
    
    
    var TokyoVol = null;
    
    function TVol(){
    
    if (getHour(0) >= 3 && getHour(0) <18)
    
    {
    
    TokyoVol=0;
    
    
    
    }else{
    
    if(getBarState()==BARSTATE_NEWBAR){
    
    TokyoVol+=volume(-1);
    
    
    
    }
    
    }
    
    return TokyoVol;
    
    }


    Problem is that the indicator needs to run on 24 hour time template and I have a problem with getting the correct values for the previous days (number of bars back). Number of bars for each day is changing so the hard numbers are not really helping here:

    Code:
         avg = tvolf.getValue(0)
         avg1 = tvolf.getValue(-100)
         avg2 = tvolf.getValue(-200)
         avg3 = tvolf.getValue(-300)
         avg4 = tvolf.getValue(-400)
         avg5 = tvolf.getValue(-500)
         avg6 = tvolf.getValue(-600)
         avg7 = tvolf.getValue(-700)
         avg8 = tvolf.getValue(-800)
         avg9 = tvolf.getValue(-900)
         avg10 = tvolf.getValue(-1000)
         avg11 = tvolf.getValue(-1100)
         avg12 = tvolf.getValue(-1200)
         avg13 = tvolf.getValue(-1300)
         avg14 = tvolf.getValue(-1400)
         avg15 = tvolf.getValue(-1500)
         avg16 = tvolf.getValue(-1600)
         avg17 = tvolf.getValue(-1700)
         avg18 = tvolf.getValue(-1800)
         avg19 = tvolf.getValue(-1900)
    Is there a way that I can get it working properly?

    Any help would be greatly appreciated.

    Thank you.

    Comment


    • #3
      Hi Alex!
      Thanks very much for the reply, but i cannot view the picture that u posted... Looks like the link to the picture doesn't work anymore.
      Last edited by tokyoSA; 10-11-2013, 06:31 AM.

      Comment


      • #4
        tokyoSA
        The issue was due to FileShare [which is where I store my inline images] being offline
        As far as I can see it is online now so if you are still not seeing the image try refreshing your page
        Alex


        Originally posted by tokyoSA View Post
        Hi Alex!
        Thanks very much for the reply, but i cannot view the picture that u posted... Looks like the link to the picture doesn't work anymore.

        Comment


        • #5
          Thank you Alex! Have it now
          About maninjapan - we actually work together, his previous code was regarding different issue, now for some reason his account is blocked so he cannot use the forum... We greatly appreciate all the help you giving us! Thank you very much!

          Comment


          • #6
            tokyoSA
            You are welcome
            Alex


            Originally posted by tokyoSA View Post
            Thank you Alex! Have it now
            About maninjapan - we actually work together, his previous code was regarding different issue, now for some reason his account is blocked so he cannot use the forum... We greatly appreciate all the help you giving us! Thank you very much!

            Comment

            Working...
            X