Wealth-Lab script language questions:

Discussion in 'Strategy Development' started by Sanjuro, Sep 30, 2002.

  1. Sanjuro


    I was reading through their examples and I don't understand
    why Every Trading System needs a loop? I'm a C/C++ programmer so it's not the language I don't understand.
    What is the loop for?
    Can't you say to just use the 15 SMA for the current bar?
    Also, is Bar variable integer the current bar?
    Bar + 1, is that the next bar?

    If Bar is 30 to barcount - 1,
    What does that go up to? How many bars are in barcount?

    Thanks for any information you can help me with.

    Every Trading System must have a main loop that cycles through the data in your chart. This is accomplished with a typical "for loop", as shown below:


    var BAR: integer;
    { ChartScript Main Loop }
    for Bar := 30 to BarCount -1 do
    { Trading rules go here, and are executed once for every bar in the chart }
    Here, the for loop starts at the 30th bar of data. You should set your main loop's starting point based on the technical indicators that you're using. For example, if you use a 30 bar EMA and a 14 bar RSI in your rules, choose the longer of the two indicators and set your starting for loop value to 30. The main loop typically ends at BarCount - 1;
  2. Biomech


    When you open a chartscript or simulator window, there is a setting for how many bars you want to go back. If you set that to 250 bars, then that is what is used for Barcount (maybe 249, I forget). The loop is to loop through each of these bars and to test your script against them. A breakout system, for example, would check every bar to see if it was higher or lower than the last x bars, and if it was you execute your entry rules.

    There is a ton of info on this kind of thing on the forums at www.wealth-lab.com. Glitch and company answer questions posted there and are always very helpful.