Ok ,but how would I then go about if I want a trailing stop to start at just that level where indicator3<span class=”crayon-o”>[</span><span class=”crayon-cn”>2</span><span class=”crayon-o”>]</span> <span class=”crayon-st”>CROSSES OVER</span> indicator4<span class=”crayon-o”>[</span><span class=”crayon-cn”>2</span><span class=”crayon-o”>] </span>? Is it possible to store this value in a constant that I can later use in “trailingstarts?
Is it possible to store this value
Value of what … price at crossing or what?
Yes exactly, and have the price at crossing to be where trailing starts
My code does what you state above, but you still need a start and step value, for example 30, in the code so when price drops by >= 30 the trade will exit.
If you have start value = 0 then if price drops by 1 point then trade exits.
You are imagining that Trail starts at crossover and then price only goes up from there … what if you are Long and price goes down after crossover??
You need to do loads of tests using your Demo Platform to see how all this hangs together else you will forever be working on ‘how you think PRT works’.
// Conditions to enter long positions
indicator1 = Average[20](close)
indicator2 = Average[100](close)
c1 = (indicator1 CROSSES UNDER indicator2)
IF c1 THEN
BUY 5 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = Average[20](close)
indicator4 = Average[100](close)
c2 = (indicator3[2] CROSSES OVER indicator4[2])
IF c2 THEN
SELL AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 500
1y backtesting gave 50 trades and 8.8% time in market. Stoploss was never triggerd during this year.
// Conditions to enter long positions
indicator1 = Average[20](close)
indicator2 = Average[100](close)
c1 = (indicator1 CROSSES UNDER indicator2)
IF c1 THEN
BUY 5 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = Average[20](close)
indicator4 = Average[100](close)
c2 = (indicator3[2] CROSSES OVER indicator4[2])
If c2 Then
// Stops and targets
trailingstart = 1 //trailing will start @trailinstart points profit
trailingstep = 1 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
ENDIF
Endif
SET STOP pLOSS 500
This is with the trailing stoploss triggerd at c2. Trailingstart and trailingstep set to 1 should give a similar result as to the one without trailing stop.
1y backtesting gave 23 trades and 61% time in market. Stoploss was triggerd 2 during this year.
I tried with different values for trailingstart and trailing step, but nothing works. As you can see the trailing stop does not work as it should and does almost never sell where it should, and that is “why time in market” goes from 8% to 61%. The results are day and night and they should be almost the same.
After alot of detective work. The second one with trailing, will only trigger “IF indicator3[2] CROSSES OVER indicator4[2] AND (now this is strange) if 2 candles after the cross over the candle goes lower then the close of the one before”
Somehow the trailing stop gets bound with what happends 2 candles after C2 and works ONLY in this candle and ONLY if this cadles low is lower then the previous candles close. And if it dont happend this candle, the bot needs to wait for next C2 bore it can try again. This almost never happends and this is why time in market exploded.
(Yes I have a delay on the sale with 2 candles, but I have the same problem with my bots without it)
I hope I make some sence, and if you have time can help me from here
The logic sounds familiar to me. What time frame?
30 min
Yes somehow the trailing stop gets bound to this and only this candle and only work here.
Now we just need to set it free 🙂
trailingstart = 1 and trailingstep =1 is nonsense.
Just run it through the optimizer.
trailingstart from 20 to 200 in increments of 10 and trailingstep from 5 to 50 in increments of 5. Should be quick.
Yes 1 and 1 is nonsence. But they should give the same result as the one without trailing stop, and it does not.
Have tried manually alot of differnet numbers and can ofc get a better reslut then when I use 1 and 1.
But no matter what numbers I use, It still only works in just that 1 candle and this is the problem.
(Don’t know that optimizer is, mb you can link smt?)
No, can’t give the same results at all. In your case the system would try to secure a point if you win one point. which is bullshit. Can someone please show him the basics? I don’t have a laptop here.
Why are you using below … this means the cross occured 2 bars ago?
c2 = (indicator3[2] CROSSES OVER indicator4[2])
Why not use …
c2 = (indicator3 CROSSES OVER indicator4)
Yes it would close out almost immediately, just like if diden’t even have it.
But the problem is not if I use 1-1 or 1-30
The problem is the trailing stop ONLY work in one candle.
Yes I want it to sell on delay from cross.
But the problem remains indicator3(2) or indicator3, the trailing stop ONLY works in just that one candle.
trailing stop ONLY works in just that one candle.
It will with a Start of 1 and a Step of 1 or 30 ?
Post your latest code and I will test it on my Platform.