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
	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;


//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;

Leave a Reply