Daily Martingale code

Forums ProRealTime English forum ProOrder support Daily Martingale code

Viewing 15 posts - 1 through 15 (of 19 total)
  • #56569

    Dear Colleagues,

    I am trying to put together a simple Daily Martingale Code.

    The system start at 090000 every day a takes the price at that time as reference (levelZERO) for the rest of the day.

    If the price goes up from levelZERO and pass the 10 pips up (level1up) opens a BUY STOP order with a SL=20 and PF=20

    If the price goes down from levelZERO and pass the 10 pips down (level1down) opens a SELLSHORT STOP order with a SL=20 and PF=20

    Every time our operation goes wrong and start again, the Martingale doubles the position size.

    The idea is to create and area of 30 pips up and 30 pips down in which, if the price trespass those levels up or down, it is a winning operation (20 pips) and then no more trading for the day.

    We all know the risk of the Martingale or any other systems based on the accumulation of orders, but since the operations are close daily and the range is 30 pips up and down from the starting price (levelZERO) at 090000, I felt very curious to see the long term results.

    I have put together the code below, but it seems that after the first operations, it stops. I know there is a way to keep the STOP orders active in the following bars but I don’t remember how it goes. Everything I tried is not working, so I will leave the code here in case anyone finds the problem.

    Thanks,

    Juan

     

    #56572

    Before anyone point it out, I know that the Martingale code is a little unconventional and there is another one here in the library shorter and simplified, but I understand this much better and it is easier for me to change it and modify it in case I want to create a reverse or other type of Martingale.

    #56592

    I am not sure but could it be that you open the trades with stoporders that causes the problem? (using stoporders and positionperf)

    Its an interesting approach, i have tried something similar but never did get it to work, ( but i am not any good at coding)

     

    #56593

    Another thing i been thinking about but i doubt it can be done with proorder?

    First of all you need a account with hedging allowed

    If you start with a box of 30 points or a inside bar or whatever

    and quit if profit is 60 points

    then you open 1 buy at boxhigh (no stop) and if it reach boxlow before take profit

    then you open 2 sell (no stop)

    and next 3 buy and so on

     

    you just keep all trades open and hedge so that you have only 1 extra open buy or sell and wait for take profit and close all

    most of the time you only need 1 buy or maybe one sell open before TP

     

    of course TP could be 1:1 but then you need to double size each time

     

    the thing is you lower the risk and the margin is lower when hedging

    and less slippage because less stoporders

     

    #56594

    Try the following in replacement of line 14-17 of your system :

    However, the result looks like a conventional Martingale system : long periods with nice gains and a few catastrophic events that destroy everything.

    1 user thanked author for this post.
    #56599

    Hi Verdi and Eric,

    Thanks so much for your suggestions and for your piece of code. It works fine, and pretty much what I expected of a Martingale: Nice periods of steady gain and sudden drops.

    Nevertheless, it is not quite what I want. I had the idea of doing the daily martingale. It means that at the end of the day the accumulation is over and next day start when positionsize=1. I realised that many of the drops are due to the accumulation of contracts through different days, which is very plausible. On the contrary, if we reduced the martingale to just one day, the probability of failing more than 4-5 consecutive operations (critical number) in one day, when a simple grid is rare.

    I have tried to reset the number of contracts every day by:

    IF time=010000 THEN

    positionsize=1

    ENDIF

    It doesn’t work.

    Any suggestions??

    Thanks,

    Juan

     

    #56600

    Same problem as before : positionperf(x) keeps counting the performance of every position, whenever it was. So, if positionperf(6)<0 occured, say 6 days ago, it will still reset positionsize to a higher value than 1. You need to find a way that only the performance of positions of the same day (not of the days before) are counted for the calculation of positionsize, just as I did it in my short code. 

     

    “IF (positionperf(1) > 0 and date[diffTiBi] = date and (not onmarket)) OR (positionperf(1) > 0 and date[diffTiBi1] = date and onmarket)” only counts the positionperf of positions that were closed on the same day.

    1 user thanked author for this post.
    #56641

    Hi Verdi,

    Thanks, I will try it this afternoon. If this work, it is going to be very useful for me in the future, because it is a problem/condition that I have been having in my last codes and didn’t know how to solve it.

    Let you of the results later,

    Thanks,

    Juan

    #56676

    HI ,

    timeframe 1 min?

    #56679

    Hi JR1976,

    I am using 5 min, but the smaller the better, although you will have to get a decent backtest due to the limited past.

    I have changed the orders at market, since does not interfere with the reading of the Martingale. The result attached are not bad, but like any Martingale subject to any sudden drawdown. Anyway, I wanted to try and see the results since I am exploring different ways to approach strategies, different than pure Technical Analysis.

    Regards,

    Juan

    P.S.- I am having your code “Riding the trend/SP500” on REAL,  and it is going fairly well. Thanks.

    1 user thanked author for this post.
    #56685

    This is my try with 200.000 bars :

    #56686

    Oh, the attachments…DAX-5-Minuten

    1 user thanked author for this post.
    #56689

    Martingale will fail, whatever conditions or filters you’ll add in your strategy. The backtests’ results (or equity curve looks) depends mainly of when you start the strategy, it is all clear in the picture that verdi55 has attached. Anyway, this is a very good coding exercise 🙂

    #56695

    Hi Verdi,

    Thanks for the 200k. No doubt about what Nicolas said. I would have never put this in REAL because any day may be the last one (literally), but I am coding and studying new different types of grid strategies, and part of this code is going to be very useful for the future.

    Regards,

    Juan

    #56842

    Have you had a look at this one: https://www.gridtrendmultiplier.com/

    Have bookmarked it some time ago in order to code something similar when I have some time but never seem to get to it.

Viewing 15 posts - 1 through 15 (of 19 total)

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