Problem Understaning the EL Code

Discussion in 'Strategy Development' started by dima888, Mar 27, 2008.

  1. dima888


    Hi there!
    I am having a difficulty understanding the following easylanguage code so I hope you can help me. The code instructs TS o buy when the moving average slopes up or down at an upper/lower band but in fact the trades are initiated when if the price doesn’t reach these bands – as if shown at the picture that I attached. I wonder what is the purpose of this upBand and dnBand functions. Looking forward to your help!

    The code:
    {King Keltner by George Pruitt—based on trading system presented by Chester
    Inputs: avgLength(40), atrLength(40);
    Vars: upBand(0),dnBand(0),liquidPoint(0),movAvgVal(0);
    movAvgVal = Average(Close,avgLength);
    upBand = movAvgVal + AvgTrueRange(atrLength);
    dnBand = movAvgVal - AvgTrueRange(atrLength);
    if(movAvgVal > movAvgVal[1]) then Buy ("KKBuy") tomorrow at upBand stop;
    if(movAvgVal < movAvgVal[1]) then Sell Short("KKSell") tomorrow at dnBand
    liquidPoint = movAvgVal;
    If(MarketPosition = 1) then Sell tomorrow at liquidPoint stop;
    If(MarketPosition = -1) then Buy To Cover tomorrow at liquidPoint stop;

    • pic.jpg
      File size:
      75.4 KB
  2. oTzt


    Hi Dima,

    The code is quite clear :
    Draw a 40 days SMA and compute the ATR (same length)
    Then, each day :
    If SMA(today) is above SMA(yestreday) Then put an instruction to enter ("Stop") tomorow at the value of todays SMA + 2 ATR (the value of the upper band is the price at which you intend to open a position. It will be openned only if tomorrows price reaches this value);
    Same test on the opposite side.

    And, each day :
    If there is position openned (long or short), then close it if the price reaches the SMA(today) price.

    I'd be surprised if this system was realy consistently producing money. Openning positions opposite to the trend at 2 ATR seems a bit like saying : "Prices, which are assumed to be normally distributed, having gone outside 2SD, have become outliers (under a statistical point of vue) and will go back to "normal".
    This seems a bit presomptuous.

    Hope this helped,
  3. dima888


    thank you for the detailed reply...but as oyu will see in the attached picture prices sometimes DO NOT reach the upper or the lower band before the trade is initiated..this is what confusing me...((((
  4. oTzt



    I didn't pay attention to that. Effectively, the 2nd and third "KKBuy" seem to be executed whereas the upper band has not been touched.
    I don't know why. Maybe a question of "tick" or something similar (rounding errors ?)

  5. The problem is that your code for the bands probably don't match the system code or the parameters. Post the indicator code so that a better evaluation can be made. This kind of system usually loses in the current environment, anyway.
  6. Let's say *today* that the upperband is at a value of 995 and is rising which conditions your system to buy tomorrow.
    Now, the band value tomorrow is 1000 and the price is 996.
    The system will BUY because on the day the "trigger/decision" was made, the band's value was 995 and today the price is 996, even though when you look at the band, the price did not touch it.

    If that's what you want, then you need to modify the code.
    Attached is a pic of the same system...

  7. FWIW, if you have a question about EL code, it makes much more sense to ask the Tradestation community. You will get a much quicker and better answer. You can find the forums here:

    Best of luck!
  8. Don't you need an account with them to log in? It asks for a username/password.

  9. I believe a subscription account will do. If not, TS needs to resolve that quickly as subscription accounts are paying customers.
  10. I'll stick with 2000i, thanks. It can do some things ts8 still can't. And it's free.

    #10     Mar 28, 2008