Scale In Trade Not Working - Only buying on the initial signal

I have tried to use a sigScaleIn in my code however it is not working. I have looked through the forum at previous questions/examples but cant see where i am going wrong. I have 2 entry conditions, initial entry and a ScaleIn entry once a condition has been meet. Looking at the detailed trade log in Exploration it is only taking the initial buy signal trade and it is never taking the scale in option even though I have plotted the scale in triggers and can see them on the chart. My code is below if anyone can point me in the right direction. Basically how do i get the code to take the scale in buy when it is triggered.

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();


//SMA PLOT
MA200 = MA(Close,200);
MA50 = MA(Close, 50);
MA20 = MA(Close, 20);

Plot(MA200, "200SMA",colorGreen);
Plot(MA50, "50SMA",colorBlue);
Plot(MA20, "20SMA",colorViolet);

//Stochastic Values

Stochastic2 = StochK(14,3);
Stochastic1 = Ref(Stochastic2,-1);

//Buy Conditions

//Entry 1
BuyCond1 = (C>MA200);// Close Price Above 200SMA
BuyCond2 = MA20>MA50; //20 SMA above 50 SMA
BuyCond3 = MA50>MA200; //50 SMA above 200 SMA
BuyCond4 = Stochastic1<20 AND Stochastic2>20; //Stochastic is below 20 then comes above 20
BuyCond5 = MA200>=Ref(MA200,-1); // 200SMA in Uptrend

Entry1 = BuyCond1 AND BuyCond2 AND BuyCond3 AND BuyCond4 AND BuyCond5;

//Entry 2

BuyCond6 = Stochastic1<50 AND Stochastic2>50; //Stochastic is below 50 then comes above 50

Entry2 = BuyCond6;
OnlyEntry2 = Entry2 AND NOT Entry1;


InitialEntry = Entry1;
ScaleInEntry = Entry2;

Buy = 	IIf(InitialEntry , 1, 
IIf(ScaleInEntry, sigScaleIn, 0));


// Position sizing
EntryPosSize1 = 10000; // Size for first entry
EntryPosSize2 = 10000; // Size for second entry
PosSize = (Entry1 * EntryPosSize1) + (Entry2 * EntryPosSize2);
SetPositionSize(PosSize, spsValue);

//Sell Conditions

SellCond1 = Stochastic1>80;

Sell = Ref(SellCond1,0);

SellPrice = Close;

//Plot Buy and Sell Signals
Buy = ExRem(Buy,Sell);
Entry2 = ExRem(Entry2,Buy);
Sell = ExRem(Sell,Buy);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorYellow,0,C,0,0);
PlotShapes(IIf(Entry2, shapeUpArrow, shapeNone), colorYellow,0,C,0,0);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone), colorYellow,0,C,0,0);


ApplyStop(0,1,10,1,False,10,0,-1,0);

You are REMOVING scale-in signals yourself by using ExRem() function.

// THIS CODE of yours REMOVES Scale-in
Buy = ExRem(Buy,Sell);

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

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