Scale-In problem

I tried to do scale in for a simple logic based on MA. AFL is given below, The problem is always the BUY signal is only Buying 5 shares and not the 12 shares though there are several instances where the logic of buying 12 shares arises. If anybody helps me to understand the problem here ill be really helpful.

MA2= MA(C,20);
MA3 = MA (C,34);
buysig1 = Cross(MA1, MA2);
buysig2 = Cross(MA1, MA3);
buysig3 = Cross(MA2,MA3);
sellsig1 = Cross(MA2,MA1);

Buy=IIf((buysig1 OR buysig2 OR buysig3), sigScaleIn,0);
X= SumSince(sellsig1, buy);
Sell=sellsig1;


firsttrade = X ==1;
secondtrade = X ==2;
Thirdtarde = X ==3;

SetOption("MaxOpenPositions", 3 );
SetPositionSize(IIf(firsttrade,12,5),spsShares);

/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
DISPLAY & GRAPHICXS OPTION
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/

SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace = 10; // create empty space of 10% top and bottom of chart 
ChartType = ParamList("Chart Type", "Price Chart");

if (ChartType == "Price Chart") 
{
Plot( Close, "Price", colorRed, styleCandle );
Plot( MA1, "MA1", colorYellow, styleLine );
Plot( MA2, "MA2", colorBrightGreen, styleLine );
Plot( MA3, "MA3", colorWhite, styleLine );
//Plot( X, "X", colorPink, styleLine );
//Plot(SAR(minacc,maxacc), "PSAR", colorYellow, styleDashed );
PlotShapes( shapeUpArrow*Buy, colorGreen, 0, L, -20 );//shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shapeDownArrow*Sell, colorRed, 0, H, -20 );//PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0);//,offset=-12``

You're assigning the value sigScaleIn to the Buy array. sigScaleIn is a constant which happens to be a large value, not a simple 0 (false) or 1 (true). Therefore, when you sum those values using SumSince(), you don't get a count of the scale in signals, but rather a sum of large numbers which results in another large number (never 1, 2, 3, etc.).

You should just be able to change this:

X= SumSince(sellsig1, buy);

to this:

X= SumSince(sellsig1, buy > 0);

to effectively count the scale-ins rather than summing them.

3 Likes

Dear @mradtke

Many thanks for the help sir. It is really working now and solved the issue
regards
samik

If the issue is solved, you should mark it as "solved" in the forum and/or "like" the post that provided an answer.

1 Like