Announcement

Collapse
No announcement yet.

Need help with coding

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

  • Need help with coding

    Can anyone give me a hint as to how I might go about refrencing an "X" minute high or low? A brief code example would be great, as I am still struggling to learn the coding process.

    Essentially, what I want to do in the end is to draw a line at some value above and below a 30 minute range.

    Thanks in advance!

  • #2
    This, done quick with the wizard, will set the price bar color to red if the high of the last 20 bars is > 500.


    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description 7532


    //{{EFSWizard_Declarations

    var vDonchian = new DonchianStudy(20, 0);
    var vLastAlert = -1;

    //}}EFSWizard_Declarations 7854


    function preMain() {
    //{{EFSWizard_Code_PreMain_setPriceBarColor
    setColorPriceBars(true);
    //}}EFSWizard_Code_PreMain_setPriceBarColor 3448
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("");
    //}}EFSWizard_PreMain 5650

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    vDonchian.getValue(DonchianStudy.UPPER) < 500
    ) onAction1();
    //}}EFSWizard_Expression_1 9294

    //}}EFSWizard_Expressions 20316


    //{{EFSWizard_Return
    return null;
    //}}EFSWizard_Return 2256

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    setPriceBarColor(Color.RGB(155,0,0));
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1 10013

    //}}EFSWizard_Actions 19967

    Comment


    • #3
      dloomis,

      Thanks so much for you help, but this isn't what I meant.
      I"m not interested in just any 30 minute high, but the high after 30 minutes of trading. Or, put another way; the high of the day at 30 minutes of trading. Once set, that hight would not move.

      Hope this is more explicit.

      Comment


      • #4
        Cool moss

        You need to figure out what time it is by using getHour, get Minute() etc then check to see if the current time is equal to your parameter of 930+x minutes. Then drawLineRelative at this level for each new bar.

        Sounds simple huh?

        Comment


        • #5
          This might be close to what you want - at least it has no syntax errors. Should draw a line starting at 10am at the high and low of the last 20 bars. Resets itslf at 4pm

          var vDonchian = new DonchianStudy(20, 0);
          var xMin
          var cBarTimeInt
          var time=0;
          var x;

          function main(xMin){
          if(xMin==null) xMin=30;
          getTime();
          if(cBarTimeInt>=930+xMin){
          time=1;
          vUPPER=vDonchian.getValue(DonchianStudy.UPPER)
          vLOWER=vDonchian.getValue(DonchianStudy.LOWER)
          }
          if(getBarState()==BARSTATE_NEWBAR) x=x+1
          if(time==1){
          drawLineRelative( 0, vUPPER,0, vUPPER,PS_SOLID, 1, Color.blue, x);
          drawLineRelative( 0, vLOWER, 0, vLOWER, PS_SOLID, 1, Color.blue, x);
          }
          if(cBarTimeInt>=1600)
          time=0;
          }

          function getTime(){
          today =new Date;
          CurHours =today.getHours();
          CurMinutes=today.getMinutes();
          CurSeconds=today.getSeconds();

          cBarTimeInt =CurHours*10000+CurMinutes*100+CurSeconds*0;
          return;
          }

          Comment


          • #6
            oops, change

            if(cBarTimeInt>=930+xMin){

            to

            if(cBarTimeInt==930+xMin){

            probably other logic erros as well.

            Comment

            Working...
            X