Announcement

Collapse
No announcement yet.

Grains Daily Up/Down Limits

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

  • Grains Daily Up/Down Limits

    Im trying to create an indicator that will show the daily up/down movement limits for grains products. I have got as far as the following. It marks the up/down limit for ZW/. I plan on adding this to my watchlist so only want it to return a number for ZW for now ( I hope to add all the grains to one indicator, but being a newbie the process is as important as the final result, so one step at a time).
    MY first question is where and how can I add an if statement so that it will only return values for ZW?

    Thanks in advance
    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("CBOT-ZW Daily Limit Move");
        
    setCursorLabelName("PD-H"0); // High Limit
        
    setCursorLabelName("PD-L"1); // Low Limit

        
    setDefaultBarStyle(PS_SOLID0); // High Limit
        
    setDefaultBarStyle(PS_SOLID1); // Low Limit  

        
    setDefaultBarFgColor(Color.red0);    // High  
        
    setDefaultBarFgColor(Color.green1);    // Low   

        
    setDefaultBarThickness(40); // High  
        
    setDefaultBarThickness(41); // Low   

        
    setPlotType(PLOTTYPE_FLATLINES0);    // High  
        
    setPlotType(PLOTTYPE_FLATLINES1);    // Low   
    }

    var 
    bInit false;
    var 
    xHigh_Limit  null;
    var 
    xLow_Limit   null;

    function 
    main() {
         
        if(
    bInit == false){
            
    xHigh  high(inv("D"));
            
    xLow   low(inv("D"))  ;
            
    bInit true;
        }
        
      
        var 
    vHigh  xHigh.getValue(-1) + 60;
        var 
    vLow   xLow.getValue(-1) - 60;
        if( 
    vHigh == null || vLow == null)
        return;
        
        
        return new Array (
    vHigh,vLow);


  • #2
    Re: Grains Daily Up/Down Limits

    DK_trader
    The simplest solution is to use the getSymbol() function which returns the symbol on the chart and check if that matches the symbol you want in which case you execute your commands else you interrupt further execution of the script [see the following screenshot for an example of this]



    With the above solution however you will get a result only if the entire symbol matches.
    If instead you want to execute your commands when the script is running on any ZW contract then you need to manipulate the symbol string as required using the methods of the String Object.
    Enclosed below are a couple of images illustrating two ways of doing this using either the split() or substr() methods.
    In addition to the article at the link I provided above you may also want to review this article of the Core JavaScript Guide which is also included in the EFS KnowledgeBase
    Alex






    Originally posted by DK_trader
    Im trying to create an indicator that will show the daily up/down movement limits for grains products. I have got as far as the following. It marks the up/down limit for ZW/. I plan on adding this to my watchlist so only want it to return a number for ZW for now ( I hope to add all the grains to one indicator, but being a newbie the process is as important as the final result, so one step at a time).
    MY first question is where and how can I add an if statement so that it will only return values for ZW?

    Thanks in advance
    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("CBOT-ZW Daily Limit Move");
        
    setCursorLabelName("PD-H"0); // High Limit
        
    setCursorLabelName("PD-L"1); // Low Limit

        
    setDefaultBarStyle(PS_SOLID0); // High Limit
        
    setDefaultBarStyle(PS_SOLID1); // Low Limit  

        
    setDefaultBarFgColor(Color.red0);    // High  
        
    setDefaultBarFgColor(Color.green1);    // Low   

        
    setDefaultBarThickness(40); // High  
        
    setDefaultBarThickness(41); // Low   

        
    setPlotType(PLOTTYPE_FLATLINES0);    // High  
        
    setPlotType(PLOTTYPE_FLATLINES1);    // Low   
    }

    var 
    bInit false;
    var 
    xHigh_Limit  null;
    var 
    xLow_Limit   null;

    function 
    main() {
         
        if(
    bInit == false){
            
    xHigh  high(inv("D"));
            
    xLow   low(inv("D"))  ;
            
    bInit true;
        }
        
      
        var 
    vHigh  xHigh.getValue(-1) + 60;
        var 
    vLow   xLow.getValue(-1) - 60;
        if( 
    vHigh == null || vLow == null)
        return;
        
        
        return new Array (
    vHigh,vLow);

    Comment

    Working...
    X