Automated trading with Pivot Points and Dojis

Viewing 15 posts - 31 through 45 (of 85 total)
  • Author
    Posts
  • #70395 quote
    cgraubner
    Participant
    Junior

    I tried to change the time frame for the daily pivot conditions by only considering the 34 candles before 16:30. But apparently that is also not working:(

    if time = 163000 then
    newdailyhigh = highest[34](high)[0]
    newdailylow = lowest[34](low)[0]
    newdailyclose = close[0]
    endif
    
    Pivot = (newdailyhigh[1] + newdailylow[1] + newdailyclose[1]) / 3
    R1 = 2*Pivot - newdailylow[1]
    S1 = 2*Pivot - newdailyhigh[1]
    rR2 = Pivot + (newdailyhigh[1] - newdailylow[1])
    S2 = Pivot - (newdailyhigh[1] - newdailylow[1])
    R3 = R1 + (newdailyhigh[1] - newdailylow[1])
    S3 = S1 - (newdailyhigh[1] - newdailylow[1])
    #70426 quote
    GraHal
    Participant
    Master

    Is anything working? 🙂

    Why don’t you get a simplifiedcut down version working then start building it back up again?

    If anybody else can offer any help here then feel free? 🙂

    #70429 quote
    cgraubner
    Participant
    Junior

    Everything else is working:) There is just this little time issue left.

    #70430 quote
    cgraubner
    Participant
    Junior

    Sorry to bother you again, but it is almost working:) I enhanced to range of the day to the whole day from 0:00 till 23:59 and the pivot lines match those of the chart:) The profit is also still high. But now I have a new issue:( As you can see in the picture, the pivot lines are good for tuesdays till friedays but they are pretty messed up on mondays. I have no idea why that happens.

    messed-up-mondays.png messed-up-mondays.png
    #70434 quote
    GraHal
    Participant
    Master

    the pivot lines are good for tuesdays till friedays but they are pretty messed up on mondays

    Now I’ve forgotten again what market this is on sorry? 🙂

    Are the Pivot lines based on price the day before? If Yes, then the DAX and other markets  open for 2 or 3 hours on Sunday night (e.g. EUR/USD @ 22:00 and DAX @ 23:00) so this could be screwing the Pivots for Monday??

    Just an idea / immediate thoughts?

    cgraubner thanked this post
    #70436 quote
    cgraubner
    Participant
    Junior

    You don’t have to say sorry:) Yes it is the DAX, and you where right about sunday. Now I change the code to this and the pivot lines for mondays are align with those within the chart:) Thank you so much!!!

    DEFPARAM CumulateOrders = false
    DEFPARAM FlatBefore = 000000
    DEFPARAM FlatAfter = 234500
    
    
    
    if OpenDayOfWeek = 1 then
    
    Pivot = (DHigh(2) + DLow(2) + DClose(2)) / 3
    R1 = 2*Pivot - DLow(2)
    S1 = 2*Pivot - DHigh(2)
    rR2 = Pivot + (DHigh(2) - DLow(2))
    S2 = Pivot - (DHigh(2) - DLow(2))
    R3 = R1 + (DHigh(2) - DLow(2))
    S3 = S1 - (DHigh(2) - DLow(2))
    
    endif
    
    if OpenDayOfWeek = 2 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    S1 = 2*Pivot - DHigh(1)
    rR2 = Pivot + (DHigh(1) - DLow(1))
    S2 = Pivot - (DHigh(1) - DLow(1))
    R3 = R1 + (DHigh(1) - DLow(1))
    S3 = S1 - (DHigh(1) - DLow(1))
    
    endif
    
    if OpenDayOfWeek = 3 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    S1 = 2*Pivot - DHigh(1)
    rR2 = Pivot + (DHigh(1) - DLow(1))
    S2 = Pivot - (DHigh(1) - DLow(1))
    R3 = R1 + (DHigh(1) - DLow(1))
    S3 = S1 - (DHigh(1) - DLow(1))
    
    endif
    
    if OpenDayOfWeek = 4 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    S1 = 2*Pivot - DHigh(1)
    rR2 = Pivot + (DHigh(1) - DLow(1))
    S2 = Pivot - (DHigh(1) - DLow(1))
    R3 = R1 + (DHigh(1) - DLow(1))
    S3 = S1 - (DHigh(1) - DLow(1))
    
    endif
    
    if OpenDayOfWeek = 5 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    S1 = 2*Pivot - DHigh(1)
    rR2 = Pivot + (DHigh(1) - DLow(1))
    S2 = Pivot - (DHigh(1) - DLow(1))
    R3 = R1 + (DHigh(1) - DLow(1))
    S3 = S1 - (DHigh(1) - DLow(1))
    
    endif
    
    
    
    GraHal thanked this post
    #70457 quote
    GraHal
    Participant
    Master

    Why not code fewer lines re days other than Day 1 and use …

    if OpenDayOfWeek <> 1 then
     
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    S1 = 2*Pivot - DHigh(1)
    rR2 = Pivot + (DHigh(1) - DLow(1))
    S2 = Pivot - (DHigh(1) - DLow(1))
    R3 = R1 + (DHigh(1) - DLow(1))
    S3 = S1 - (DHigh(1) - DLow(1))
    cgraubner thanked this post
    #70557 quote
    cgraubner
    Participant
    Junior

    You are right, that looks better!:)

    Unfortunately there still seems to be a problem with my stops.

    I tried to set the stop to the highest high of the doji or of the confirmation candle right next to the doji. So if the high of the doji is higher, then this is my stop, and vice versa. Additionally the stop should be placed 2 points higher than those highs, because of the spread. But as you can see in the picture the trade is exited by the condition when a close ist higher than the previous high. It should have been closed somewhere around the red line. It would be nice if the stop was triggerd immediately and not at the open of the next candle. Thank you very much for your help!:)

    //DAX
    //15 min
    
    DEFPARAM CumulateOrders = false
    DEFPARAM FlatBefore = 090000
    DEFPARAM FlatAfter = 173000
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    S1 = 2*Pivot - DHigh(1)
    rR2 = Pivot + (DHigh(1) - DLow(1))
    S2 = Pivot - (DHigh(1) - DLow(1))
    R3 = R1 + (DHigh(1) - DLow(1))
    S3 = S1 - (DHigh(1) - DLow(1))
    
    dojisize = 4.2*pipsize
    doji = Range >= ABS(Open[1] - Close[1]) * dojisize
    
    bearishp = (doji and close[1] <= pivot+2 and close[1] >= pivot-2 and close<low[1])
    
    If bearishp Then
    
    SellShort size Contract at Market
    
    if  shortonmarket and high>high[1] then
    exitshort at (high+2*pipsize) stop
    endif
    if  shortonmarket and high<high[1] then
    exitshort at (high[1]+2*pipsize) stop
    endif
    Endif
    
    IF shortonmarket  and (close >high[1]) then
    exitshort at market
    
    ENDIF
    stop-issue.png stop-issue.png
    #70567 quote
    GraHal
    Participant
    Master

    To get an immediate exit (not at end of candle) try this …

    The difference is that you are setting the Stop at Trade Open.

    If bearishp Then
     
    SellShort size Contract at Market
    ExitShort at (close >high[1]) Stop                     
    Endif

     

    #70627 quote
    cgraubner
    Participant
    Junior

    This did not change anything. And the conditions where it places the stop would also be neglected.

    //DAX
    //15 min exit strategy
    
    If bearishp Then
    
    SellShort size Contract at Market
    exitshort at (high+2*pipsize) stop
    exitshort at (high+2*pipsize) stop
    
    Endif
    
    IF shortonmarket  and (close >high[1]) then
    exitshort at market
    
    ENDIF
    #70643 quote
    cgraubner
    Participant
    Junior

    I tried a different approach but as soon as I added one more Pivot Line the system fails again and messes up. It works for only one Line, though. Within this approach I tried to store the candle conditions of the entry. It was also not possible to write the exitshort commands within the “if bearishp” conditions. I had to write them into new if conditions afterwards.

    I don’t know what to try anymore, or if it will work at all like I planned. Any suggestions?:)

    //DAX
    // 15 min
    
    DEFPARAM CumulateOrders = false
    DEFPARAM FlatBefore = 090000
    DEFPARAM FlatAfter = 173000
     
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    S1 = 2*Pivot - DHigh(1)
    rR2 = Pivot + (DHigh(1) - DLow(1))
    S2 = Pivot - (DHigh(1) - DLow(1))
    R3 = R1 + (DHigh(1) - DLow(1))
    S3 = S1 - (DHigh(1) - DLow(1))
     
    dojisize = 4.2*pipsize
    doji = Range >= ABS(Open[1] - Close[1]) * dojisize
     
    bearishp = (doji and close[1] <= pivot+2 and close[1] >= pivot-2 and close<low[1])
    bearishr1 = (doji and close[1] <= r1+2 and close[1] >= r1-2 and close<low[1])
    
    If bearishp then
    if high<high[1] Then
    hdbp = high[1]+2
    SellShort size Contract at Market
    
    elsif high>high[1] then
    hnbp = high+2
    sellshort size contract at market
    endif
    endif
    
    if shortonmarket then
    if hdbp then
    exitshort at hdbp stop
    elsif hnbp then
    exitshort at hnbp stop
    endif
    endif
    
    If bearishr1 then
    if high<high[1] Then
    hdbr1 = high[1]+2
    SellShort size Contract at Market
    
    elsif high>high[1] then
    hnbr1 = high+2
    sellshort size contract at market
    
    endif
    endif
    
    if shortonmarket and hdbr1 then
    exitshort at hdbr1 stop
    endif
    
    if shortonmarket and hnbr1 then
    exitshort at hnbr1 stop
    endif
    
    exitshort at (close >high[1]) stop
    #70645 quote
    cgraubner
    Participant
    Junior

    Sorry to write again, but I coudn’t edit it anymore. A simple solution might be to set up 8 different trading systems where each system consideres a different Pivot line and execute all of them at the same time. Does that make sense?

    #70647 quote
    GraHal
    Participant
    Master

    I’m not one bit a supa-coder and have to visualise more complex actions happening in order to understand them and so all I have been doing is offering a solution to your snippets that you said did not work.

    Maybe supa-coder @RobertoGozzi (or AN Other) might happen along anytime soon and see what is wrong with your System?

    In the meantime, to make it easy for helpers …

    • Post an equity curve of results from a backtest.
    • What is the most significant function that is not working?
    #70660 quote
    robertogozzi
    Moderator
    Master

    I was looking at code at post https://www.prorealcode.com/topic/automated-trading-with-pivot-points-and-dojis/page/3/#post-70557, these are the logical errors I could spot:

    1. lines 24 and 28 + 41 and 43 may assign new values to the variables that mimic a stoploss at each new bar because they do not tell between being or not ONMARKET and this behaviour will change the results of your attempts to exit due to SL, so they should not be changed ONCE a trade has been opened (line 22 should read If bearishp and Not OnMarket then)
    2. at lines 34, 36, 53 and 57 variables HDBP, HNBP, HDBR1 and HNBR1 will always be true once they have been set the first time, while you should reset them to ZERO when Not OnMarket, I guess;
    3. line 61 will NEVER be true, since you want to exit at a price which is either 0 or 1; for sure it won’t work with DAX, it may turn true with EUR/USD if that pair falls to 1.0000 and at that very moment that line is executed, what did you want to do with that line?
    GraHal and cgraubner thanked this post
    #70698 quote
    cgraubner
    Participant
    Junior

    First of all, thank you very much!!! 😉

    I changed a few things, but it is still not executing the exitshorts when hitting the highest high of the doji or the trigger candle. Where the red circle is, was it supposed to exit.

     

    //DAX
    //15 min
    
    DEFPARAM CumulateOrders = false
    DEFPARAM FlatBefore = 090000
    DEFPARAM FlatAfter = 173000
    
    
    
    if OpenDayOfWeek = 1 then
    
    Pivot = (DHigh(2) + DLow(2) + DClose(2)) / 3
    R1 = 2*Pivot - DLow(2)
    
    
    endif
    
    if OpenDayOfWeek = 2 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    
    
    endif
    
    if OpenDayOfWeek = 3 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    
    
    endif
    
    if OpenDayOfWeek = 4 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    
    
    endif
    
    if OpenDayOfWeek = 5 then
    
    Pivot = (DHigh(1) + DLow(1) + DClose(1)) / 3
    R1 = 2*Pivot - DLow(1)
    
    
    endif
    
     
    dojisize = 4.2*pipsize
    doji = Range >= ABS(Open[1] - Close[1]) * dojisize
     
    bearishp = (doji and close[1] <= pivot+2 and close[1] >= pivot-2 and close<low[1])
    bearishr1 = (doji and close[1] <= r1+2 and close[1] >= r1-2 and close<low[1])
    
    size = 5
    
    If bearishp and not onmarket then
    if high<high[1] Then
    hdbp = high[1]+2
    SellShort size Contract at Market
     
    elsif high>high[1] then
    hnbp = high+2
    sellshort size contract at market
    endif
    endif
     
    if shortonmarket then
    if hdbp then
    exitshort at hdbp stop
    elsif hnbp then
    exitshort at hnbp stop
    endif
    endif
     
    If bearishr1 and not onmarket then
    if high<high[1] Then
    hdbr1 = high[1]+2
    SellShort size Contract at Market
     
    elsif high>high[1] then
    hnbr1 = high+2
    sellshort size contract at market
     
    endif
    endif
     
    if shortonmarket and hdbr1 then
    exitshort at hdbr1 stop
    endif
     
    if shortonmarket and hnbr1 then
    exitshort at hnbr1 stop
    endif
     
    if shortonmarket and (close >high[1]) then
    exitshort at market
    endif
    
    if not onmarket then
    hdbp = 0
    hnbp = 0
    hdbr1 = 0
    hnbr1 = 0
    endif
    stop.png stop.png
Viewing 15 posts - 31 through 45 (of 85 total)
  • You must be logged in to reply to this topic.

Automated trading with Pivot Points and Dojis


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
cgraubner @cgraubner Participant
Summary

This topic contains 84 replies,
has 5 voices, and was last updated by robertogozzi
7 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/07/2018
Status: Active
Attachments: 25 files
Logo Logo
Loading...