Buy n number of trades every single day till MaxOpenPositions is reached

Hello Coders, I am trying to Buy an Hold N number of shares, but I want to limit upto max 20 new position to be opened every single day and hold them all.
I tried this method, but it could not get me right.

SetOption("MaxOpenPositions", 1200);      	
SetOption("AllowSameBarExit", False);		
SetOption("AccountMargin", 100);            
SetOption("CommissionMode",1);             	
SetOption("CommissionAmount",0.3);        	
SetOption("usecustombacktestproc", False); 	
SetOption("HoldMinBars", 1);
SetTradeDelays(1, 1, 1, 1);
RoundLotSize = 1;

Filter 		= 

// Max trades limit EVERY SINGLE DAY untill MaxOpenPositions is reached
N = 20;

SETUP =  Month() != 9;

Buy	=	SETUP;

Sell = 0; 


PlotShapes( Buy*shapeUpArrow, colorYellow, 0, Low );
PlotShapes( Sell*shapeDownArrow, colorred, 0, High );

tradeCount = onBuy = 0;

for( i = 0; i < BarCount; i++ )
{
    // reset trade counter on the new day
    if( SETUP[ i ] ) tradeCount = 0;

    // keep buy signal if there is no trade and trade count did not hit the limit
    if( Buy[ i ] AND tradeCount < N AND NOT onBuy )
    {
        OnBuy = 1;
        TradeCount++;
    }
    else
        Buy[ i ] = 0; // ignore other buy signals


    if( onBuy AND Sell[ i ] )
    {
        onBuy = 0; // reset onBuy flag on exit
    }
}




PositionScore = ROC(C, 30); 

SetPositionSize( 500, spsValue);


if ( Status( "action" ) == actionExplore )
{    
   Filter = IIf(BUY,1,0);
   AddColumn(PositionScore, "POSITIONSCORE", 1.2);
   SetSortColumns( -3);
}

Please assist on this

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.