Announcement

Collapse
No announcement yet.

background colors intrabar

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

  • background colors intrabar

    Below I've attached an abbreviated EFS that was first created with the Wizard then modified with the editor. The problem I am having occurs intra bar. Often times I will get an intrabar signal (which is what I want and why I used strategy.CLOSE of THISBAR) but the problem is when the signal is false the background color does not change back to neutral grey. I think it occurs when it first mets my BUY/SELL condition but then the conditions change but not enough to meet my EXIT conditions, so I'm stuck inbetween signals? I'm neither in a trade nor my exit conditions have not been met either. Unless I refresh the EFS by reloading it or the chart the background stays the same. Am I making any sense?

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Signal 7 - large time frame");
    }

    function main() {

    var vState = getBarState();


    //Expression_1_ENTRY_LONG
    if (
    ENTRY CONDITION
    ) onAction1()

    //Expression_2_ENTRY_SHORT
    if(
    SHORT CONDITION
    ) onAction2()


    //Expression_3_EXIT_LONG
    if (
    Strategy.isLong() &&
    EXIT LONG CONDITION
    ) onAction3()


    //Expression_4_EXIT_SHORT
    if (
    Strategy.isShort()&&
    EXIT SHORT CONDITION
    ) onAction4();


    //background colors
    if (
    Strategy.isLong()){
    setBarBgColor(Color.RGB(233,255,233));
    }
    if (
    Strategy.isShort()){
    setBarBgColor(Color.RGB(255,233,233));
    }
    else if (
    !Strategy.isInTrade()){
    setBarBgColor(Color.RGB(192,192,192));
    }

    //alerts for NEWBAR
    if (
    Strategy.isLong() &&
    (getHour()*100)+getMinute() > vt1 &&
    vState == (BARSTATE_NEWBAR))
    {
    Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
    Alert.addToList(getSymbol(), "Buy Signal large time frame", Color.RGB(0,0,0), Color.RGB(0,255,0));
    }
    if (
    Strategy.isShort() &&
    (getHour()*100)+getMinute() > vt1 &&
    vState == (BARSTATE_NEWBAR))
    {
    Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
    Alert.addToList(getSymbol(), "Sell Signal large time frame", Color.RGB(0,0,0), Color.RGB(195,0,0));
    }
    else if (
    (!Strategy.isInTrade()) &&
    (getHour()*100)+getMinute() > vt1 &&
    vState == (BARSTATE_NEWBAR))
    {
    Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
    Alert.addToList(getSymbol(), "Exit all trades large time frame", Color.RGB(0,0,0), Color.RGB(195,0,0));
    }

    //{{_Return
    return null;
    //}}_Return 2256

    }

    function postMain() {
    }

    //{{Action_1
    function onAction1() {
    if (vLastAlert != 1) Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    vLastAlert = 1;
    }


    //{{Action_2!
    function onAction2() {
    if (vLastAlert != 2) Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    vLastAlert = 2;
    }


    //{{Action_3_EXIT_LONG
    function onAction3() {
    if (vLastAlert != 3) Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    vLastAlert = 3;
    }


    //{{Action_4_EXIT_SHORT
    function onAction4() {
    if (vLastAlert != 4) Strategy.doCover("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    vLastAlert = 4;
    }

    I think it has something to do with the vLastAlert system, is there a different way to do this? I want the background color to indicate whether or not I'm long/short or neutral and update tick by tick.
    thanks
    morph
    Last edited by morpheous; 08-21-2003, 06:06 AM.

  • #2
    either this is not possible or I'm not making any sense.,

    Comment


    • #3
      I remember taking a look at this before and thinking it was complex and better handled by some one else.

      So, ith that in mind, here is my 2 cents.

      I think you need a line to set the bar color to some neutral color. Try inserting the line before all of the other tests. That way if none of the other situations apply, the default color will come on.

      ie

      //background colors
      setBarBgColor(Color.RGB(3,3,233));

      if (
      Strategy.isLong()){
      setBarBgColor(Color.RGB(233,255,233));
      }

      Comment


      • #4
        Hello morpheous,

        The problem is you are trying to use a back testing formula for real time analysis. The Strategy object is not intended for real time usage so your checks for Strategy.isLong() etc. are not returning the expected result. To make a formula compatible for both back testing and real time analysis there are just a few things I would recommend.

        1. Create a global variable called vPosition. Set this equal to "long" when long, "short" when short and null when you are not in a position.

        2. Replace all Strategy.isLong(), Strategy.isShort() and Strategy.isInTrade() with:
        vPosition == "long"
        vPosition == "short"
        vPosition != null

        3. Add this if statement to the front of all Strategy.do functions so they look like this:
        if (getCurrentBarIndex() != 0) Strategy.do .... etc. ....

        The only Strategy functions that should be left in your formula would be the Strategy.do functions. Then change your bar coloring routine to the following and place it just above your last return statement in main().

        PHP Code:
            //background colors
            
        if (vPosition == "long") {
                
        setBarBgColor(Color.RGB(233,255,233));
            } else if (
        vPosition == "short") {
                
        setBarBgColor(Color.RGB(255,233,233));
            } else {
                
        setBarBgColor(Color.RGB(192,192,192));
            } 
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Hello Jason,

          I'm not doing something correct here, I've copied the EFS below, it doesn't give me any background colors and trades 3 times as much as before so I'm obviously missing something, could you look at it for me.
          thank you

          var vMACDExit = new MACDStudy(12, 26, 9, "Close", false);
          var vMACDEntry = new MACDStudy(5, 20, 9, "Close", false);
          var vStochExit = new StochStudy(14, 3, 3);
          var vStochEntry = new StochStudy(10, 3, 3);
          var vChop14 = new ChopStudy(14);
          var vADXDM = new ADXDMStudy(14);
          var vEMA20 = new MAStudy(20, 0, "Close", MAStudy.EXPONENTIAL);
          var vEMA200 = new MAStudy(200, 0, "Close", MAStudy.EXPONENTIAL);
          var vEMA10 = new MAStudy(10, 0, "Close", MAStudy.EXPONENTIAL);
          var vEMA50 = new MAStudy(50, 0, "Close", MAStudy.EXPONENTIAL);
          var vEMA5 = new MAStudy(5, 0, "Close", MAStudy.EXPONENTIAL);
          var vRSI14 = new RSIStudy(14, "CLose");
          var vLastAlert = 0;
          var vADX = 10
          var vt1 = 915;
          var vt2 = 1354;
          var vt3 = 1354;
          var vt4 = 1600;
          vPosition = 0



          function preMain() {
          setPriceStudy(true);
          setStudyTitle("Signal 11 - large time frame");
          }

          function main() {


          var vLong = vStochEntry.getValue(StochStudy.FAST) > vStochEntry.getValue(StochStudy.SLOW) &&
          vStochEntry.getValue(StochStudy.SLOW) > 20 &&
          vADXDM.getValue(ADXDMStudy.ADX) > vADX &&
          vMACDEntry.getValue(MACDStudy.SIGNAL) < vMACDEntry.getValue(MACDStudy.MACD) &&
          vMACDEntry.getValue(MACDStudy.HIST) > vMACDEntry.getValue(MACDStudy.HIST, -1) &&
          (getHour()*100)+getMinute() < vt4 &&
          close() > open();

          var vShort =vStochEntry.getValue(StochStudy.FAST) < vStochEntry.getValue(StochStudy.SLOW) &&
          vStochEntry.getValue(StochStudy.SLOW) < 80 &&
          vADXDM.getValue(ADXDMStudy.ADX) > vADX &&
          vMACDEntry.getValue(MACDStudy.SIGNAL) > vMACDEntry.getValue(MACDStudy.MACD) &&
          vMACDEntry.getValue(MACDStudy.HIST) < vMACDEntry.getValue(MACDStudy.HIST, -1) &&
          (getHour()*100)+getMinute() < vt4 &&
          close() < open();

          var vSell= vPosition == "long" &&
          vStochExit.getValue(StochStudy.FAST) < vStochExit.getValue(StochStudy.SLOW) &&
          vStochExit.getValue(StochStudy.SLOW) < 90 &&
          close() < close(-1);

          var vCover =vPosition == "short" &&
          vStochExit.getValue(StochStudy.FAST) > vStochExit.getValue(StochStudy.SLOW) &&
          vStochExit.getValue(StochStudy.SLOW) > 10 &&
          close() > close(-1);

          //Expression_1_ENTRY_LONG
          if (
          vLong == true
          ) onAction1()


          //Expression_2_ENTRY_SHORT
          if (
          vShort == true
          ) onAction2()


          //Expression_3_EXIT_LONG
          if (
          vSell == true
          ) onAction3()

          //Expression_4_EXIT_SHORT
          if (
          vCover == true
          ) onAction4()

          //ADXtime
          if (
          vPosition == "long" &&
          vADXDM.getValue(ADXDMStudy.ADX) < 10
          ) onAction3()

          else if (
          vPosition == "short" &&
          vADXDM.getValue(ADXDMStudy.ADX) < 10
          ) onAction4()


          //closetime
          if (
          vPosition == "long" &&
          (getHour()*100)+getMinute() >= 1600
          ) onAction3()

          else if (
          vPosition == "short" &&
          (getHour()*100)+getMinute() >= 1600
          ) onAction4()


          //NEWBAR ALERTS
          var vState = getBarState();
          if (
          vPosition == "long" &&
          (getHour()*100)+getMinute() > vt1 &&
          vState == (BARSTATE_NEWBAR))
          {
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
          Alert.addToList(getSymbol(), "Buy Signal large time frame", Color.RGB(0,0,0), Color.RGB(0,255,0));
          }
          else if (
          vPosition == "short" &&
          (getHour()*100)+getMinute() > vt1 &&
          vState == (BARSTATE_NEWBAR))
          {
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
          Alert.addToList(getSymbol(), "Sell Signal large time frame", Color.RGB(0,0,0), Color.RGB(195,0,0));
          }
          else if (
          (getHour()*100)+getMinute() > vt1 &&
          vState == (BARSTATE_NEWBAR))
          {
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
          Alert.addToList(getSymbol(), "Exit all trades large time frame", Color.RGB(0,0,0), Color.RGB(195,0,0));
          }


          //background colors

          if (vPosition == "long") {
          setBarBgColor(Color.RGB(233,255,233));
          } else if (vPosition == "short") {
          setBarBgColor(Color.RGB(255,233,233));
          } else {
          setBarBgColor(Color.RGB(192,192,192));
          }
          return;


          }

          function postMain() {
          }

          //{{Action_1
          function onAction1() {
          if (getCurrentBarIndex() != 0) Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
          vPosition == "long";
          }


          //{{Action_2
          function onAction2() {
          if (getCurrentBarIndex() != 0) Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
          vPosition == "short";
          }


          //{{Action_3_EXIT_LONG
          function onAction3() {
          if (getCurrentBarIndex() != 0) Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
          vPosition == null;
          }


          //{{Action_4_EXIT_SHORT
          function onAction4() {
          if (getCurrentBarIndex() != 0) Strategy.doCover("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
          vPosition == null;
          }

          Comment


          • #6
            Hello Morpheous,

            All your changes look good except for one small problem in your onAction functions. Your using a "==" to set the value of vPosition, which is incorrect. That symbol is checking for equality of. You want to use this symbol in your if statements, which you are. But in your onAction functions use "=" to set the value of vPosition to "long" etc. You probaly already know that, but anyway. It's a common mistake.

            Try this for starters and let me know how it goes.

            PHP Code:
            //{{Action_1
            function onAction1() { 
                if (
            getCurrentBarIndex() != 0Strategy.doLong(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                
            vPosition "long";
            }


            //{{Action_2
            function onAction2() {
                if (
            getCurrentBarIndex() != 0Strategy.doShort(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                
            vPosition "short";
            }


            //{{Action_3_EXIT_LONG
            function onAction3() {
                if (
            getCurrentBarIndex() != 0Strategy.doSell(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                
            vPosition null;
            }


            //{{Action_4_EXIT_SHORT
            function onAction4() {
                if (
            getCurrentBarIndex() != 0Strategy.doCover(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                
            vPosition null;

            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              Hi Jason,

              Well I added the change and it now works, unfortunately it works the same as it did before, I get false signals intrabar that do not reset themselves when conditions change.
              For example, one of my buy "vLong" conditions is close() > open();
              I get the buy signal intrabar no problem(background turns green) when conditions are met and the bar color is green, but when price reverses and the bar turns red the background color still stays green. Only when I reload the EFS or the chart does the vPosition reset itself the the background changes back to neutral grey. Any other ideas?

              morph.

              Comment


              • #8
                Hello Morpheous,

                From what you are telling me, sounds like you need to wait until the bar closes to determine if you are going to take a position. Normally, we could just add setComputeOnClose() to preMain(). But we can’t since you are using the Alert object. The solution is to simulate a compute on close behavior by using getBarState() and allowing certain code blocks to execute only at the instance of BARSTATE_NEWBAR. I've made some significant changes to your formula. In brief, what happens now is that the formula will wait until the bar closes and then look at all the conditions on bar -1. At the instance of the new bar, if a trade condition is found to be true, the trade will occur at the open of that new bar (Strategy.MARKET, Strategy.THISBAR). The color of the bars will now only reflect your position status during that bar. I also added some logic that will only allow your Alerts to be triggered when a trade occurs (see vLastPosition). Therefore, if you are in a long position for 6 bars, you'll only get an Alert when you first entered the position and when you exit 6 bars later. Try this out and let me know if we're getting closer to what you need.

                morpheousStrategy.efs
                Jason K.
                Project Manager
                eSignal - an Interactive Data company

                EFS KnowledgeBase
                JavaScript for EFS Video Series
                EFS Beginner Tutorial Series
                EFS Glossary
                Custom EFS Development Policy

                New User Orientation

                Comment


                • #9
                  eSignal Developers
                  It seems that the (undocumented) behaviour of the ALERT object needs to be changed to permit it to function when using setComputeOnClose, etc. I have been having a lot of problems with this, and it appears that others are also.
                  Thanks
                  George

                  Comment


                  • #10
                    Hello George,

                    The best way to handle this is to submit your ideas/suggestions to [email protected].
                    Jason K.
                    Project Manager
                    eSignal - an Interactive Data company

                    EFS KnowledgeBase
                    JavaScript for EFS Video Series
                    EFS Beginner Tutorial Series
                    EFS Glossary
                    Custom EFS Development Policy

                    New User Orientation

                    Comment


                    • #11
                      Hi Jason

                      Thanks for the clean up effort of that EFS, however it's not exactly what I'm looking for. The reason why I don't just go with computeonclose is because I want a real time tick by tick indication of wether or not I'm long short or neutral and I want the background color to be that indication. My strategy is to take a position at the close of thisbar if the signals are given and correct. So ideally I'm trying to get a pop up alert at the open of every newbar telling me my position status and the background to change color tick by tick accordingly. For backtesting I'm trying to get long/short/sell/cover at the close of this bar.
                      It sounds like this may be impossible though. My previous EFS was real close, maybe if there was a way to reload the EFS or reset the vPosition? at the end of every bar then I would feel more comfortabe taking a position on the signal without reloading the chart first?

                      Morph

                      Comment


                      • #12
                        Hello Morpheous,

                        I'm beginning to understand what you need now. Try the new formula below. It should behave as you want for back testing and real time.

                        morpheousStrategy.efs
                        Jason K.
                        Project Manager
                        eSignal - an Interactive Data company

                        EFS KnowledgeBase
                        JavaScript for EFS Video Series
                        EFS Beginner Tutorial Series
                        EFS Glossary
                        Custom EFS Development Policy

                        New User Orientation

                        Comment


                        • #13
                          thanks

                          that seems to have done the trick

                          thanks jason

                          Comment

                          Working...
                          X