Announcement

Collapse
No announcement yet.

Calling another efs?? - different time intervals

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

  • Calling another efs?? - different time intervals

    This is probably a commonly asked question.....but I appreciate any help:

    I wish to write an efs that issues a BUY/SELL trade for an instrument in a certain time interval, say a 10 minute bar chart. This signal will be dependent on a value set in another efs, itself based on a different time interval, say a 60 minute bar chart.
    What must be the format of the Main clause in the called efs, and of its RETURN clause?

    And which type of CALL is most appropriate, the "call( EFSName, args )", or "callFunction( EFSName, FunctionName, [Parameters...])"?


    Details of the system are as follows:

    The longer time interval chart will establish if there is an uptrend, downtrend or neither in place, and return a value accordingly.

    The shorter term interval chart will take the passed value, and based on an oscillator, issue a BUY STOP after a pullback in an uptrend, or a SELL STOP after a run-up in a downtrend.

    This is basically the Elder triple screen system. In English, BUY after a pullback within an uptrend, and vice-versa.

    My understanding is that since I am operating in different timeframes, I need two (2) charts and so, two (2) efs. Hence the need for one to invoke the other.
    Thanks
    George

    note: I am hoping that R7.4 will support these kind of trades with the Integrated Brokers (such as IB), trades over and above simple BUY/SELL.

  • #2
    I would do it this way...

    Longer term chart...

    Create your EFS so that it accomplishes the tasks and creates GLOBAL VARIABLES. I would think you would need two global variables.

    1. for trend
    2. for an entry trigger

    See...

    setGlobalValue()
    getGlobalValue()

    Shorter term chart

    Create your EFS so that it accomplishes the tasks and READS the GLOBAL VARIABLES of the longer term chart. Then you could create your final entry conditions and trigger your trade.

    Hope this helps..

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      More on global variables

      Doji3333
      Many thanks. I have everything set up, but cannot access the Global variables which I have set in the higher level EFS (i.e. the one where the variables are setGlobalValue'd, and then (presumably optionally), getGlobalValue'd for debugging purposes).

      The EFS produces the correct values, but when I try and access them in the called EFS, they are always null.

      How - exactly - does the invoking EFS access such global variables? What is the programming language statement to use? I thought they were in some "pool" and could be retrieved with a simple getGlobalValue in the "calling" EFS, but I am always returned null values.

      There is precious little doco on global variable properties, methods, etc. The Manual on p.21-13 refers to http://www.esignal.com/advcharting but that URL leads nowhere.

      Many thanks
      George

      Comment


      • #4
        Following on ....

        Re my previous post.....In the "calling routine" I am dumping the values of the setGlobalValue variables on entry, and they are all null (for each bar in the calling routine i.e. the "child" EFS).

        Now, thinking about how this programming feature probably works on static data (after trading hours), I am guessing that whatever is the current value of the passed setGlobalValue variable(s), that value will be used for each and every bar of the "calling" routine. So, if the last value of the "called" GlobalValue variable is null, then that value will be used for all bars in the calling routine.

        Is this how it works?

        What I am doing is that the "parent" routine establishes the presence of a trend, and passes this as a GlobalValue variable to a "child" routine which first establishes if a trend is in place var y = getGlobalValue("DownTrend"). If so, it looks for overbot/oversold situations to trigger a BUY/SELL, as appropriate. But if it (the Trend variable) is null at the last bar of the parent routine, then it will be null for all bars of the called routine, no trend will be found, and so no BUY/SELLsignal can ever be given!

        Is this correct?

        If so, my code may well be fine, but I must simply wait for this thing to run in RealTime, when non-null values will be stored in the setGlobalValue variables, and passed down.


        George

        Comment


        • #5
          Hi,

          Now, thinking about how this programming feature probably works on static data (after trading hours), I am guessing that whatever is the current value of the passed setGlobalValue variable(s), that value will be used for each and every bar of the "calling" routine. So, if the last value of the "called" GlobalValue variable is null, then that value will be used for all bars in the calling routine.
          Yes, there is basically no way to synch these up, so depending on which EFS is run first you will either get nothing on the "listener" study or you will get only the last value of the "sender".

          In RT mode of course this will be different, but using this method of globals will make it much harder to display your indicator for historical data or to do backtesting. The bit of trouble you will have in RT mode however is to know which formula is running "first". For example if I have a sender program set up on a 60 minute interval and the listen on a 10 minute interval as each tick comes in the 10 minute might execute first, or the 60 minute might. For most people this really doesn't make much difference (one tick delay on signals at worst case), bit for other it could cause critical problems with their code.

          Garth
          Garth

          Comment


          • #6
            Wombat would it be possible for you to post your efs as I am attempting to do the same thing with a 13 min and 3 min CCi
            thanks

            Comment


            • #7
              Sure, here it is

              Matt
              Here it is. Note that for this posting, I have simply appended the calling EFS (the one that tries to GET the global variables) immediately after the called routine (the one that sets them).
              var EMAlen = 13
              var MACDfast=12;
              var MACDslow=26;
              var MACDsmoothing = 9;
              var EMA = new MAStudy(EMAlen, 0, "Close", MAStudy.EXPONENTIAL);
              var slow = new MAStudy(7, 0, "Close", MAStudy.SIMPLE);
              var MACD = new MACDStudy (MACDfast,MACDslow,MACDsmoothing,"Close",true);
              var At ='@';
              var Sell_Mess = "SELL";
              var Sell_Close = "SELL Cls";
              var Sell_Short = "SELL Shrt";
              var Buy_Mess = "BUY";
              var Buy_Lng = "BUY Lng";
              var Buy_Cvr = "BUY Cvr";
              var EOD_Buy = "BUY EOD";
              var EOD_Sell = "SELL EOD";
              var DOJI_Mess ="DOJI";
              var BearP_Rising = "Buying Opp";
              var BullP_Falling = "Selling Opp";
              function preMain() {
              setPriceStudy(false);
              setColorPriceBars(true);
              setDefaultPriceBarColor(Color.khaki);
              setStudyTitle("L/T Trend");
              /* setCursorLabelName("MA(13,C)e",0);
              setDefaultBarFgColor(Color.black,0);setDefaultBarS tyle( PS_DASH, 0 );
              setDefaultBarThickness(2,0);*/
              setCursorLabelName("Up",0);
              setDefaultBarFgColor(Color.green,0);
              setCursorLabelName("Down",1);
              setDefaultBarFgColor(Color.red,1);

              setComputeOnClose(true);
              }

              function PriceBarColors() {
              if (close() > open()) setPriceBarColor(Color.lime)
              else
              if (close() < open()) setPriceBarColor(Color.red);

              return;
              }

              function MACDHistTrendUp()
              { if ( (vMACD_Hist >= vMACD_Hist_1) /* && (vMACD_Hist_1 >= vMACD_Hist_2)*/ )
              return true;
              }
              function MACDHistTrendDown()
              {
              if ( (vMACD_Hist <= vMACD_Hist_1) /* && (vMACD_Hist_1 <= vMACD_Hist_2)*/ )
              return true;
              }
              function MATrendUp()
              { if ( (vEMA >= vEMA_1) && (vEMA_1 >= vEMA_2) )
              return true;
              }
              function MATrendDown()
              { if ( (vEMA <= vEMA_1) && (vEMA_1 <= vEMA_2) )
              return true;
              }

              function main()
              {
              /*var DownTrend = false;
              false; */


              vEMA = EMA.getValue(MAStudy.MA,0);
              vEMA_1 = EMA.getValue(MAStudy.MA,-1);
              vEMA_2 = EMA.getValue(MAStudy.MA,-2);
              vMACD = MACD.getValue(MACDStudy.MACD);
              vMACD_Signal = MACD.getValue(MACDStudy.SIGNAL);
              vMACD_Hist = MACD.getValue(MACDStudy.HIST,0);
              vMACD_Hist_1 = MACD.getValue(MACDStudy.HIST,-1);
              vMACD_Hist_2 = MACD.getValue(MACDStudy.HIST,-2);

              if ( (MACDHistTrendDown()) && (MATrendDown()) )
              TrendIsDown=true
              else TrendIsDown = false;



              if ( (MACDHistTrendUp()) && (MATrendUp()) )
              TrendIsUp = true
              else TrendIsUp = false ;
              /*debugPrint("UP",TrendIsUp);debugPrint("DN",TrendI sDown)
              debugPrint("MACD",MACDHistTrendDown());debugPrint( "MA",MATrendDown());
              debugPrint(MACDHistTrendUp());debugPrint(MATrendUp ());*/

              setGlobalValue("gvTrendIsUp",TrendIsUp);setGlobalV alue("gvTrendIsDown",TrendIsDown);
              UpTrend=getGlobalValue("gvTrendIsUp");
              DownTrend=getGlobalValue("gvTrendIsDown");

              PriceBarColors();
              /* UpTrend=true;DownTrend=false;*/
              debugPrint("Bar " + getCurrentBarIndex()+" UpTrend= " + UpTrend + " DownTrend= " + DownTrend + "\n" );

              return new Array (UpTrend,DownTrend);
              //*******Second EFS *********
              var study = new StochStudy(5, 3, 3);
              var UBand = 80;
              var LBand = 20;
              var At =' @';
              var blank =' ';
              var Buy = "BUY"
              var Sell = "SELL";
              var Sell_Short = "SELL Shrt";
              var Flat = "FLAT";
              var Order_Stat = Flat;


              function preMain() {;
              setPriceStudy(false);
              setColorPriceBars(true);
              setDefaultPriceBarColor(Color.khaki);
              setStudyMin(0);
              setStudyMax(100);
              var LBand = 20;
              var UBand = 80;
              addBand(LBand, PS_SOLID, 1, Color.black, "20");
              addBand(UBand, PS_SOLID, 1, Color.black, "80");
              setDefaultBarFgColor(Color.red, 0);

              setDefaultBarFgColor(Color.green, 1);
              setStudyTitle("S/T Trend");
              setCursorLabelName("%K(5)",0); // %K
              setDefaultBarFgColor(Color.red,0); // %D
              setCursorLabelName("%D(3)",1);
              setDefaultBarFgColor(Color.green,1);
              setCursorLabelName("STATUS:",2); //
              setDefaultBarFgColor(Color.khaki,2); //

              setComputeOnClose(true);

              }
              function PriceBarColors() {
              if (close() > open()) setPriceBarColor(Color.lime)
              else
              if (close() < open()) setPriceBarColor(Color.red);

              return;
              }

              function BuyMessage(Mess) {
              vHL = .25*(high() - low());vVar = vHL * 1.75; vAddVar = vVar * 0.35;
              var Buy_Mess = "BUY_STOP"+blank+getSymbol()+At+Math.max((high(0), high(0)));
              setBarFgColor(Color.black,0);setBarFgColor(Color.b lack,1);
              setBarThickness(2,0);setBarThickness(2,1);setBarBg Color(Color.green);
              Alert.addToList(getSymbol(),Buy_Mess, Color.green, Color.lightgrey );
              Alert.playSound("cashreg.wav");
              Alert.email(Buy_Mess);
              drawShapeRelative(0, low() - vVar, Shape.UPARROW,null, Color.lime,null,null);
              drawTextRelative(-1, low() - (vVar + vAddVar), (Mess+At+/*formatPriceNumber*/ (close())),
              Color.black, Color.lime,Text.BOLD | Text.ONTOP, null, null);
              Order_Stat = Buy;

              return ;
              }
              function SellMessage(Mess) {
              vHL = .25*(high() - low());vVar = vHL * 1.75; vAddVar = vVar * 0.35;
              var Sell_Mess = "SELL_STOP"+blank+getSymbol()+At+Math.min((low (-0),low(-0)));
              setBarFgColor(Color.black,0);setBarFgColor(Color.b lack,1);
              setBarThickness(2,0); setBarThickness(2,1); setBarBgColor(Color.red);
              Alert.addToList(getSymbol(),Sell_Mess, Color.red, Color.lightgrey );
              Alert.playSound("cashreg.wav");
              Alert.email(Sell_Mess);
              drawShapeRelative(0, high() + vVar, Shape.DOWNARROW,null, Color.red, null,null);
              drawTextRelative(-1, high() + (vVar + vAddVar), ( Mess+At+/*formatPriceNumber*/(close())),
              Color.black, Color.red,Text.BOLD | Text.BOTTOM, null, null);
              Order_Stat = Sell;

              return null;
              }
              function main() { /*call( "\\elder\\##longer_term.efs"); debugPrint("Called"); */
              var InPosition;
              var vFast = study.getValue(StochStudy.FAST);
              var vSlow = study.getValue(StochStudy.SLOW);



              var x = getGlobalValue("UpTrend");debugPrint(x);
              var y = getGlobalValue("DownTrend");
              /* if (getCurrentBarIndex() != 0)*/
              /*debugPrint("Bar " + getCurrentBarIndex()+" UpTrend= " + x + " DownTrend= " + y + "\n" );*/
              /*x = true; y=true; */

              if (x) //Longer term timeframe Trending Up
              if ((vFast <= LBand) && (vSlow <= LBand)) //ST Oversold
              {
              BuyMessage(Buy); InPosition = true;
              }

              if (y) //Longer term timeframe Trending Down
              if ((vFast >= UBand) && (vSlow >= UBand)) //ST Overbot
              {
              SellMessage(Sell) ;InPosition = true;
              }
              if (!InPosition) Order_Stat = Flat;
              PriceBarColors();
              return new Array(vFast, vSlow, Order_Stat);

              Comment


              • #8
                Hello,

                Can someone please confirm that this triple screen formula works. If so would it be possible for someone to post it so that I can check it out.

                Cheers

                Carlton

                Comment


                • #9
                  Carlton
                  Attached is the L/T Trend ie the "called" efs.
                  Alex
                  Attached Files

                  Comment


                  • #10
                    And here is the S/T Trend ie the "calling" efs.
                    I would suggest you go through the comments/explanations from both George and Garth regarding using the efs outside of real time mode
                    Alex
                    Attached Files

                    Comment

                    Working...
                    X