Hello All!
I was wondering if you could help me. I would like to add a bit of code into my trend following system that skips the next trade if the previous trade were profitable.
The idea being that on trend following systems, periods of whipsawing often follow trending markets.
Anyone familiar with the turtle system should be aware of the above concept.
I’ve tried using positionperfp[1] but can’t figure out how to proceed.
Any help is appreciated. Thanks
Hello trendfollower86,
you can find a snippet below that shows an example of how the positionperf can be used to manage future orders.
if not onmarket then
perf = positionperf(1)
endif
if perf > 0.01 then
notrade = 1
else
notrade = 0
endif
if buyingcondition and notrade = 0 then
buy at market
endif
Thanks very much for your reply Derek.
I understand the code above, however the problem I have is that the code above will not only skip the next trade, but all other trades following a winner.
I imagine I need to put some kind of count function in the code so it counts to a maximum of 1 when a trade is skipped and then takes the next trade when reset.
I’m finding this thread interesting as it touches upon coding that would be really useful –
How do you register “signals” but not trade them and instead just “count” each signal and then code to trade the 5th signal for example.
This would be useful for counter trend signals such as the RSI where we know that the first, second and third can be misses but the fourth or fifth
brings home the bacon.
Ok. I have something like the following:
IF positionperf(1) > 0.01 then
SkipTrade = summation[Close CROSSES Over Upper100](1)
EndIf
LongEntry = (Not OnMarket or ShortOnMarket) AND BullSlope=1 and SkipTrade=1
If LongEntry Then
Buy LongPoundsPerPoint PerPoint RoundedUp At Upper100 Stop
Set Stop pLoss ATR*2
SkipTrade=0
EndIf
But annoyingly, this doesn’t take any trades because SkipTrade never gets set to 1
The problem with all trades being skipped is probably caused by
if perf > 0.01 then
You can graph your Positionperformance when running a backtest to have the values for your system returned with the backtest results. Then you can enter the value you need (because honestly I don’t know what 0.01 is referring to).
Simply remove the sample code from above and add this line to your backtest:
graph positionperf
Hello Bighug,
maybe like this?
if buyingcondition and counter = 5 then
buy at market
elsif buyingcondition and counter <5 then
counter = counter+1
endif
if onmarket then
counter = 0
@trendfollower
Your code is wrong. If you refer to previous Derek’s post, you already have the needed code to achieve your request = no more trade if the previous one is a profit > 0
About your code, line 2, condition should be placed in parenthesis, and periods in brackets, you have apparently done a mistake while copy/paste code from another topic.
There is also mistake in my code:
if buyingcondition and counter = 5 then
buy at market
counter = 0
elsif buyingcondition and counter <5 then
counter = counter+1
endif
This should work.
@Nicolas.
I’m not trying to achieve no more trades as you state. I am trying to skip the next trade if its previous trade was a winner. Then take the next trade regardless.
@Derek, not sure where your reference to ” if perf” has come from. I don’t have that in my code. If you are referring to
“IF positionperf(1) > 0.01 then". I am trying to say, if the last postion closed out and returned any kind of profit skip the next trade.
@Derek. Much appreciated. I have had some luck with this code:
if buyingcondition and counter = 5 then
buy at market
counter = 0
elsif buyingcondition and counter <5 then
counter = counter+1
endif