SigscaleOut did not occur like in the chart

a

Hello friends, I'm trying to figure out why mycode sigscaleout doesn't work like in the chart. I started this code from development from here.

Some of the same topics still do not provide appropriate answers to my codings here, here.

//modification from https://www.amibroker.com/guide/h_pyramid.html
//http://www.amibroker.com/members/library/formula.php?id=1380

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


///////////////////////////////////////////////////////////////////////////////////////////////////
SetTradeDelays(0, 0, 0, 0);
SetOption("AllowPositionShrinking", True );
SetOption( "InitialEquity", 100000000 );
SetOption( "MaxOpenPositions", 80 );
TickSize = 0 ;



Buy1  =  RSI() < 20 ;
Sell1  = RSI() > 80 ;
BarsSinceSell   = BarsSince(Sell1);
BarsSinceBuy    = BarsSince(Buy1);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FirstEntry 				= Buy1 ;
InFirstPos 				= Flip(FirstEntry, Sell1);
FirstTrigger 			= ExRem(InFirstPos, Sell1);
BarsSinceFirstTrigger   = BarsSince(FirstTrigger);
FirstTriggerPrice 		= IIf(BarsSinceFirstTrigger < BarsSinceSell, Ref(C,-BarsSinceFirstTrigger), 0 );


SecondEntry 			=  C < (FirstTriggerPrice) AND InFirstPos AND Ref(InFirstPos,-1);
InSecondPos				= Flip(SecondEntry, Sell1);
SecondTrigger 			= ExRem(InSecondPos, Sell1);
BarsSinceSecondTrigger	= BarsSince(SecondTrigger);
SecondTriggerPrice 		= IIf(BarsSinceSecondTrigger < BarsSinceSell, Ref(C,-BarsSinceSecondTrigger), 0);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Jual_1 			        = Sell1;
PosisiJual1  		    = Flip(Jual_1, Buy1);
Triger_jual1 			= ExRem(PosisiJual1, Buy1);
Bars_sejak_jual1        = BarsSince(Triger_jual1);
TriggerJual1 		    = IIf(Bars_sejak_jual1 < BarsSinceBuy, Ref(C,-Bars_sejak_jual1), 0 );


Jual_2 			        =  C > (TriggerJual1) AND PosisiJual1 AND Ref(PosisiJual1,-1);
PosisiJual2		  	    = Flip(Jual_2, Buy1);
Triger_dua 		        = ExRem(PosisiJual2, Buy1);
Bars_sejak_jual2	    = BarsSince(Triger_dua);
secondTriggerJual 		= IIf(Bars_sejak_jual2 < BarsSinceBuy, Ref(C,-Bars_sejak_jual2), 0);


Buy = IIf( FirstTrigger, 1, IIf( SecondTrigger, sigScaleIn, 0  ) ) + 
                   IIf(Triger_jual1, 1, IIf( Triger_dua,  sigScaleOut, 0)) ;

Sell = sell1;

Sell = ExRem(Sell,Buy);

//Sell = ExRem(Buy,sell);
BuyPrice = SellPrice = C;
        
SetPositionSize(IIf( FirstTrigger,400, 800 ), 
                  IIf( Buy > 0,spsShares, spsNoChange ) );
SetPositionSize( 50, IIf( Buy == sigScaleOut, spsPercentOfPosition, spsNoChange ) );


PlotShapes (IIf (FirstTrigger,  shapeSmallCircle, shapeNone), colorWhite, 0,c, 0 );
PlotShapes (IIf (SecondTrigger,  shapeSmallCircle, shapeNone), colorGreen, 0,C, 0 );
PlotShapes (IIf (Triger_jual1, shapeSmallCircle, shapeNone), colorRed, 0, C, 0);
PlotShapes (IIf (Triger_dua, shapeSmallCircle, shapeNone), colorBlue, 0, C, 0);

Need help to anyone thank you.

Did you check the detail log ?

  1. first buy
    a

  2. Wrong scalein
    b

  3. Not Scaleout
    c

  4. Not Exit
    d

in my opinion my mistake is in this code...

BarsSinceSell   = BarsSince(Sell1);
BarsSinceBuy    = BarsSince(Buy1);

and 

Buy = IIf( FirstTrigger, 1, IIf( SecondTrigger, sigScaleIn, 0  ) ) + 
                   IIf(Triger_jual1, 1, IIf( Triger_dua,  sigScaleOut, 0)) ;

From the example is Buy = Buy + sigScaleIn * DoScaleIn + sigScaleOut * DoScaleOut;

i try this

Buy1  = Buy =  RSI() < 20 ;
Sell1  = RSI() > 80 ;
BarsSinceSell   = BarsSince(Sell1);
BarsSinceBuy    = BarsSince(Buy1);

Buy = Buy + IIf( FirstTrigger, 1, IIf( SecondTrigger, sigScaleIn, 0  ) ) + 
                   IIf(Triger_jual1, 1, IIf( Triger_dua,  sigScaleOut, 0)) ;

still not working

Didi you check all ....

Thank you for the guidance,
I have checked and applied it, I think my code has no problem from the link information.

Remember - it is YOUR code and does exactly what YOU told it to do. Nothing more nothing less. Anything you get is the result of YOUR code.

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?

Yes Tomasz, you are righ

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