Help with code for basic market modeling

Forums ProRealTime English forum ProBuilder support Help with code for basic market modeling

Viewing 13 posts - 1 through 13 (of 13 total)
  • #19401

    Hi!

    I need some programming help since I am still building my skills.

    Due to a bug in Pro Order 10.2 I started to programm indicators instead of backtests because the backtesting engine returned wrong entries and exits on the more sophisticated indicators.

    It all kind of went it’s own way from there and now I use it to model markets on a basic level.

     

    The goal is to evaluate price behavior after a specific pattern occurs (Event A).

    The open of the following bar is then compared to the five following closes.

    Please find this idea in Pseudocode below.

     

    One problem is:

    If event A happens on two consecutive days, the code above will check the condition for the first event only once and for second event five times.

    The first event is overwritten by the second. But it should also be evaluated for the next five days. To put it differently, several events of the A-Type can be going on at the same time.

    I resolved this very manually by adding five separate events.

    The following commented code shows the procedure for the first event and how the second event is being initiated.

     

     

    At the end all of the results are summed up:

     

    The return and the binprob variables are the starting points for actual evaluation and analysis. They provide a basic insight into the price movement that follows event A and return a winning-losing probability for this type of event and time span.

    As you can see it is difficult to add more events and more bars following the initial event. Can you show me how to resolve this? Maybe put this procedure into proper loops?

    Ultimately I want to add another event B following event A. This would be something along the lines of:

    If the price crosses above the five days moving average look for a´close higher than tomorrows open within the next five days. But if the price crosses below the 5 days moving average before the good result occurs check if there will be a close below tomorrows open within the next five days following the second cross.

    #19540

    Hi Derek,

    I must admit that read and understand the code you have posted is a bit tricky .. 🙂

    Please don’t be offend, but in order to help you in the most effective way, I believe I should rebuild the whole code in a proper coding way (and it will also be easier and quicker for me).

    Would you mind telling me what is the “eventA” please? I need to start with a good knowledge of the whole plan! Thanks in advance.

    #19545

    Hi Nicolas,

    thank you for offering your support and I surely am rather thankfull.

    It does not matter what event A is but I have been using John Ehlers Supersmoother from the library.

    The condition is S > S[1].

     

    #19654

    Hello Nicolas,

    let me try to explain in a different way what this is supposed to be.

    I consider it to be more of a universal tool for statistical analysis than an actual indicator or even a handicapped backtest. There is a good result (the condition has been meet after X days) and the corresponding bad result. If I look at todays price chart and ask myself: What is the right side of this market?” the binprob variable can provide an easy insight into the patterns just observed on the chart.

    For example:

    If the price crosses over the Supersmoother what is the probability that the price will (still) be above the indicator in 1,2,3,4,5..X days? If I want to enter a market and the price has been above the indicator for 6 days already does this mean I could also wait for 3-4 days more and hope for a pullback with a 70-80% probability? Thus telling me in which direction I should enter and when a good moment could be comming up?

    The condition to be checked (price above the supersmoother) can easily be adapted to many different needs. In return this indicator can provide a probability distribution for the request.

    Another example are the many forum posts asking for a exit condition after 3 bars. Why 3 bars and not five? The return function can provide an insight into the expected return for every following day.

    I hope this helps you a bit better to understand where this is going.

    In an optimal world those results could be exported into a spreadsheet 🙂 Anyways in my view it is a little swiss army knife and surely think that other users can profit from this, too.

    #23363

    Hello! A late reply from me here, but an interesting problem. Did you manage to solve it? Was the indicator/system of any use in terms of edge?

    I have created similar systems based on a similar technique (basic form of machine learning). This is tricky to do in PRT, but possible.

    1 user thanked author for this post.
    #23377

    If you want to know if the price goes in the same direction of your indicator, you could use correlation between them with least square regression analysis.

    #23491

    Hello Wing,

    unfortunately I have not been able to resolve this in PRT and have returned to excel to do it.

    I started this thread to get a better statistical analysis tool and not to test an actual system.

     

    #23492

    @Nicolas: I cannot wrap my head around your suggestion. Would you mind to elaborate a little more?

    #23515

    @Derek

    Sorry, I just read again the whole thread, it will not be helpful for your statistical analysis tool. I’m jumping from topic to topic, so sometimes I should refresh my ideas 🙂

    For example: If the price crosses over the Supersmoother what is the probability that the price will (still) be above the indicator in 1,2,3,4,5..X days? If I want to enter a market and the price has been above the indicator for 6 days already does this mean I could also wait for 3-4 days more and hope for a pullback with a 70-80% probability? Thus telling me in which direction I should enter and when a good moment could be comming up?

    If I’m referring to this example, all we need to do is to count how much bars were above since the last cross of Close above the Supersmoother curve? No matter if a candle Close was above or below the previous one, etc. only a count above/below Supersmoother?

    #23559

    @Nicolas:That’s more like it.

    The price crossing the Supersmoother is an event or a condition. The question is: What is the probability that the event will still be true in X bars?

    So, maybe, the code has to start from the bar when prices crosses UNDER the Supersmoother and then look back how many bars the price was above the Supersmoother. The direction of the price does not matter.

    Every time the price crosses ABOVE the Supersmoother the number of events observed increases ( event = event +1).

    Every time the price was above the Supersmoother for longer than X bars it was a good event ( good event +1).

    Good event / event  = Probability

     

    #23572

    Something like this?

     

     

    2 users thanked author for this post.
    #23658

    That is quite something Nicolas. Thank you.

    Please find my version of the stats variable below.

     

    In the attached screenshot you can see that a lower high of the stats variable can be a reasonable indicator for a downswing and a higher low an indicator for the corresponding upswing. A long flat top of the indicator could be the end of a major trend.

    2 users thanked author for this post.
    #23682

    Purely statistical speaking, you can now add a moving average with a period of your choice with standard deviation from it :1 and 2

     

Viewing 13 posts - 1 through 13 (of 13 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login