How to make an anti martingale code?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #16204 quote
    enzo_52enzo_52
    Participant
    Senior

    Hi Nicolas,  i would like to put a antimartingala, if i win add 1 quantity if i lose i decrease /2 quantity,  can you help me?

    thanks anyway

    Vincenzo

    #16219 quote
    NicolasNicolas
    Keymaster
    Legend

    This code snippet will help you achieve this:

    defparam preloadbars=0
    
    //dummy strategy !
    longcondition = RSI[14] crosses over 50
    
    if not longonmarket and longcondition then
    if positionperf(1)<0 then
     positionsize = positionsize-1
    else
     positionsize = positionsize+1
    endif
     size = max(1,positionsize)
     BUY size SHARE AT MARKET
    endif
    
    SET TARGET PPROFIT 10
    set stop ploss 20
    
    graph size
    graph positionperf(1)

    Not tested but it should work as intended. Here I assume that “1” SHARE is the minimum lot possible for the traded instrument of the trading strategy. Let us know if it’s ok for you.

    #16254 quote
    enzo_52enzo_52
    Participant
    Senior

    Thanks Nicolas, but it doesn t work,  this is the code of TS  on BUND with TF 4h, can you put the anti-martingala ? if i win increase +1, if i lose decrease 2

    thanks

    Vincenzo

    // STRATEGY BYE BYE BYE BUND
    // IG MARKET - FGBL BUND 1 EUR - 4 H - SPREAD 2
    DEFPARAM CumulateOrders = false
    PositionSize = 1
    
    indicator1, ignored = CALL "PRICE ACTION BUND"
    c1 = (indicator1 >= 1)
    
    indicator1, ignored = CALL "PRICE ACTION BUND"
    c2 = (indicator1 <=- 1)
    
    indicator1, ignored = CALL "PRICE ACTION BUND"
    c3 = (indicator1 crosses over 0)
    
    IF c1 or c2 or c3 AND CurrentDayOfWeek <> 1 THEN
    BUY POSITIONSIZE CONTRACT AT MARKET
    ENDIF
    
    // TRAILING STOP LOGIK BY KENNETH KVISTAD MODIFIED FOR LONG AND SHORT POSITION
    TGL =66
    
    if not onmarket then
    MAXPRICE = 0
    EXITPRICE = 0
    ENDIF
    
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close)
    if MAXPRICE-tradeprice(1)>=TGL*pointsize then
    EXITPRICE = MAXPRICE-TGL*pointsize
    ENDIF
    ENDIF
    
    if onmarket and EXITPRICE>0 then
    SELL AT EXITPRICE STOP
    ENDIF
    
    SET STOP PLOSS 350
    SET TARGET PPROFIT 500
    #16256 quote
    NicolasNicolas
    Keymaster
    Legend

    Yes it works, I think you can add it yourself to the code with ease 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

How to make an anti martingale code?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
enzo_52 @enzo_52 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by NicolasNicolas
9 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/08/2016
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...