I think I solve the main core of the problem but the code working not quite correct because of the bug that I think I spot but don't know how to re-write the problematic portion of the code.
So first of all, I simplify my initial condition to make life easier a little bit. I use not 300 shares but 400 shares (it is easier to divide in mind ) everything else the same.
(Only long position ) I enter to the position with 400 shares.
1. Initial stop => -10 cents
2. Target #1 => + 20 cents and I close 200 shares (half of the position )
Stop #2 => +10 cents (close remaining 200 shares )
3. Target #2 => + 40 cents and closing 100 shares
Stop #3 => +35 cents (close remaining 100 shares )
4. If price didn't hit stop #3 after reaching target#2 => I close it at any price at the end of the day.
all data intraday
CODE:
Please log in to see this code.
The code has several problems that I spot.
Problem #1 : it keep going divide position. So in the results we can see not only 400, 200, 100 shares but 50, 25,13,6 ... even 0 shares
Even if I change the variable InitialPositionSize on the constant 400 (shares for example ). The function of splitting stop to work.
Problem #2: Function GetTime(int bar) doesn't work at all.
I think the core problem located here :
CODE:
Please log in to see this code.
But I dont know how to substitute
CODE:
Please log in to see this code.
expression in order to introduce target1, target2 and InitialPositionSize variables.
Please help me to solve this problems. Many thanks in advance !