Skip next trade – TrendFollowing

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #26447 quote
    trendfollower86
    Participant
    New

    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

    #26460 quote
    Derek
    Participant
    Veteran

    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
    GraHal thanked this post
    #26487 quote
    trendfollower86
    Participant
    New

    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.

    #26517 quote
    Big Hug
    Participant
    Average

    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.

    #26520 quote
    Big Hug
    Participant
    Average
    #26531 quote
    trendfollower86
    Participant
    New

    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

    #26567 quote
    Derek
    Participant
    Veteran

    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
    #26568 quote
    Derek
    Participant
    Veteran

    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
    
    Big Hug thanked this post
    #26569 quote
    Nicolas
    Keymaster
    Master

    @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.

    #26584 quote
    Derek
    Participant
    Veteran

    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.

    #26585 quote
    trendfollower86
    Participant
    New

    @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. 

    #26591 quote
    trendfollower86
    Participant
    New

    @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
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Skip next trade – TrendFollowing


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by trendfollower86
9 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/26/2017
Status: Active
Attachments: No files
Logo Logo
Loading...