Hello,
since a few weeks i’ve been trying to code one of my strategies. I find this forum very helpfull, but am kind of stuck right now.
I hope someone can help me out a bit.
For trading I use PRT10.2 through IG.
When trading manual and enter a trade, I open 3, 4 or 5 lots and use R1, R2, R3 as target and after that I trail the position left using a moving average or bar by bar.
I understand that with auto trading through IG (I found out eventually in this forum) it is not posssible to close positions partially.
Because of that ‘feature’ I was thinking to enter the same strategy 3, 4 or 5 times but with different targets (and moving the SL, but more about that later)
For identifying the setup bar I use a couple of selfmade indicators. In the example below Indicator 1 and 11.
After the setup bar is closed, my entry (Buy STOP) is 0.5 ticks above the high of the setup bar. My Stoploss is placed 2 ticks below the low of the setup bar.
(see code below, till now everything is working fine)
But sometimes the setup bar is not taken out by the first following bar, but the second bar. For my strategy that is still valid. I’ve tried to use differtent examples I found in this forum and the manual,
but i am completly lost on how to code that my stoploss has to be beneath the low of the setup bar and not the first bar after the setup bar.
I attached an image (R1.jpg) with additional text tot clarify things.
Question 1: how can i adjust my code (see below) in a way that ALSO the second bar is a valid entry when taking out the setup bar and still use the same stoploss beneath
the low of the setupbar? The problem I face is referring to the low of the setup bar.
Working code with only using the first bar after the setup bar as a trigger:
indicator1 = CALL “myindicator1”
indicator11 = CALL “myindicator11”
c1 = (indicator1=1)
c11 = (indicator11 <= 2 or indicator11[1] <= 2)
Buyprice=high+0.5
R1 = (buyprice-low) +2
IF C1 and C11 THEN
BUY 1 shares AT buyprice STOP
SET STOP PLOSS R1
set target pprofit R1
ENDIF
And now the second part of my post.
As mentioned before I want to enter the trade with multiple positions. For the second entry I initaly like the use the same stoploss. But after reaching R1 I want to move the stoploss to:
buyprice – (0.4*(buyprice-initial stoploss)).
Question 2: The problem with coding this is I can refer to the buyprice, I can refer to R1 but how can I refer to the low of the setup bar after reaching R1? (the question is somewhat the same as question 1)
See also the attached image (R2.jpg).
I think the key to this is to ‘store’ the values of the setup bar (High, Low)(?).
Many, many thanks in advance!