martingale reset to one contract after win.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #197595 quote
    wrigsy
    Participant
    New

    Hi All,

    I am new to coding and trying to code something I do on the us30 it is trading with the trend and get in on a retracement confirmation. Risk reward is roughly 10 to 1 or slightly worse so I martingale losses by 0.1 so when I win the loss is covered with a small increase in contract size when taking out a new position. I’m trying to code to free up time. I have tried using snippets from the site but not getting anywhere, any help would be great. I am having trouble with the martingale resetting after a win also how to only increase position size by 0.1 of 1 contract.

    I know my entry on retracement is not great but will come back to it once I have a basic code working.  (I will add some other time frame for confirmation also some more vol filters and break even)

    Thank you for your help much appreciated,

    Leigh

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    once n = 1
     
    
    noEntryBeforeTime = 140000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 213000
    timeEnterAfter = time < noEntryAfterTime
     
    /// Conditions to enter long positions
    c1 = (close[1] <= close[2])
    c2 = (close[2] <= close[3])
    c3 = (close >= close)
    indicator1 = Volume
    c4 = (indicator1 >= indicator1[1])
    indicator2 = Average[20](close)
    indicator3 = Average[50](close)*1.00044
    c5 = (indicator2 >= indicator3)
     
     
    IF (c1 AND c2 AND c3 AND c4 AND c5) AND timeEnterBefore AND timeEnterAfter THEN
    
     
    IF PositionPerf(1) <0 THEN
    n = n+1
    ELSIF PositionPerf(1) =0 THEN 
    n = n+1
    ELSIF  PositionPerf(1) >0 THEN
    n = n+1
    ENDIF
     
    buy n contracts at market
    Endif
    
     
    Set Stop pLoss 14
    Set Target pProfit 120
    #197618 quote
    robertogozzi
    Moderator
    Master

    Try this one:

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    once n = 1
    
    noEntryBeforeTime = 140000
    timeEnterBefore = time >= noEntryBeforeTime
     
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 213000
    timeEnterAfter = time < noEntryAfterTime
    
    /// Conditions to enter long positions
    c1 = (close[1] <= close[2])
    c2 = (close[2] <= close[3])
    c3 = (close >= close)
    indicator1 = Volume
    c4 = (indicator1 >= indicator1[1])
    indicator2 = Average[20](close)
    indicator3 = Average[50](close)*1.00044
    c5 = (indicator2 >= indicator3)
    
    IF STRATEGYPROFIT - STRATEGYPROFIT[1] > 0 THEN
       n = 1
    ELSIF STRATEGYPROFIT - STRATEGYPROFIT[1] < 0 THEN
       n = n * 1.1
    ENDIF
    
    IF (c1 AND c2 AND c3 AND c4 AND c5) AND timeEnterBefore AND timeEnterAfter THEN
       buy n contracts at market
    Endif
    
    Set Stop pLoss 14
    Set Target pProfit 120
    graph n
    wrigsy thanked this post
    #197634 quote
    wrigsy
    Participant
    New

    Great, thank you Roberto. Much appreciated !

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

martingale reset to one contract after win.


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
wrigsy @wrigsy Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by wrigsy
3 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/20/2022
Status: Active
Attachments: No files
Logo Logo
Loading...