Hi All,
I have a problem with my code and I cannot figure out where I am going wrong, would appreciate any help here pls.
I have a code which buys on a positionscore + RSI () > 50 and then use a trailing stop loss based on ATR
Below is the scan results for a particular basket and my issue is with one trade in particular.
The scan results for IB Ventures looks great. RSC ranking in one of the top vs peers
Individual scores for the scan dates meet my criteria and stock closing remains above Stop Loss levels
My problem is that the system buys IB ventures on 20-4-2018 (Green) great !! BUT sells it on 01-06-2018. I do not want to sell it esp when it meets the criteria with (1st Rank and RSI > 50 and Closing > Stop Level…. Basically, a perfect hold/scale in stock for my system and instead it sells it…
Red Horizontal Line is Stop Loss level, Price doesn’t hit the SL level and still system sells it on red arrow day.
** Note RSC Rank for IBVENTURES on 1 June (37.94) is higher than Graphite (30.58) in screenshot above
Any idea what could be going wrong here?
I use a scale in and a trailing stop loss based (formula below)
//---------------------------------------------- Scaling In ----------------------------------------------//
Sellsignal = 0;
x = SumSince(sellsignal, buysignal);
xsigs = x <=50;
firsttrade = x <=0;
TimeFrameRestore();
BuySignalX = TimeFrameExpand( BuySignal, inWeekly );///@link https://www.amibroker.com/guide/a_mistakes.html#TIMEFRAME
xsigsX = TimeFrameExpand( xsigs, inWeekly );
SellsignalX = TimeFrameExpand( Sellsignal, inWeekly );
Friday = DayOfWeek()==5;
Monday = DayOfWeek()==1;
Buy = IIf(Friday AND BuySignalX AND xsigsX, sigScaleIn, 0);
exitLastBar = datetime() >= GetFnData("DelistingDate");
Sell = Friday AND SellsignalX OR exitLastBar;
//SetPositionSize( PctSize, spsPercentOfEquity );
//--------------------------------------------------------------------------------------------------------//
//-------------------------------------------- Trailing Stop ---------------------------------------------//
delay = 2;
stopAmount = IIf( Friday, RiskPerShare, 100000 );//if it's not Monday, sends a very high stop amount to ApplyStop
ApplyStop( stopTypeTrailing, stopModePoint, StopAmount, 2, True, 0, delay);///@link http://www.amibroker.com/kb/2014/10/17/using-price-levels-with-applystop-function/
//--------------------------------------------------------------------------------------------------------//
thanks,
Gautam