i see you use IQFeed data. Below is another example of scaling. I believe they call this method "The Ladder". You can display this for QGC#. I used 50$ as a separation. For other futures one would need other settings. For QGC# one would need deep pockets and a lot of strong beer
to sit through such trades. But you could also trade QMGC#, QMES# or QMNQ#. The buy and sell levels I now calculate as a single price level but one could also maybe try variable levels like based on ATR.
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "FuturesMode", True );
SetOption( "CommissionMode", 3 );
SetOption( "CommissionAmount", 2.37 );
SetPositionSize( 1, spsShares );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 0 );
newBuySeries = ParamToggle( "New Buying Series", "Buy at any Level down|Use last Sell Level", 0 );
// separation between levels in points
separation = 50; // use 50$ for Gold futures from about 2016 - 2021 period
// determine price range and add 10%
priceRange = LastValue( Highest( H ) ) * 1.1;
// create buy and sell arrays trigger arrays
buyTrigger = sellTrigger = 0;
buyLevel = sellLevel = 0;
miny = Status( "axisminy" );
maxy = Status( "axismaxy" );
for( i = separation; i < priceRange; i = i + separation )
{
//_TRACE( "i: " + i );
level = i;
if( LastValue( level ) > miny AND LastValue( level ) < maxy )
{
Plot( level, "", colorWhite, styleLine | styleNoRescale | styleNoLabel, Null, Null, 0, 0, 1 );
}
buyTrigger = IIf( Cross( level, C ), 1, buyTrigger );
buyLevel = IIf( Cross( level, C ), level, buyLevel );
sellTrigger = IIf( Cross( C, level ), 1, sellTrigger );
sellLevel = IIf( Cross( C, level ), level, sellLevel );
}
Buy = Sell = 0;
BuyPrice = SellPrice = C;
npos = 0;
maxpos = 50; // maximum number of positions
nposarray = 0;
lev = 1e12;
for( i = 0; i < BarCount; i++ )
{
if( ( BuyTrigger[i] ) AND npos == 0 AND buyLevel[i] < lev )
{
Buy[i] = 1;
npos = 1;
nposarray[i] = npos;
lev = buyLevel[i];
}
else
if( ( BuyTrigger[i] ) AND npos > 0 AND npos < maxpos AND buyLevel[i] < lev )
{
Buy[i] = sigScaleIn;
npos = npos + 1;
nposarray[i] = npos;
lev = buyLevel[i];
}
if( ( SellTrigger[i] ) AND npos == 1 AND sellLevel[i] > lev )
{
Sell[i] = 1;
npos = 0;
nposarray[i] = npos;
// final sell, new round of buy can start now
if( NewBuySeries )
{
lev = sellLevel[i]; // use last sell level when starting the first new buy
}
else
{
lev = 1e12; // or reset level and restart buying at any cross down.
}
}
else
if( ( SellTrigger[i] ) AND npos > 1 AND sellLevel[i] > lev )
{
Buy[i] = sigScaleOut;
npos = npos - 1;
nposarray[i] = npos;
lev = sellLevel[i];
}
}
PlotShapes( IIf( Buy == 1, shapeUpArrow, shapeNone ), colorDarkGreen, 0, L, -15 );
PlotShapes( IIf( Buy == 1, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
PlotShapes( IIf( Buy == sigScaleIn, shapeUpArrow, shapeNone ), colorlightblue, 0, L, -15 );
PlotShapes( IIf( Buy == sigScaleIn, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
PlotShapes( IIf( Buy == sigScaleOut, shapeDownArrow, shapeNone ), colorOrange, 0, H, -15 );
PlotShapes( IIf( Buy == sigScaleOut, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, -15 );
PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorWhite, 0, SellPrice, 0 );
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
ft = "Arial Black";
sz = 10;
for( i = fvb; i <= lvb; i++ )
{
if( Buy[i] == 1 )
{
PlotTextSetFont( "" + 1, ft, sz, i, L[i], colorGreen, colorWhite, -sz * 4 );
}
if( Buy[i] == sigScaleIn )
{
PlotTextSetFont( "" + nposarray[i], ft, sz, i, L[i], colorGreen, colorWhite, -sz * 4 );
}
if( Buy[i] == sigScaleOut )
{
PlotTextSetFont( "" + nposarray[i], ft, sz, i, H[i], colorOrange, colorWhite, sz * 3 );
}
if( Sell[i] == 1 )
{
PlotTextSetFont( "" + nposarray[i], ft, sz, i, H[i], colorRed, colorWhite, sz * 3 );
}
}
Filter = Buy OR Sell;
AddColumn( Buy, "Buy" );
AddColumn( Sell, "Sell" );
AddColumn( nposarray, "Number Of Positions" );
