Logging and displaying trades

In real trading it is desirable to use a persistent trade record so that trades for multiple sessions be analyzed using the Backtester. The easiest way to do this is to save the trades in a composite. The code shown below is a simplified version of what will be used in the TDash system, however, it can be used with any trading system. This code requires you set Preferences -> Intraday -> “Time of first tick inside bar” or “START time of interval”. Apply the code to an empty pane, start Bar-Replay, and open the Parameter window. After placing some trades you can send the code to the Backtester for analysis. You can perform the following actions:

I use small solid triangles for Buy and Sell signals, and hollow triangles for Short and Cover signals. This allows me to overlay the Buy and Cover signals, and the Sell and Short signals, to display trade reversals. The triangles are placed at the actual trading price (the Close in this example). This is what the arrows look like:

_SECTION_BEGIN"USING A TRADE COMPOSITE" );
function DeleteCompositeCompositeName )
{
    global Ticker;
    oAB CreateObject"Broker.Application" );
    oStocks oAB.Stocks();
    oStocks.RemoveCompositeName );
    oAB.RefreshAll();
}

function  AddTradeToCompositeTickerActionLMTPrice )
{
    global Ticker;
    BI  BarIndex();
    LBI LastValueBI );

    if ( Action != "" )
    {
        SignalArray NzForeignTicker "~SignalArrays""V"False ) );
        BuyPriceArray NzForeignTicker "~SignalArrays""O"False ) );
        SellPriceArray NzForeignTicker "~SignalArrays""H"False ) );
        ShortPriceArray NzForeignTicker "~SignalArrays""L"False ) );
        CoverPriceArray NzForeignTicker "~SignalArrays""C"False ) );

        switch ( Action )
        {

            case "BUY":
                SignalArray[LBI] = SignalArray[LBI] | 1;
                BuyPriceArray[LBI] = LMTPrice;
                break;

            case "SELL":
                SignalArray[LBI] = SignalArray[LBI] | 2;
                SellPriceArray[LBI] = LMTPrice;
                break;

            case "SHORT":
                SignalArray[LBI] = SignalArray[LBI] | 4;
                ShortPriceArray[LBI] = LMTPrice;
                break;

            case "COVER":
                SignalArray[LBI] = SignalArray[LBI] | 8;
                CoverPriceArray[LBI] = LMTPrice;
                break;

            case "REVLONG":
                SignalArray[LBI] = SignalArray[LBI] | 1;
                CoverPriceArray[LBI] = BuyPriceArray[LBI] = LMTPrice;
                break;

            case "REVSHORT":
                SignalArray[LBI] = SignalArray[LBI] | 4;
                SellPriceArray[LBI] = ShortPriceArray[LBI] = LMTPrice;
                break;
        }

        AddToCompositeSignalArrayTicker "~SignalArrays""V"atcFlagEnableInIndicator );
        AddToCompositeBuyPriceArrayTicker "~SignalArrays""O"atcFlagEnableInIndicator );
        AddToCompositeSellPriceArrayTicker "~SignalArrays""H"atcFlagEnableInIndicator );
        AddToCompositeShortPriceArrayTicker "~SignalArrays""L"atcFlagEnableInIndicator );
        AddToCompositeCoverPriceArrayTicker "~SignalArrays""C"atcFlagEnableInIndicator );
    }
}

Ticker Name();
Action "";

if ( ParamTrigger"Buy""BUY" ) ) Action "BUY";
if ( ParamTrigger"Sell""SELL" ) ) Action "SELL";
if ( ParamTrigger"Short""SHORT" ) ) Action "SHORT";
if ( ParamTrigger"Cover""COVER" ) ) Action "COVER";
if ( ParamTrigger"Reverse to Long""REVLONG" ) ) Action "REVLONG";
if ( ParamTrigger"Reverse to Short""REVSHORT" ) ) Action "REVSHORT";
if ( ParamTrigger"Delete Signal Compoiste""DELETE" ) ) DeleteCompositeTicker "~SignalArrays" );
AddTradeToCompositeTickerActionLastValueClose ) );

RequestTimedRefresh0.1 );
if ( SetForeignTicker "~SignalArrays" ) )
{
    SignalArray    NzForeignTicker "~SignalArrays""V"False ) );
    Buy         IIfSignalArray 11);
    Sell         IIfSignalArray 21);
    Short         IIfSignalArray 41);
    Cover         IIfSignalArray 81);

    BuyPrice     NzForeignTicker "~SignalArrays""O" ) );
    SellPrice     NzForeignTicker "~SignalArrays""H" ) );
    ShortPrice    NzForeignTicker "~SignalArrays""L" ) );
    CoverPrice     NzForeignTicker "~SignalArrays""C" ) );

    PlotShapesIIfBuyshapeSmallUpTriangleshapeNone ), 50BuyPrice);
    PlotShapesIIfSellshapeSmallDownTriangleshapeNone ), 40SellPrice);
    PlotShapesIIfShortshapeHollowDownTriangleshapeNone ), 40ShortPrice);
    PlotShapesIIfCovershapeHollowUpTriangleshapeNone ), 50CoverPrice);

}
RestorePriceArrays();

PlotC""1128 );
_SECTION_END();

Comments are closed.