Extending a limit order

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #212748 quote
    Mike Boorman
    Participant
    Average

    Hello folks,

    I’m trying to enter the market on a pullback that can occur up to five bars after one of the entry conditions is met.

    I would like to enter on the furthermost right bar in this screengrab (when price pulls back to the 15EMA), but it currently doesn’t work. I can tell from the graph drawing that it is because my entry rule of close >=highfractal+7 has become invalid. How can I save this entry rule to memory and allow the system to wait 5 bars for the price to pull back to the EMA?

    Thanks in advance for your help 🙂

    DEFPARAM CumulateOrders = False
    
    ONCE HighCount = Undefined
    ONCE HighFractal = Undefined
    ONCE NbBarLimit = 10
    
     
    IF (High > High[1]) AND (High > High[2]) and high= highest[4](high) THEN
    HighLevel = High
    MyLimitBuy = ExponentialAverage[15](close)
    MyIndex = Barindex
    ENDIF
    IF BarIndex >= MyIndex + NbBarLimit THEN
    MyLimitBuy = 0
    ENDIF
     
    IF (High < HighLevel) THEN
    HighCount = HighCount - 1
    ELSIF (High >= HighLevel) THEN
    HighCount = 0
    ENDIF
     
    IF HighCount = -1 THEN
    HighFractal = HighLevel
    ELSE
    HighFractal = HighFractal
    ENDIF
    
    IF MyLimitBuy > 0 AND NOT LongOnMarket and close >=highfractal+7 THEN
    BUY 1 perpoint AT MyLimitBuy LIMIT
    ENDIF
    
    
    
    SET STOP pLOSS 10
    SET TARGET pPROFIT 20
    
    
    graph close >=highfractal+7
    
    Screen-Shot-2023-04-03-at-19.30.18.png Screen-Shot-2023-04-03-at-19.30.18.png
    #213306 quote
    robertogozzi
    Moderator
    Master

    You should post more details about the strategy conditions, along with a screenshot where trigger and entry points are highlighted.

    Mike Boorman thanked this post
    #213314 quote
    Mike Boorman
    Participant
    Average

    Thank you for bumping this, Roberto.

    Rules are:

    1. New higher high, 7 points or more higher than previous
    2. Enter when price pulls back to 15ema

     

    I’ve attached a better screengrab showing what ought to be trigger bar and entry bar.

    Screen-Shot-2023-04-14-at-19.12.20.png Screen-Shot-2023-04-14-at-19.12.20.png
    #213355 quote
    ZeroCafeine
    Participant
    Senior

    @Mike Boorman
    I want to try to understand and help, wich Time Frame for your strategy to do some test ?

    and maybe also you can change de first groupe of condition to C1 and draw the C1 condition, maybe it’s can be help you :

    C1 = (High > High[1]) AND (High > High[2]) and high= highest[4](high)
    
    IF C1 THEN
    HighLevel = High
    MyLimitBuy = ExponentialAverage[15](close)
    MyIndex = Barindex
    ENDIF
    
    Graph C1 AS "C1"
    Mike Boorman thanked this post
    #213361 quote
    Mike Boorman
    Participant
    Average

    Thanks for the response, @ZeroCafeine

    I’ve amended the code like you said and created a screengrab.

    I’m working on the DAX 5 minute, April 14 2023.

    ZeroCafeine thanked this post
    Screen-Shot-2023-04-16-at-17.37.59.png Screen-Shot-2023-04-16-at-17.37.59.png
    #213368 quote
    ZeroCafeine
    Participant
    Senior

    Hi
    I don’t understand every think from your code, if you can explain more what do you want to do,

    But after cheking your code and try to understand it, I saw a first problem in the line 8 :

    IF (High > High[1]) AND (High > High[2]) and high= highest[4](high) THEN
    // Last condition : high= highest[4](high) 
    

    this last condition is useless because it will always be true,

    First case : when you use the Highset function on the last 4 candles, don’t forget that you also include the last candle (Candle[0]), so if the High of the last candle is higher than the last 3 then your code means the same thing as this: Highest[0] = High[0] and this is always true, so you don’t need this condition,

    Second case : if you don’t want to include the last candle [0] in the Highest fonction, it’s possible but you have to use like this :

    high = highest[4](high[1])

    in this case you compare the last high with the high of the other candlestick, on the other hand in this case you want the high of the last candle to be equal to the highest high you will find, and then in this case there is a high probability that you will not find this case, it is possible but rare

    I hope to be clear and not to be mistaken, if you do not understand I can make you a diagram

    #213436 quote
    Mike Boorman
    Participant
    Average

    I’ve changed the code to the high=highest[4](high[1]) you suggested, but this isn’t the problem. My problem is that I want PRT to remember that the high condition WAS true, and then enter the market once the price drops back to the 15EMA.

    I’ve done another screengrab with the new code, pointing to the bar I want to enter (in this case it comes two bars after the high condition is true). How can I enter the market here?

    DEFPARAM CumulateOrders = False
    
    ONCE HighCount = Undefined
    ONCE HighFractal = Undefined
    ONCE NbBarLimit = 5
    
     
    C1 = high= highest[4](high[1])
    
    If c1 then
    HighLevel = High
    MyLimitBuy = ExponentialAverage[15](close)
    MyIndex = Barindex
    ENDIF
    IF BarIndex >= MyIndex + NbBarLimit THEN
    MyLimitBuy = 0
    ENDIF
     
    IF (High < HighLevel) THEN
    HighCount = HighCount - 1
    ELSIF (High >= HighLevel) THEN
    HighCount = 0
    ENDIF
     
    IF HighCount = -1 THEN
    HighFractal = HighLevel
    ELSE
    HighFractal = HighFractal
    ENDIF
    
    IF MyLimitBuy > 0 AND NOT LongOnMarket and close >=highfractal+7 THEN
    BUY 1 perpoint AT MyLimitBuy LIMIT
    ENDIF
    
    
    
    SET STOP pLOSS 10
    SET TARGET pPROFIT 20
    
    
    //graph highfractal
    graph C1 as "C1"
    
    Screen-Shot-2023-04-18-at-12.01.11.png Screen-Shot-2023-04-18-at-12.01.11.png
    #213575 quote
    ZeroCafeine
    Participant
    Senior

    @Mike Boorman

    I don’t understand what you want to do between line 19 and 29, but maybe this can helo you, change all your buy condition to one condition and graph it like that :

    BuyConditions = MyLimitBuy > 0 AND NOT LongOnMarket and close >=highfractal+7
    
    IF BuyConditions THEN
    BUY 1 Shares AT MyLimitBuy LIMIT
    ENDIF
    
    Graph BuyConditions AS "BuyCondition"

    and you will see on the graphique, your BuyConditions is all the time false so all the time the BuyConditions = 0, So that is maybe why your code no buy anythink

    #213961 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE Signal = 0
    Ema15       = average[15,1](close)
    IF high > (high[1] + 7*PipSize) THEN
       Signal = 1
    ENDIF
    IF OnMarket THEN
       Signal = 0
    ELSE
       IF Signal = 1 THEN
          IF low <= Ema15 THEN
             BUY 1 Contract at Market
             SET STOP    pLOSS 50
             SET TARGET pPROFIT 100
          ENDIF
       ENDIF
    ENDIF
    Mike Boorman thanked this post
    #214137 quote
    Mike Boorman
    Participant
    Average

    Thank you for your help Roberto. I’ve just run a test. As you can see from the screengrab, signal = 1 even when the market is going down, which isn’t what I want.

    If the market is going down with red bars, I can’t understand how the high of the current bar could possibly be greater than the high[1] + 7? But PRT is saying it’s true.

    Screen-Shot-2023-05-04-at-17.23.04.png Screen-Shot-2023-05-04-at-17.23.04.png
    #214257 quote
    robertogozzi
    Moderator
    Master

    It’s because the SIGNAL is never cleared, unless OnMarket, so if the trend reverses the signals is still retained.

    This version will clear the SIGNAL whenever a candle closes BELOW Ema15:

    ONCE Signal = 0
    Ema15       = average[15,1](close)
    IF high > (high[1] + 7*PipSize) THEN
       Signal = 1
    ENDIF
    IF close < Ema15 THEN
       Signal = 0
    ENDIF
    IF Not OnMarket AND Signal AND ((low <= Ema15) AND (min(open,close) >= Ema15)) THEN
       BUY 1 Contract at Market
       SET STOP   pLOSS   50
       SET TARGET pPROFIT 100
       Signal = 0
    ENDIF
    Mike Boorman thanked this post
    #214271 quote
    Mike Boorman
    Participant
    Average

    Thanks Roberto. It’s getting closer 🙂

    I want to be more clever with the previous high. At the moment signal is true if high is +7 from the previous bar, but I’d like it to be +7 from a previous high. I’m not exactly sure how to define the ‘previous high’ I am seeing with my eyes, but I’ve attached a screengrab to show what I mean.

    Screen-Shot-2023-05-07-at-22.26.36.png Screen-Shot-2023-05-07-at-22.26.36.png
    #215039 quote
    robertogozzi
    Moderator
    Master

    I was trying to understand what’s the issue, but I need your latest code used.

    Mike Boorman thanked this post
    #215049 quote
    Mike Boorman
    Participant
    Average

    Thanks for you offer of help, Roberto. These are the rules:

    -New higher high, 7 points or more higher than last significant high
    -Enter when price pulls back to 15ema

    StartTime = 080000
    Limitentrytime = 230000
    
    daysforbiddenentry = OpenDayOfWeek=6 OR OpenDayOfWeek=0
    Definitehigh=highest[10](high)
    
    ONCE Signal = 0
    Ema15       = average[15,1](close)
    IF high > (high[1] + 7) THEN
    Signal = 1
    ENDIF
    IF close < Ema15 THEN
    Signal = 0
    ENDIF
    IF Not OnMarket AND Signal AND ((low <= Ema15) AND (min(open,close) >= Ema15)) and time >=StartTime and time <=LimitEntrytime and not daysForbiddenEntry THEN
    BUY 1 perpoint at Market
    SET STOP    pLOSS 16
    SET TARGET pPROFIT 5
    ENDIF
    
    graph signal
    

    The problem is that ‘signal’ is currently derived from high[1], which is the previous bar. I don’t want to consider the previous bar. I want to consider the previous significant high with a look back. In the screengrab I have attached, I want ‘signal’ to become true on the bar where I have put the left green arrow. Once the signal becomes true, the green arrow to the right should then become an entry when the price pulls back to the 15ema.

    Thank you again for your help.

    Screen-Shot-2023-05-23-at-10.11.34.png Screen-Shot-2023-05-23-at-10.11.34.png
    #215057 quote
    robertogozzi
    Moderator
    Master

    Try replacing line 9 with:

    IF high >= (Definitehigh[1] + 7) THEN
    Mike Boorman thanked this post
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Extending a limit order


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 16 replies,
has 3 voices, and was last updated by robertogozzi
2 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/03/2023
Status: Active
Attachments: 8 files
Logo Logo
Loading...