用WLD测试多系统

Discussion in 'Wealth-Lab Developer' started by ilian, Oct 27, 2007.

?

请投票!

  1. 有用,谢谢!

    50 vote(s)
    64.1%
  2. 路过,看看。

    28 vote(s)
    35.9%
  1. 用WLD测试多系统的脚本要不要写在studies的目录下????????
     
  2. 运行的时候 为什么会出现显示 Couldn't find file"EasyMultiSystem" on input paths
     
  3. 你可能要设置一下那个“EasyMultiSystem”的地址,它的物理存贮地址可能跟你指定的位置不相符
     
  4. EasyMultiSystem是什么含义 如何设置呢?
     
  5. EasyMultiSystem是什么意思呢,谢谢!
     
  6. 08年6月提出这个问题,到现在还没有解决,焦急啊! 有没有人详细告诉我一下!
     
  7. 名为EasyMultiSystem的脚本要在studies目录下,同样你要测试的系统也要在studies目录下。
    提示“Couldn't find file"EasyMultiSystem" on input paths ”是说名为EasyMultiSystem的脚本在studies目录下找不到,如果没有,你在wld-->Community--Download ChartScripts中把所有的ChartScripts都下载过来,那么studies目录下肯定会有EasyMultiSystem。
     
  8. EasyMultiSystem的脚本是不是:

    WealthScript Code
    // ******* Get Slippage Settings

    var Slippage: float;
    var LimitOrders: boolean;
    begin
    var c: float = PriceClose(0);
    var o: float = PriceOpen(1);
    var h: float = PriceHigh(1);
    var l: float = PriceLow(1);
    @#Close[0] := 500;
    @#Open[1] := 500;
    @#High[1] := 1000;
    @#Low[1] := 250;
    BuyAtMarket(1, '');
    Slippage := 2 * PositionEntryPrice(0) - 1000;
    BuyAtLimit(1, 250, '');
    LimitOrders := (PositionCount < 2);
    ClearPositions;
    @#Close[0] := c;
    @#Open[1] := o;
    @#High[1] := h;
    @#Low[1] := l;
    end;


    // ****** Class definition: "List of Positions"

    type TPosition = class
    Long: boolean;
    Shares: integer;
    Symbol: string;
    OrderType: integer;
    BasisPrice: float;
    SignalName: string;
    Data: float;
    Priority: float;
    RiskStop: float;
    GlobalPosition: integer;
    ExitPrice: float;
    ExitSignalName: string;
    end;

    type TPositionList = class(TList)
    function AddPosition(p: integer): integer;
    procedure Execute(Date, p: integer);
    end;

    function TPositionList.AddPosition(p: integer): integer;
    begin
    var Position: TPosition = TPosition.Create;
    Position.Long := PositionLong(p);
    Position.Shares := PositionShares(p);
    Position.Symbol := PositionSymbol(p);
    Position.OrderType := PositionOrderType(p);
    Position.BasisPrice := PositionBasisPrice(p);
    Position.RiskStop := GetPositionRiskStop(p);
    Position.SignalName := PositionSignalName(p);
    Position.Data := GetPositionData(p);
    Position.Priority := GetPositionPriority(p);
    Position.GlobalPosition := -1;
    Position.ExitPrice := PositionExitPrice(p);
    Position.ExitSignalName := PositionExitSignalName(p);
    AddObject(0, Position);
    Result := Count;
    end;

    procedure TPositionList.Execute(Date, p: integer);
    begin
    if p > 0 then
    begin
    // Entry
    var Position: TPosition = Object(p - 1) as TPosition;
    SetPrimarySeries(Position.Symbol);
    var Bar: integer = DateToBar(Date);
    SetShareSize(Position.Shares);
    SetRiskStopLevel(Position.RiskStop);
    var ok: boolean;
    // use original orders and slippage, so that $imulator will know about BasisPrice
    SetSlippage(true, Slippage, LimitOrders);
    case Position.OrderType of
    0: if Position.Long then ok := BuyAtMarket(Bar, Position.SignalName)
    else ok := ShortAtMarket(Bar, Position.SignalName);
    1: if Position.Long then ok := BuyAtStop(Bar, Position.BasisPrice, Position.SignalName)
    else ok := ShortAtStop(Bar, Position.BasisPrice, Position.SignalName);
    2: if Position.Long then ok := BuyAtLimit(Bar, Position.BasisPrice, Position.SignalName)
    else ok := ShortAtLimit(Bar, Position.BasisPrice, Position.SignalName);
    3: if Position.Long then ok := BuyAtClose(Bar, Position.SignalName)
    else ok := ShortAtClose(Bar, Position.SignalName);
    end;
    if ok then
    begin
    Position.GlobalPosition := LastPosition;
    SetPositionData(LastPosition, Position.Data);
    SetPositionPriority(LastPosition, Position.Priority);
    end;
    end
    else
    begin
    // Exit
    var Position: TPosition = Object(-p - 1) as TPosition;
    p := Position.GlobalPosition;
    if p >= 0 then // entry was successful...
    begin
    SetPrimarySeries(Position.Symbol);
    var Bar: integer = DateToBar(Date);
    // OrderType is unknown for exits, therefore we have to do an "ExitAtPrice"
    SetSlippage(false, 0, false); // slippage was already included into ExitPrice
    if Position.Long then
    if Position.ExitPrice > PriceOpen(Bar) then
    SellAtLimit(Bar, Position.ExitPrice, p, Position.ExitSignalName)
    else
    SellAtStop(Bar, Position.ExitPrice, p, Position.ExitSignalName)
    else
    if Position.ExitPrice < PriceOpen(Bar) then
    CoverAtLimit(Bar, Position.ExitPrice, p, Position.ExitSignalName)
    else
    CoverAtStop(Bar, Position.ExitPrice, p, Position.ExitSignalName);
    end;
    end;
    end;

    var PositionList: TPositionList = TPositionList.Create;


    // ****** Class definition: "List of Trades"

    type TTradeList = class(TList)
    procedure AddTrade(Timestamp: float; Trade: integer);
    procedure Execute(Trade: integer);
    end;

    procedure TTradeList.AddTrade(Timestamp: float; Trade: integer);
    begin
    AddData(Timestamp, Trade);
    end;

    procedure TTradeList.Execute(Trade: integer);
    begin
    PositionList.Execute(trunc(Item(Trade)), Data(Trade));
    end;

    var TradeList: TTradeList = TTradeList.Create;


    // ****** Class definition: "List of Alerts"

    type TAlert = class
    PositionType: integer;
    Shares: integer;
    Symbol: string;
    OrderType: integer;
    Price: float;
    SignalName: string;
    Position: integer;
    end;

    type TAlertList = class(TList)
    procedure AddAlert(a: integer);
    procedure Execute(a: integer);
    end;

    var GetScriptName: string; // overrides WL's builtin method

    procedure TAlertList.AddAlert(a: integer);
    begin
    var Alert: TAlert = TAlert.Create;
    Alert.PositionType := AlertPositionType(a);
    Alert.Shares := AlertShares(a);
    Alert.Symbol := AlertSymbol(a);
    Alert.OrderType := AlertOrderType(a);
    Alert.Price := AlertPrice(a);
    // RiskStop? sorry, not available :( we need a new function: AlertRiskStop
    // SignalName? sorry, not available :( we need a new function: AlertSignalName
    Alert.SignalName := GetScriptName; // at least, show which system generated this alert...
    // match exit alerts to corresponding active positions
    case Alert.PositionType of
    1:
    begin
    var p : integer = LastActivePosition + 1;
    for a := 1 to ActivePositionCount do
    begin
    repeat p := p - 1; until PositionActive(p);
    if PositionLong(p) then
    if PositionSymbol(p) = Alert.Symbol then
    if PositionShares(p) = Alert.Shares then
    begin
    Alert.Position := PositionList.Count - PositionCount + p;
    break;
    end;
    end;
    end;
    3:
    begin
    var p : integer = LastActivePosition + 1;
    for a := 1 to ActivePositionCount do
    begin
    repeat p := p - 1; until PositionActive(p);
    if PositionShort(p) then
    if PositionSymbol(p) = Alert.Symbol then
    if PositionShares(p) = Alert.Shares then
    begin
    Alert.Position := PositionList.Count - PositionCount + p;
    break;
    end;
    end;
    end;
    end;
    AddObject(0, Alert);
    end;

    procedure TAlertList.Execute(a: integer);
    begin
    var Alert: TAlert = Object(a) as TAlert;
    SetPrimarySeries(Alert.Symbol);
    var Bar: integer = BarCount;
    SetShareSize(Alert.Shares);
    case Alert.PositionType of
    0:
    begin
    case Alert.OrderType of
    0: BuyAtMarket(Bar, Alert.SignalName);
    1: BuyAtStop(Bar, Alert.Price, Alert.SignalName);
    2: BuyAtLimit(Bar, Alert.Price, Alert.SignalName);
    3: BuyAtClose(Bar, Alert.SignalName);
    end;
    end;
    1:
    begin
    var Position: TPosition = PositionList.Object(Alert.Position) as TPosition;
    var p: integer = Position.GlobalPosition;
    if p >= 0 then
    case Alert.OrderType of
    0: SellAtMarket(Bar, p, Alert.SignalName);
    1: SellAtStop(Bar, Alert.Price, p, Alert.SignalName);
    2: SellAtLimit(Bar, Alert.Price, p, Alert.SignalName);
    3: SellAtClose(Bar, p, Alert.SignalName);
    end;
    end;
    2:
    begin
    case Alert.OrderType of
    0: ShortAtMarket(Bar, Alert.SignalName);
    1: ShortAtStop(Bar, Alert.Price, Alert.SignalName);
    2: ShortAtLimit(Bar, Alert.Price, Alert.SignalName);
    3: ShortAtClose(Bar, Alert.SignalName);
    end;
    end;
    3:
    begin
    var Position: TPosition = PositionList.Object(Alert.Position) as TPosition;
    var p: integer = Position.GlobalPosition;
    if p >= 0 then
    case Alert.OrderType of
    0: CoverAtMarket(Bar, p, Alert.SignalName);
    1: CoverAtStop(Bar, Alert.Price, p, Alert.SignalName);
    2: CoverAtLimit(Bar, Alert.Price, p, Alert.SignalName);
    3: CoverAtClose(Bar, p, Alert.SignalName);
    end;
    end;
    end;
    end;

    var AlertList: TAlertList = TAlertList.Create;


    // ******* function to collect Trades and Alerts after a system has been executed

    procedure GetTradesAndAlerts;
    begin
    var p, t, a: integer;
    for p := 0 to PositionCount - 1 do
    begin
    t := PositionList.AddPosition(p);
    // force AtMarket orders to be executed before AtStop, then AtLimit and finally AtClose
    TradeList.AddTrade(GetDate(PositionEntryBar(p)) + PositionOrderType(p) / 4, t);
    // force all exits to be executed after that bar's entries (but before AtClose entries)
    if not PositionActive(p) then TradeList.AddTrade(GetDate(PositionExitBar(p)) + 5 / 8, -t);
    end;
    for a := 0 to AlertCount - 1 do AlertList.AddAlert(a);
    // restore a clean environment for next system
    RestorePrimarySeries;
    ClearPositions;
    ClearIndicators;
    ClearExternalSeries('');
    InstallBreakEvenStop(0);
    InstallProfitTarget(0);
    InstallReverseBreakEvenStop(0);
    InstallStopLoss(0);
    InstallTimeBasedExit(0);
    InstallTrailingStop(0, 0);
    end;


    // ******* function to re-execute all collected Trades and Alerts

    procedure ExecuteAllTradesAndAlerts;
    begin
    var t, a: integer;
    TradeList.SortNumeric;
    for t := 0 to TradeList.Count - 1 do TradeList.Execute(t);
    // Alerts
    for a := 0 to AlertList.Count - 1 do AlertList.Execute(a);
    RestorePrimarySeries;
    SetSlippage(true, Slippage, LimitOrders);
    end;


    // ******* redefine CreatePane and PlotSeries as no-ops
    // (dont let the systems compete for their own charting, it could be a real mess...)

    function RealCreatePane(Height: integer; AbovePrices, ShowGrid: boolean): integer;
    begin
    Result := CreatePane(Height, AbovePrices, ShowGrid);
    end;

    function CreatePane(Height: integer; AbovePrices, ShowGrid: boolean): integer;
    begin
    Result := RealCreatePane(1, true, false);
    end;

    procedure PlotSeries(Series, Pane, Color, Style: integer);
    begin
    end;

    procedure PlotSeriesLabel(Series, Pane, Color, Style: integer; Label: string);
    begin
    end;
     
  9. 还是应该是:
    {$I 'EasyMultiSystem'}

    // wrapping each system into a separate function:

    procedure TS_An_easier_seventeen_liner;
    begin
    GetScriptName := 'An easier seventeen-liner';
    {$I 'An easier seventeen-liner'}
    GetTradesAndAlerts;
    end;

    procedure TS_3L2O3_single_positions;
    begin
    GetScriptName := '3L2O3 - single positions';
    {$I '3L2O3 - single positions'}
    GetTradesAndAlerts;
    end;

    procedure TS_HiLoLimit_friendly_4;
    begin
    GetScriptName := 'HiLoLimit friendly 4';
    {$I 'HiLoLimit friendly 4'}
    GetTradesAndAlerts;
    end;

    procedure TS_noname; // you can also define a system "inline", rather than including an existing one
    begin
    GetScriptName := 'noname';
    var Bar, a, p: integer;
    for Bar := 90 to BarCount - 1 do
    begin
    p := LastActivePosition + 1;
    for a := 1 to ActivePositionCount do
    begin
    repeat p := p - 1; until PositionActive(p);
    var Decay: float = 4/5 + ln(Bar + 1 - PositionEntryBar(p));
    var LimitPrice: float = PriceOpen(Bar) + 0.9 * ATR(Bar, 9) / decay;
    if (PriceClose(Bar) > LimitPrice) then
    SellAtMarket(Bar + 1, p, '');
    end;
    if Highest(Bar, RSISeries(#Close, 30), 30) > 60 then
    BuyAtLimit(Bar + 1, PriceClose(Bar) - 0.9 * ATR(Bar, 9), '');
    end;
    GetTradesAndAlerts;
    end;

    // running each system sequentially, while collecting their trades and alerts
    TS_An_easier_seventeen_liner;
    TS_3L2O3_single_positions;
    TS_noname;
    TS_HiLoLimit_friendly_4;

    // re-playing all collected trades and alerts
    ExecuteAllTradesAndAlerts;
     
  10. 问题解决了,谢谢ilian!
     
  11. 那在分钟线上不能交易的问题解决了吗?
     
  12. 这个script有更新吗?
     
  13. 你在问我吗?我今天才发现不能在分钟线上交易的问题
     
  14. 没有使用分钟线交易,一直是日K线交易.
     
  15. 显然是很有含金量的贴子。 支持楼主