Scripts demonstrating different ways to set trade volumes and initiate trades

Scripts that demonstrate different ways of setting the volume of your trades (fixed quantity, percentage of ask volume, and dollar amount) are on the github here:
And scripts that demonstrate the different ways to initiate a trade in backtesting (market, limit order, midpont peg) are available here:
These are designed to introduce these different ways to new traders, so please post any feedback!


  • ptunneyptunney Posts: 246

    The code for these scripts is also available under PUBLIC SCRIPTS > GITHUB

  • Can somebody explain to me why do midpoint peg orders need price as an argument? Shouldn't their price be automatically set as (md.L1.ask + / 2?

  • aj165602aj165602 Posts: 105

    The way to think of a midpoint peg order is a midpoint limit order that adjusts in one direction only, until you are filled. The price you enter in the script determines how far you are willing to chase the market until you are filled.

  • Yes, it's effectively a limit on the price you will pay for the stock. It probably doesn't have much effect on backtesting.

  • @ns553697 if you backtest with >= ~$25M, it usually does and it should have, unless you only trade the most liquid stocks. ;)
    @aj165602 the reason I did not see a difference between a limit midpoint peg and a market pindpoint peg with some equities was that for these symbols, L1 data are missing!
    One example: HLT on the 4th of January 2017; can you solve the problem quicky? If not, I may provide you with more such examples or create a script to output them all - just message me on the KTG Tech Slack→ search for Martin Saip (martin_saip).

Sign In or Register to comment.