# Pyramaniac

Code to pyramid up to N contracts on a day trade basis.

```input: maxSize(5),startTime(1000),endTime(1555);
var: stb(0),sts(0),tpAmt(0),lprft(0),sprft(0);

stb = High + minMove/priceScale;
sts = Low - minMove/priceScale;

print(date," ",time," ",stb," ",sts," ",currentShares);

if (time > startTime and time < endTime ) then
begin
tpAmt = average(range,10);
if(high>high[1]) then lprft = highD(0)+1*tpAmt;
if(low < low[1]) then sprft = lowD(0) -1*tpAmt;
if(currentShares < maxSize and c < average(c,9) and low < low[1] and close < close[1]) then buy("pyrabuy")next bar at sts limit;
if(currentShares < maxSize and c < average(c,9) and high >high[1] and close > close[1]) then sellShort("pyrasell") next bar at stb limit;

end;

//if(currentShares >= maxSize and marketPosition = 1) then sell("longmaxliq") next bar sts stop;
//if(currentShares >= maxSize and marketPosition =-1) then buyToCover("shortmaxliq") next bar stb stop;
if(marketPosition = 1) then sell("longProf") next bar lprft limit;
if(marketPosition =-1) then buytoCover("shortProf") next bar at sprft limit;
setexitonclose;```

## 2 thoughts on “Pyramaniac”

1. D G says:

Hi George!
Is there a way to exit a scaled-in (pyramided) strategy in one single order? Say your strategy is set to \”allow up to [n] entry orders\” as configured in the Strategy Properties.

Let\’s say you\’ve set it to [7]. Your strategy goes out there and accumulates 7 separate signals/buy orders. Then your strategy generates a sell signal. Currently, TS will issue 7 individual sell orders for each of the 7 buys. This is expensive.

What could be done in the strategy code to make it possible to SUM or TOTAL all shares from the 7 buys and then to send a single sell order covering all shares?

Thank you!

1. Hello D G – sorry for the late reply. Is it issuing N exit orders during automation? If automation is on and you turn it off does it still proffer N exit orders in the TradeManager window – via simulation? Again sorry for the delay in my response. Just let me know and/or if you figured it out.
Best George