Announcement

Collapse
No announcement yet.

Getting data from a non-price study to the price chart

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

  • Getting data from a non-price study to the price chart

    I have developed an oscillator in a non-price study that is processor intensive to calculate (so I don't want to duplicate it in the price chart) and a nice way to display it there. What I would like to do is generate a variable in that study that is either +1, -1 or zero when certain conditions are met, and get that variable to the main price study chart so that I can display a green or red bar in the background using setBarBgColor(), or another function. The whole point is that when my non-price oscillator makes a buy or sell signal, that a corresponding green or red bar appears on the main price chart so it is as obvious as possible for me to see.

    I have worked with EFS for several years and it seems like each study (price or non-price) is a little world unto itself - how do I get data from one to another?

  • #2
    Hello traderslomo,
    I wrote an example tonight for you that uses a stochastic crossover to color the bars red and green and also to put the difference between the %k and %d value on the chart for you so that you can see the possibilities. I also uploaded a notepad file of the code since pasting stuff here sometimes isn't exactly accurate. You should be able to use this with any calculations that you want to use...enjoy!

    function preMain(){
    setPriceStudy(true);
    setStudyTitle("Stochastic Bar Painter")
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.grey);
    }

    function main(){
    if(getBarState() == BARSTATE_ALLBARS) nStochDifference = null;
    if(getCurrentBarCount() < 14 + 3 + 3) return;

    nStochDifference = stochK(14,3,3) - stochD(14,3,3);

    if(nStochDifference > 0) setPriceBarColor(Color.green);
    else setPriceBarColor(Color.RGB(192, 0, 0));

    if(nStochDifference > 0)
    drawTextAbsolute(0, TopRow1, nStochDifference.toFixed(3), Color.RGB(0,192,0),
    null, Text.PRESET|Text.CENTER, "Courier New", 12, "StochDiff");
    else
    drawTextAbsolute(0, TopRow1, nStochDifference.toFixed(3), Color.RGB(192,0,0),
    null, Text.PRESET|Text.CENTER, "Courier New", 12, "StochDiff");
    return;
    }

    /*
    NOTE: You could add another number next to it if you wanted to. The key is for
    "StochDiff"and "Var2" to have different names that are static...unlike
    "StochDiff"+rawtime(0) which will put a value on every bar.

    if(nStochDifference > 0)
    drawTextAbsolute(-15, TopRow1, AnotherVar.toFixed(2), Color.RGB(0,192,0),
    null, Text.PRESET|Text.CENTER, "Courier New", 12, "Var2");
    else
    drawTextAbsolute(-15, TopRow1, AnotherVar.toFixed(2), Color.RGB(192,0,0),
    null, Text.PRESET|Text.CENTER, "Courier New", 12, "Var2");
    */
    Attached Files

    Comment


    • #3
      Another approach that you could use would be to use efsExternal like below:

      var xSeriesVarName; // Global variable

      main(){
      if(getBarState() == BARSTATE_ALLBARS){
      var nSeriesVarName = null;
      xSeriesVarName = efsExternal("YourEFS.efs" [,comma separated main() parameters] [, sym() | inv() ]);
      }
      nSeriesVarName = xSeriesVarName.getValue(0);
      ...Your Code;
      }

      // If you don't have any main() parameters and don't want to specify
      // the symbol or interval then you would just use: efsExternal("YourEFS.efs")
      // For more info go to: https://kb.esignal.com/article.aspx?article=1206&p=4

      Comment


      • #4
        LetUsLearn,

        I really appreciate all your posts as they are very helpful. I've been a member of this board for more then 10 years. Years ago this board was much more active with an amazing dialogue on a daily basis with people such as yourself generously helping the rest of us out.

        I never really understood the purpose of the efsExternal and efsInternal functions and when one would use each of those versus a building function?

        Thank very much.

        Glen
        Glen Demarco
        [email protected]

        Comment


        • #5

          Glen
          You may want to start reading this thread (posted about 15 years ago when the EFS2 functions were introduced) and then continue by doing a search through the forums for efsInternal or efsExternal as these topics have been discussed at nauseam with plenty of examples
          Alex


          Originally posted by demarcog View Post
          LetUsLearn,

          I really appreciate all your posts as they are very helpful. I've been a member of this board for more then 10 years. Years ago this board was much more active with an amazing dialogue on a daily basis with people such as yourself generously helping the rest of us out.

          I never really understood the purpose of the efsExternal and efsInternal functions and when one would use each of those versus a building function?

          Thank very much.

          Glen

          Comment


          • #6
            Hello Glen,
            You are welcome! From what you have said I assume that you understand now, but in case that I’m mistaking, let me say that you would use efsInternal() to create a series object out of one of the functions in the efs code that you have in main() and you would use efsExternal() to access the series objects that main() returns from other efs programs that you have created outside of your current main() program. Just make sure that the external efs is in your “My Formula” folder in Interactive Data’s folder. I used to think that it could be in any of the “Formula” folders, but recently I tried to access a formula from the “My Download” folder and I got an error message that it couldn’t be found until I moved it to the “My Formula” folder…I’d swear that I didn’t have this problem before…maybe I’m mistaken? The benefit of a series object is that it gives you access to your function’s calculated values for all of the bars on the chart, and you can access them with their bar index just like everything else in eSignal…so create series objects when you want to access a prior bar’s values in your code!
            Like you, I wish there was more of a community of programmers with an active interest and discussion on this forum. I have seen your complaint about eSignal’s back-test quality, I used to wonder too, so over a period of a few years while testing various ideas I kind of built my own back-tester where I could define what I wanted to see. It evolved into where I would put 10, then 20 and now over 30 global variables into my program and then paste a lot of functions into it that would do all of the calculations. I liked it because I understood the results and could customize them into whatever I wanted. Recently I wanted to test some ideas out and thought that it was such a pain to paste all of this backend stuff into my programs just to test an idea out, so I went on a mission and created a library file where I put all of the generic global calculation-related variables that have nothing to do with the current program into a global object that I put into a library file with all of the functions that do the trades and printing of the results to eSignal’s formula output window. Now all I have to do is to put a reference in to the library file and I can access everything in my back-tester. I doubt that you want to hear this, but I have found that I get the exact same results as eSignal…the only difference is that my results only include closed out trades and eSignal includes open trade P/L in theirs. I might put this out there for others to use in the future. While mine only calculates the basics, like each trade time/price, PL, Total PL, Winners, Losers, Break Evens, Longs, Shorts, Long PL, Short PL, Profit Sum, Loss Sum, Average Profit, Average Loss, Number of Stop Losses. I used to have a TagExit and TagEntry variable to show me in which part of the code that caused a buy or sell to happen when I had a program that had a lot of branches and I wanted to know where the trades came from without having to painstakingly go through a chart to find out…so you can put anything you want into it, just try not to drowned in the data! The caveat of all of this, is that it can be difficult to understand another person’s code…but I really believe that it’s pretty straight-forward.
            Lastly let me say that I always have my “Formula Output” window up on one of my screens, since my back-tester isn’t really just a back-tester but a streaming picture of what your program is doing, and if it puts on a trade in real-time, then you’ll see it on the “Formula Output” window.

            Comment


            • #7
              LetUsLearn,

              Thank you for the lucid explanation. I did read the posts Alexis mentioned and it was not clear but you did a great job of explaining it.

              The only issue I have with eSignals backtester which is ignored by the forum/support and posted ad nauseam in a half a dozen well documented posts.

              It's quite clear that when using multiple time intervals the profits are grossly over inflated by orders of magnitude.

              It's incomprehensible that a product which paying customers use to make a living, owned by one of the biggest exchanges in the world, essentially falsely advertised the "multiple time interval" back testing capability.

              If you read my posts which I provided the actual strategy efs to tech support you will see the details.

              The problem is essentially any simple strategy with multiple time intervals, for example price closes above a 20 period sma on a 5, 15 and 45 minute interval with the strategy loaded on 5 minute chart. The strategy make no logical sense but to illustrate the problem the strategy goes long/short when price closes below the 20 period sma on both the 5, 15 and 45 minute intervals.

              The back testing report will look like you have found the holy grain of trading the winning percentage will be in the 70-80 percentage profitable range, which is virtually impossible when the strategy loaded into a 5 minute chart with two external intervals of 15 and 45 minutes with 3 20 period sma loaded as indicators.

              If you run the same strategy in a 5 minute chart without external intervals of 15 and 45 but rather a close above the 20, 60 and 180 periods (the 20 period approximate sma's equivalent on a 15 and 45 minute chart) you will get an entirely different abysmal profit performance.

              The problem unfortunately is neither fixed, documented or even acknowledged which I find most disheartening.


              Thanks again

              glen
              Last edited by demarcog; 03-11-2020, 09:58 AM.
              Glen Demarco
              [email protected]

              Comment

              Working...
              X