Sterling VBA Trade Management

Discussion in 'Trading Software' started by Mike805, Sep 7, 2011.

  1. Hello All,

    Over the last few years I've developed some simple VBA code to route and manage trades to Sterling using the API, most of it is done in VBA and some of it is done in C#.

    One of the functions that I would like to implement via the API in my VBA code base is the "Close 25% (or 50%,75%,100%) of open longs/shorts at MKT". This is an "clickable" option in the Position Summary window.

    Does anyone know how to do this effectively? Do I have to write code that pulls all the positions, does all the pertinent calculations, and then sends out orders? This seems like reinventing the wheel since Sterling has those functions built in.

    Has anyone written code like this before, or, where you able to utlize those built in functions? If the code exists somewhere, can someone point me to the source?

    Thanks in advance for any advice.

  2. here is how to do it in tradelink

    this will work w/any of 17 brokers in tradelink including sterling

    tradelink is open source so you can checkout the code also.

    public class MyResponse : ResponseTemplate
       void GotTick(Tick k)
             // get pl for position
             decimal pl = Calc.OpenPL(,pt[f.symbol]);
             // if PL above 1%, close 25%
             if (pl>pt[f.symbol].AvgPrice*.01)
                 sendorder(new MarketOrderFlat(pt[f.symbol],Calc.Norm2Min(pt[f.symbol].Size*.25m,100));
             // close half if over 5%
                 if (pl>pt[f.symbol].AvgPrice*.05)
                 sendorder(new MarketOrderFlat(pt[f.symbol],Calc.Norm2Min(pt[f.symbol].Size*.50m,100));
             // close all if over 10%
             if (pl>pt[f.symbol].AvgPrice*.1)
                 sendorder(new MarketOrderFlat(pt[f.symbol]);
       PositionTracker pt = new PositionTracker();
       override void GotFill(Trade f) { pt.Adjust(f); }
       override void GotPosition(Position p) { pt.Adjust(p); }
    google tradelink project or for more info