Announcement

Collapse
No announcement yet.

Using Volume and the "sym" function

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

  • Using Volume and the "sym" function

    Hello,

    I've written a very simple study to color the background of the chart when the volume of the bar exceeds a certain level which is working correctly. I have then added the "sym" function to highlight the current chart when the volume in a different market exceeds a certain level. This also works OK except it will only work for the two most recent days, and I need it to go back as far as possible. I dont think there is an error with the code, but maybe Im missing something to do with using the sym function and volume?? I have posted the code below, and the two examples I have used are the Bobl and Bund futures (on a 5 min chart) but I have also tried the study on various other markets and can still only As always, any help is greatly appreciated!

    If you put the following code on the 5 min bobl chart (BL H4-DT) it works fine, but if you then put it on the 5 min bund chart (GB H4-DT) it will only work on the two most recent days.

    PHP Code:

    function preMain()  
    {  
        
    setPriceStudy(true);  
        
    setCursorLabelName("Vol Condition Test");  
        
    }

    function 
    main() {
        
        var 
    nVol volume(0,sym("BL H4-DT"));
        if (
    nVol >= 3500){
            
    setBarBgColor(Color.red)
        } else return;
        


  • #2
    ferret
    See this thread
    Alex


    Originally posted by ferret View Post
    Hello,

    I've written a very simple study to color the background of the chart when the volume of the bar exceeds a certain level which is working correctly. I have then added the "sym" function to highlight the current chart when the volume in a different market exceeds a certain level. This also works OK except it will only work for the two most recent days, and I need it to go back as far as possible. I dont think there is an error with the code, but maybe Im missing something to do with using the sym function and volume?? I have posted the code below, and the two examples I have used are the Bobl and Bund futures (on a 5 min chart) but I have also tried the study on various other markets and can still only As always, any help is greatly appreciated!

    If you put the following code on the 5 min bobl chart (BL H4-DT) it works fine, but if you then put it on the 5 min bund chart (GB H4-DT) it will only work on the two most recent days.

    PHP Code:

    function preMain()  
    {  
        
    setPriceStudy(true);  
        
    setCursorLabelName("Vol Condition Test");  
        
    }

    function 
    main() {
        
        var 
    nVol volume(0,sym("BL H4-DT"));
        if (
    nVol >= 3500){
            
    setBarBgColor(Color.red)
        } else return;
        

    Comment


    • #3
      Alexis,

      Thanks for the reply! Ive added the "setIntervalsBackfill(true)" line into the preMain and that has solved the problem!

      However, Ive encountered another problem. In my code, I have simply written a return statement near the beginning: if (nVol <= X) return; so that the code wont execute if there isnt X amount of volume in that bar. The problem is when the market that the sym function refers to has not traded for a period of time, the volume filter does not work properly as I guess there is no volume data for that bar for the code to evaluate.

      Any ideas for a way around this issue???

      Many thanks

      Daniel

      Comment


      • #4
        Hi there,

        Still struggling with this issue! Can anyone help?

        I have added a null check to the "if(nVol < X) return;" statement but this hasnt worked.

        After investigating further, Ive found that when the market that the sym function is refering to hasnt traded for that bar, the nVol variable gets assigned to the volume for the previous bar so I have added "nVol = 0;" after the conditional statements. However this still seems to be overrode by the "var nVol = volume(0,sym("XXX")); the next time round and still assigns the previous bar's volume to nVol.

        Is there anyway to fix the bar that the sym function refers to, to the current bar in the chart?

        Many thanks in advance for any help.
        Last edited by ferret; 02-11-2014, 12:10 PM.

        Comment


        • #5
          Solution found!

          Used the "getMinute" function to compare the time of the bars in both markets!

          Daniel

          Comment

          Working...
          X