Announcement

Collapse
No announcement yet.

Color coding price bars based on TII

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

  • Color coding price bars based on TII

    Can someone show me how to color code the price bars based on whether the TII of the current bar is >TII of previous bar (GREEN) or TII of current bar<TII of previous bar red. I want the default bar color of grey in the case where the TIICurrent=TIIPrev

    If possible i want a conditon that the TII>10 and <90 in both cases.
    So the basic strategy here is you enter long if the previous bar is green and its high is taken out and you enter short if the previous bar is red and its low is taken out.

    I dont want to confuse anyone with the strategy that is being worked on in the other thread for the trend strengh indicator as it is a differnt strategy than this is so instead of adding to the efs from that thread please refer to the orignal TII.efs code by TSSUPPORT on theri efs studeis thread. You can find it on either the bottom of page 1 or top of page 2 in that thread.
    Thanks,
    yoda

  • #2
    I have done a similar study using the cci to color code my bars and wanted to make sure i have a few thigns correct.

    Is the current bar refered to as (1), the previous bar as (0) and 2 bars ago(-1) ?
    If so what i need to program is
    If TII(0) > TII(-1) and 10<TII(0)<90 and high(1)>high(0) then go long
    if TII(0) < TII(-1) and 10<TII(0)<90 and low(1) <low(0) then go short.
    i hope this makes it clear what im trying to accomplish here
    Thanks
    Yoda

    Comment


    • #3
      The current bar is indexed to 0, the previous one is -1, then comes -2, etc.

      maybe you could re write your formula with those corrections and then ask for mor help.

      You have a nice way of asking for help, keep it up, the kind people on this board seem to be responding to your sincere efforts.

      Nice to see you trying to modify the code on your own now, looks like your java script education is coming along just fine.

      Comment


      • #4
        yoda

        you could also set the crossovers above 90 or below 10 by setting the conditions this way

        IF tii(-2) < 90 AND tii(-1) >=90
        AND IF tii(0) > tii(-1)
        THEN Buy @ High(-1)+Stop

        similarly

        IF tii(-2) > 10 AND tii(-1) <= 10
        AND IF tii(0) < tii(-1)
        THEN Sell @ Low(-1)-Stop

        This should Buy/Sell only on the first occurrence of the condition and should reset only if the tii comes back down below 90 in the first case or above 10 in the second.

        Alex

        Comment


        • #5
          alexis,
          My system isnt meant to play just the crossovers it should also buy if the TII indicator is increasing even if its over 10 on the previous bar.
          Is it possible to have this in my code

          if TII(-1)>TII(-2) && TII(-1)>10 &&TII(-1)<90 then
          colorbar....(color.green)

          if TII(-1) <TII(-2) && TII(-1)<10 && TII(-1)<90 then
          colorbar ... (color.green)

          In other words can you have three conditons in one statement or do i have to put them into 2 statements.

          As far as the code goes for buying if high(0)>high(-1) ive tried for hours to find a way to get that to show up on the strategy analysis but it always buys the open. gspiker has been an enormous help for mw to figure this out but i still cant get that one item to work.

          big time thianks to you dloomis,doji and gspiker for taking the time to help me out. i actually spend hours tryin out code myself before i even post on this board but ther is just some nuances of this javascript that still elude me
          Yoda

          Comment


          • #6
            Add jasonk to the list of course

            Comment


            • #7
              yoda

              As far as the code goes for buying if high(0)>high(-1) ive tried for hours to find a way to get that to show up on the strategy analysis but it always buys the open.

              Look at the attached efs that uses a breakout of prior high/low for the entry.
              Run it on a 3 min ES H3 set with 9:30-16:15 Time Template and run a Backtest.
              If you go for example to today's 11:26 (ET) bar you should see that despite the condition was true on the 11:25 bar it did not buy because the stop high+0.25 was not touched.
              It instead buys at 11:28 at the high+0.25 of the prior blue bar.
              Equally it does not sell on the 11:32 after a red bar but instead sells on the 11:38 bar that takes out the low of the prior red bar.
              The entry values in Backtesting should reflect the correct prices as far as I can see.
              Maybe from this you can extrapolate what you want to do with TII.
              Hope this helps
              Alex

              Edit after post: I think I have forgotten to add the setColorPriceBars(true);
              statement so current bars may paint white. Non the less the object of the efs was to illustrate the order entry.
              Attached Files
              Last edited by ACM; 03-04-2003, 02:28 PM.

              Comment


              • #8
                so far my attempts at getting the price bars to color basde on tii being higher or lower than previous tii have given me error after error.

                1)If tii is defined as a variable in my efs does the code recognoze
                tii(0), tii(-1) as the values of the tii form the current bar and previous bar respectviely or do i have to define something else in my code.

                2) This is the code i added:

                if (tii(0)>tii(-1)) {
                setPriceBarColor(Color.green);
                } else if(tii(0)<tii(-1)) {
                setPriceBarColor(Color.red);
                }

                3) i also have the statements:
                setColorPriceBars(true);
                setDefaultPriceBarColor(Color.grey);
                in thepremain function area;

                4) the code i have written in 2) was placed right after my entry criteria.
                5)when i try to apply the efs to my chart it gives no data at all so either the problem is the placemtn of my additonal code or the code itself or both.
                Thanks for your help here
                yoda

                Comment


                • #9
                  1)If tii is defined as a variable in my efs does the code recognoze tii(0), tii(-1) as the values of the tii form the current bar and previous bar respectviely or do i have to define something else in my code.
                  No, but if you return tti to eSignal (ie: do a return(tti) from your efs for each bar), then you can use ref() to reference old return values (and hence old values of tti). The format for ref is:

                  ref(offset, number of bars)

                  So ref(-1) would give you the value of the study for the last bar
                  and ref(-10,8) would start 10 periods ago and return the following 8 bars of values.

                  If you don't return tii from your formula, then you will have to either use arrays (if you are going to look back a long way in time) or some regular variables to store the last one or two values of tii.

                  4) the code i have written in 2) was placed right after my entry criteria.
                  I suspect you want this coloring to happen no matter what, so make sure there are no condiftional around it.
                  Garth

                  Comment


                  • #10
                    gs,
                    Let me see if i understand correctly. Right after tii is defined i should place my code for the color bars even before the test for stops and test for profits.
                    Now since i want this color code to go back as far as esignal data will allow i should set up an array using 2 varaibles like ttcurrent and tt previuos.
                    If this is true how would i define these varaibles:
                    would it be var ttcurrent = tti(0)
                    Thanks
                    Yoda

                    Comment


                    • #11
                      Alex or anyone,

                      I've taken your code for entering long/short w/ stop +/-0.25. however, upon backtesting (in which i use another indicator) it will, for example, go long (or short) each time my indicator condition is true - in other words it will pyramid. I'd like it to stay long (or short) 1st time and ignore new long sigs, and then reverse once short condition is met.

                      Additionally, i'd like to (and this may be difficult) set BE stop if trade goes +2. If trade goes +5, then take 1/2 postion off and BE stop postion adjusts accordingly. The other 1/2 will close out once reversal condition met.
                      Is this possible?

                      also,
                      even though i would use a 24hr intraday chart, i'd like it to enter trades after 6:30pst and close out any open trades at 13:00pst M-F, thus no overnight nor sunday trading.

                      Originally posted by Alexis C. Montenegro
                      yoda

                      As far as the code goes for buying if high(0)>high(-1) ive tried for hours to find a way to get that to show up on the strategy analysis but it always buys the open.

                      Look at the attached efs that uses a breakout of prior high/low for the entry.
                      Run it on a 3 min ES H3 set with 9:30-16:15 Time Template and run a Backtest.
                      If you go for example to today's 11:26 (ET) bar you should see that despite the condition was true on the 11:25 bar it did not buy because the stop high+0.25 was not touched.
                      It instead buys at 11:28 at the high+0.25 of the prior blue bar.
                      Equally it does not sell on the 11:32 after a red bar but instead sells on the 11:38 bar that takes out the low of the prior red bar.
                      The entry values in Backtesting should reflect the correct prices as far as I can see.
                      Maybe from this you can extrapolate what you want to do with TII.
                      Hope this helps
                      Alex

                      Edit after post: I think I have forgotten to add the setColorPriceBars(true);
                      statement so current bars may paint white. Non the less the object of the efs was to illustrate the order entry.
                      Last edited by michaelm; 04-27-2003, 04:13 PM.
                      Michael

                      Comment


                      • #12
                        Michael
                        You may want to look at the 5-15 x-over.efs in this thread as an example for not triggering multiple trades in one direction.
                        Alex

                        Comment


                        • #13
                          thanks alex, but i use the onAction1 etc...the thread doesn't really help with all that i'm asking.
                          Here's what i'm using for long side so far, perhaps you can tweak it to do what i need?

                          //{{EFSWizard_Actions
                          //{{EFSWizard_Action_1
                          function onAction1() {
                          setPriceBarColor(Color.lime);
                          if (vLastAlert != 1) setPriceBarColor(Color.RGB(0,0,255));
                          if (vLastAlert != 1) Strategy.doLong("", Strategy.STOP, Strategy.NEXTBAR, Strategy.DEFAULT, high()+0.25);
                          if (vLastAlert != 1) Alert.addToList(getSymbol(), "aPnt6 BUY Order "+(high()+0.25), Color.black, Color.green);
                          if (vLastAlert != 1) Alert.playSound("Warning.wav");
                          vLastAlert = 1;
                          }
                          Michael

                          Comment


                          • #14
                            Michael

                            The function onAction() you just posted only shows what actions are to be taken once a set of conditions are met and not the conditions themselves.
                            You need to insert another condition in your formula that determines whether you already are in a trade or not, once all the other conditions are met, otherwise the system will keep on issuing buy or sell orders.

                            If you open the efs I suggested using the Formula Wizard you will see that the last condition in Set1 is
                            isLong()==0
                            What this means is essentially the following "IF all the prior conditions are met AND the system is NOT already long (isLong==0) THEN perform all the steps in onAction".

                            Run a backtest of that efs and set the results aside. You will see that it only executes a buy or sell once even though the crossovers can happen more than one time. Then with the Formula Wizard X out those lines in Set1 and Set2 where isLong and isShort are set. Save the efs and run the backtest again and you will see that now it pyramids trades.

                            Alex
                            Last edited by ACM; 04-27-2003, 10:56 PM.

                            Comment


                            • #15
                              alex,
                              i'm trying to get this stuff, but i am really more a trader than a programmer. i really appreciate those of you who are gurus at this.

                              the indicator formula i'm refering to is below.

                              from this i would like to go long 0.25point above blue bar high (or short -0.25 below low of red bar). All actions should be sent to Alert Window.

                              if long entered, set initial stop loss at 4 points. if new signal to short happens before initial stop loss hit, then it will reverse and cxl the initial stop loss. if trade goes +2 points in favor, then move initial stop loss to a break even stop. if trade goes +5points, then cover 1/2 of trade, have the BE stop adjust for 1/2 left, and the 1/2 left of trade will stay on until there is a short signal, whereupon it will cover that 1/2 and go short.
                              visa versa for the short side.

                              i would like trade signals to occur only between 6:30 - 13:00 pst, M-F. thus, new trades initiate only after 6:30, and cover if in trade at 12:59.

                              I am also including link to
                              this thread, which seems like you had some great ideas.

                              Here's the indicator code, and thank you so much.

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


                              //{{EFSWizard_Declarations

                              var vADXDM = new ADXDMStudy(14);
                              var vLastAlert = -1;

                              //}}EFSWizard_Declarations 5889


                              function preMain() {
                              /**
                              * This function is called only once, before any of the bars are loaded.
                              * Place any study or EFS configuration commands here.
                              */
                              //{{EFSWizard_PreMain
                              setPriceStudy(false);
                              setStudyTitle("APaint");
                              setCursorLabelName("APaint", 0);
                              setDefaultBarStyle(PS_SOLID, 0);
                              setDefaultBarFgColor(Color.red, 0);
                              setDefaultBarThickness(1, 0);
                              setPlotType(PLOTTYPE_HISTOGRAM, 0);
                              addBand(0, PS_SOLID, 1, Color.yellow);
                              setColorPriceBars(true);
                              //}}EFSWizard_PreMain 28968

                              }

                              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 (
                              vADXDM.getValue(ADXDMStudy.PDI)-vADXDM.getValue(ADXDMStudy.NDI)
                              > 0
                              ) onAction1()
                              //}}EFSWizard_Expression_1 7444

                              //{{EFSWizard_Expression_2
                              else if (
                              vADXDM.getValue(ADXDMStudy.PDI)-vADXDM.getValue(ADXDMStudy.NDI)
                              < 0
                              ) onAction2()
                              //}}EFSWizard_Expression_2 11131

                              //{{EFSWizard_Expression_3
                              else if (
                              1 < 1
                              ) onAction3();
                              //}}EFSWizard_Expression_3 6628

                              //}}EFSWizard_Expressions 54132


                              //{{EFSWizard_Return
                              return vADXDM.getValue(ADXDMStudy.PDI)-vADXDM.getValue(ADXDMStudy.NDI)
                              ;
                              //}}EFSWizard_Return 5500

                              }

                              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(0,255,0));
                              if (vLastAlert != 1) setPriceBarColor(Color.RGB(0,0,255));
                              vLastAlert = 1;
                              }
                              //}}EFSWizard_Action_1 16572

                              //{{EFSWizard_Action_2
                              function onAction2() {
                              setPriceBarColor(Color.RGB(255,192,160));
                              if (vLastAlert != 2) setPriceBarColor(Color.RGB(255,0,0));
                              vLastAlert = 2;
                              }
                              //}}EFSWizard_Action_2 19655

                              //{{EFSWizard_Action_3
                              function onAction3() {
                              setPriceBarColor(Color.RGB(0,0,0));
                              vLastAlert = 3;
                              }
                              //}}EFSWizard_Action_3 10592

                              //}}EFSWizard_Actions 82254
                              Michael

                              Comment

                              Working...
                              X