The code snippet can demonstrate the two problems.
Problem 1: setstoploss only works if it is hardcoded -- i.e. when an Input or a variable are used to hand over a value to setstoploss, the stop loss is triggered on the same bar and same price as the entry.
Problem 2: setstoploss uses only multiples of 100 to move the stop loss of a stock $0.50. E.g. the code snippet opens a long SPY position on 6/23 at 377.02. And setstoploss(600) exits the position several bars and 3pts later at 374.02.
I've found no mention of either of these issues on the forum, setstoploss seems to be a well proven and often used so it has to be something I'm just not seeing -- something simple, fundamental -- like looking for your glasses when they're on your head.
Can anyone point me in a direction?
Code: Select all
// // [IntrabarOrderGeneration = true] // IOG is not the issue.
Inputs:
StopAmount( 600 );
If time = 1015 then Buy next bar at open;
//setstoploss(StopAmount) ; // Use one or the other, not both at the same time.
setstoploss(600) ;
setexitonclose; // This just keeps the chart organized