Announcement

Collapse
No announcement yet.

same SMA for high, low and close price data

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

  • same SMA for high, low and close price data

    Hi

    Could someone tell me what mistake I am making in the code below

    Regardless of whether I call (directly or indirectly) the

    high
    low
    close

    I get the same result for a moving average – the sma moving average based on the close price

    In the function one of the sma’s / Breakout3 is prefixed as a var to see if that made any difference – it didn’t



    var FlagA = 0;
    var FlagA1 = 0;
    var FlagB = 0;
    var FlagB1 = 0;
    var Breakout = 0;
    var Breakout1 = 0;
    var Breakout2 = 0;
    var Breakout3 = 0;
    var Breakout4 = 0;
    var Breakout5 = 0;

    function main() {

    FlagA1 =low;
    FlagB1 =high;

    Breakout = sma(10,FlagA1.getValue);
    Breakout1 = sma(10,FlagB1.getValue);
    Breakout2 = sma(10,high.getValue);
    var Breakout3 = sma(10,high.getValue);
    Breakout4 = sma(10,low.getValue);
    Breakout5 = sma(10,close.getValue);

    return new Array (Breakout,Breakout1,Breakout2,Breakout3, Breakout4, Breakout5);

    }



    The answer to what I am doing wrong is probably pretty obvious but I cant seem to work it out.

    The output data which shows each column as identical is below this and after that is the pre main function – all plots OK (ie but with identical numbers) on the charts


    Thanks

    Robert



    Output to csv file

    Bar Date Time Open High Low Close Upper Env Lower Env Upper Env1Lower Env1Upper Env2Lower

    1 03/16/09 00:00 12608 12622 12409 12431 <None> <None> <None> <None> <None> <None>
    2 03/17/09 00:00 12432 12532 12328 12408 <None> <None> <None> <None> <None> <None>
    3 03/18/09 00:00 12325 13218 12323 12909 <None> <None> <None> <None> <None> <None>
    4 03/19/09 00:00 12916 13108 12827 12915 <None> <None> <None> <None> <None> <None>
    5 03/20/09 00:00 12919 13012 12826 12908 <None> <None> <None> <None> <None> <None>
    6 03/23/09 00:00 12903 12924 12808 12820 <None> <None> <None> <None> <None> <None>
    7 03/24/09 00:00 12811 12912 12625 12904 <None> <None> <None> <None> <None> <None>
    8 03/25/09 00:00 12812 12820 12632 12725 <None> <None> <None> <None> <None> <None>
    9 03/26/09 00:00 12714 12826 12629 12819 <None> <None> <None> <None> <None> <None>
    10 03/27/09 00:00 12815 12913 12731 12818 12731 12731 12731 12731 12731 12731
    11 03/30/09 00:00 12818 12931 12808 12831 12812 12812 12812 12812 12812 12812
    12 03/31/09 00:00 12829 12930 12820 12923 12830 12830 12830 12830 12830 12830


    590 07-12-11 00:00 12604 12715 12600 12615 12404 12404 12404 12404 12404 12404
    591 07/13/11 00:00 12628 12702 12526 12623 12412 12412 12412 12412 12412 12412
    592 07/14/11 00:00 12620 12627 12520 12526 12419 12419 12419 12419 12419 12419
    593 07/15/11 00:00 12522 12605 12503 12601 12429 12429 12429 12429 12429 12429
    594 07/18/11 00:00 12531 12616 12508 12522 12506 12506 12506 12506 12506 12506
    595 07/19/11 00:00 12515 12702 12500 12620 12517 12517 12517 12517 12517 12517
    596 07/20/11 00:00 12628 12628 12526 12528 12525 12525 12525 12525 12525 12525
    597 07/21/11 00:00 12600 12601 12423 12503 12530 12530 12530 12530 12530 12530
    598 07/22/11 00:00 12503 12531 12502 12527 12601 12601 12601 12601 12601 12601
    599 07/25/11 00:00 12506 12603 12424 12502 12530 12530 12530 12530 12530 12530
    600 07/26/11 00:00 12506 12530 12422 12526 <None>

    preMain

    function preMain() {
    setPriceStudy(true);
    setComputeOnClose()
    setStudyTitle("FunctionParameter: TEST-ERROR");

    setPlotType(PS_DASH,0);
    setPlotType(PS_DASH,1);
    setPlotType(PS_DASH,2);
    setPlotType(PS_DASH,3);

    setCursorLabelName("Upper Env", 0);
    setCursorLabelName("Lower Env", 1);
    setCursorLabelName("Upper Env1", 2);
    setCursorLabelName("Lower Env1", 3);
    setCursorLabelName("Upper Env2", 4);
    setCursorLabelName("Lower Env2", 5);

    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarFgColor(Color.grey, 2);
    setDefaultBarFgColor(Color.green, 3);
    setDefaultBarFgColor(Color.magenta, 4);
    setDefaultBarFgColor(Color.purple, 5);

    setDefaultBarThickness(3, 0);
    setDefaultBarThickness(3, 1);
    setDefaultBarThickness(3, 2);
    setDefaultBarThickness(3, 3);
    setDefaultBarThickness(3, 4);
    setDefaultBarThickness(3, 5);

    }

  • #2
    Re: same SMA for high, low and close price data

    Hi RobertHere,

    You should check out the EFS2 How-To links below to check out how to construct the sma series your trying to formulate. Alex (and others) have published some great code examples and accompanying explanations if you go through the different threads.

    Also, your references to high, low or close are references to functions. You'll see in the links you will have to call the function, e.g. high(), low() or close() to get a data series.

    Also check out the efs Knowledgebase for definitive explanations.

    Hope this helps.

    Steve

    Originally posted by RobertHere
    Hi

    Could someone tell me what mistake I am making in the code below

    Regardless of whether I call (directly or indirectly) the

    high
    low
    close

    I get the same result for a moving average – the sma moving average based on the close price

    In the function one of the sma’s / Breakout3 is prefixed as a var to see if that made any difference – it didn’t



    var FlagA = 0;
    var FlagA1 = 0;
    var FlagB = 0;
    var FlagB1 = 0;
    var Breakout = 0;
    var Breakout1 = 0;
    var Breakout2 = 0;
    var Breakout3 = 0;
    var Breakout4 = 0;
    var Breakout5 = 0;

    function main() {

    FlagA1 =low;
    FlagB1 =high;

    Breakout = sma(10,FlagA1.getValue);
    Breakout1 = sma(10,FlagB1.getValue);
    Breakout2 = sma(10,high.getValue);
    var Breakout3 = sma(10,high.getValue);
    Breakout4 = sma(10,low.getValue);
    Breakout5 = sma(10,close.getValue);

    return new Array (Breakout,Breakout1,Breakout2,Breakout3, Breakout4, Breakout5);

    }



    The answer to what I am doing wrong is probably pretty obvious but I cant seem to work it out.

    The output data which shows each column as identical is below this and after that is the pre main function – all plots OK (ie but with identical numbers) on the charts


    Thanks

    Robert



    Output to csv file

    Bar Date Time Open High Low Close Upper Env Lower Env Upper Env1Lower Env1Upper Env2Lower

    1 03/16/09 00:00 12608 12622 12409 12431 <None> <None> <None> <None> <None> <None>
    2 03/17/09 00:00 12432 12532 12328 12408 <None> <None> <None> <None> <None> <None>
    3 03/18/09 00:00 12325 13218 12323 12909 <None> <None> <None> <None> <None> <None>
    4 03/19/09 00:00 12916 13108 12827 12915 <None> <None> <None> <None> <None> <None>
    5 03/20/09 00:00 12919 13012 12826 12908 <None> <None> <None> <None> <None> <None>
    6 03/23/09 00:00 12903 12924 12808 12820 <None> <None> <None> <None> <None> <None>
    7 03/24/09 00:00 12811 12912 12625 12904 <None> <None> <None> <None> <None> <None>
    8 03/25/09 00:00 12812 12820 12632 12725 <None> <None> <None> <None> <None> <None>
    9 03/26/09 00:00 12714 12826 12629 12819 <None> <None> <None> <None> <None> <None>
    10 03/27/09 00:00 12815 12913 12731 12818 12731 12731 12731 12731 12731 12731
    11 03/30/09 00:00 12818 12931 12808 12831 12812 12812 12812 12812 12812 12812
    12 03/31/09 00:00 12829 12930 12820 12923 12830 12830 12830 12830 12830 12830


    590 07-12-11 00:00 12604 12715 12600 12615 12404 12404 12404 12404 12404 12404
    591 07/13/11 00:00 12628 12702 12526 12623 12412 12412 12412 12412 12412 12412
    592 07/14/11 00:00 12620 12627 12520 12526 12419 12419 12419 12419 12419 12419
    593 07/15/11 00:00 12522 12605 12503 12601 12429 12429 12429 12429 12429 12429
    594 07/18/11 00:00 12531 12616 12508 12522 12506 12506 12506 12506 12506 12506
    595 07/19/11 00:00 12515 12702 12500 12620 12517 12517 12517 12517 12517 12517
    596 07/20/11 00:00 12628 12628 12526 12528 12525 12525 12525 12525 12525 12525
    597 07/21/11 00:00 12600 12601 12423 12503 12530 12530 12530 12530 12530 12530
    598 07/22/11 00:00 12503 12531 12502 12527 12601 12601 12601 12601 12601 12601
    599 07/25/11 00:00 12506 12603 12424 12502 12530 12530 12530 12530 12530 12530
    600 07/26/11 00:00 12506 12530 12422 12526 <None>

    preMain

    function preMain() {
    setPriceStudy(true);
    setComputeOnClose()
    setStudyTitle("FunctionParameter: TEST-ERROR");

    setPlotType(PS_DASH,0);
    setPlotType(PS_DASH,1);
    setPlotType(PS_DASH,2);
    setPlotType(PS_DASH,3);

    setCursorLabelName("Upper Env", 0);
    setCursorLabelName("Lower Env", 1);
    setCursorLabelName("Upper Env1", 2);
    setCursorLabelName("Lower Env1", 3);
    setCursorLabelName("Upper Env2", 4);
    setCursorLabelName("Lower Env2", 5);

    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarFgColor(Color.grey, 2);
    setDefaultBarFgColor(Color.green, 3);
    setDefaultBarFgColor(Color.magenta, 4);
    setDefaultBarFgColor(Color.purple, 5);

    setDefaultBarThickness(3, 0);
    setDefaultBarThickness(3, 1);
    setDefaultBarThickness(3, 2);
    setDefaultBarThickness(3, 3);
    setDefaultBarThickness(3, 4);
    setDefaultBarThickness(3, 5);

    }

    Comment


    • #3
      Hi Steve

      Thanks for the feed back Steve - I'll read the links

      Thanks

      Robert

      Comment


      • #4
        Robert,

        Breakout = sma(10,FlagA1.getValue);
        Breakout1 = sma(10,FlagB1.getValue);
        Breakout2 = sma(10,high.getValue);
        var Breakout3 = sma(10,high.getValue);
        Breakout4 = sma(10,low.getValue);
        Breakout5 = sma(10,close.getValue);

        Looking at your code you've assigned the same sma(10) to all of your breakouts. The second parameter is invalid and not being considered.

        Without fully understanding your project here's a little snippet of code from function main() used to assign the variable for the High, low and close. It then uses those same variables as the source to get the 10 point SMA for each.

        PHP Code:
        function main() {


            if (
        bInit == false){  // Use a condition statment to execute and assign value to your variables
                
        vHigh =high ();  // vHigh is the series object for the high
                
        vLow =low(); // vLow is the series object for the low
                
        vClose =close(); // vClose is the series object for the close
                
        bInit true;
            }
                  
            
        Breakout sma(10,vHigh);    // assigns the value of the 10pt MA of the High to Breakout
            
        Breakout1 sma(10,vLow);   // assigns the value of the 10pt MA of the low Breakout1
            
        Breakout2 sma(10,vClose);   // assigns the value of the 10pt MA of the Close to Breakout2
         
        return new Array(Breakout,Breakout1Breakout2);




        Hope this helps

        AveryH
        eSignal Support

        Comment


        • #5
          Hi Avery

          Thank you for the updates - it was very helpful for me to see what I was doing that was incorrect

          Things seem much clearer now - Breakout was just a label not actually used for anything.

          In my example I didnt understand why the second parameter is invalid or that you had to assign the variable before you could use it.

          As I now understand it one cant call any value / variable other than close directly into a function (sma/lowest/highest etc) except if you assign it to a variable first - ie " if (bInit == false){ " etc

          Is that correct ?

          Your comments were very helpful - I'll update things and see where that goes

          Thanks

          Robert

          Comment


          • #6
            Hi Robert,

            Your most welcome.

            Looks like Avery has you well covered on this one.

            Steve

            Originally posted by RobertHere
            Hi Steve

            Thanks for the feed back Steve - I'll read the links

            Thanks

            Robert

            Comment


            • #7
              Hey Robert,

              Sorry for the delay in getting back to you.
              As I now understand it one cant call any value / variable other than close directly into a function (sma/lowest/highest etc) except if you assign it to a variable first - ie " if (bInit == false){ " etc
              You're somewhat correct. The close should not be used directly either, as shown in the sample. The OHLC are all Series Objects and they need to be assigned to a variable so that you can retract the specific data you need.

              AveryH
              eSignal Support

              Comment

              Working...
              X