Max profit and loss each day in a trading strategy

Resetting each day the daily target profit and maximum allowed loss.

This code snippet that can be added to any trading strategy.

 

Share this

  1. sophie riordan • 10/10/2016 #

    Hi Wing  
    Thanks for the code, I am new to this and I have added the snippet to my code but I am not able to make it run I need to add the buy conditions but not coding properly any help would be really appreciated.
    Thank you.
    Leigh

    • Wing • 10/10/2016 #

      The easiest would be if you posted here or in a forum thread your code so far and I or someone else can see how it should look with this code snippet added.

  2. Makkman • 10/10/2016 #

    help anyone ??
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated

    maxdailyprofit=20000
    maxdailyloss=2

    once tradeallowed=1

    if intradaybarindex=0 then
    myprofit=strategyprofit
    tradeallowed=1
    endif

    if strategyprofit>=myprofit+maxdailyprofit or strategyprofit= noEntryBeforeTime

    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 173000
    timeEnterAfter = time = indicator2[1])
    c2 = (indicator1 > 60)
    IF tradeallowed=1 and c1 and c2 and timeenterbefore and timeenterafter THEN
    BUY 0.5 CONTRACT AT MARKET
    ENDIF

    // Conditions to enter short positions
    indicator3 = RSI[2](close)
    indicator4 = RSI[2](close)-15
    c3 = (indicator3 <= indicator4[1])
    c4 = (indicator3 < 40)
    IF tradeallowed=1 and c3 and c4 and timeenterbefore and timeenterafter THEN
    SELLSHORT 0.5 CONTRACT AT MARKET
    ENDIF
    SET STOP TRAILING 2.5

    • Nicolas • 10/10/2016 #

      Help for what please? Open a new topic in the forums to get help for coding, it is not an appropriate place here!

  3. Makkman • 10/10/2016 #

    Didnt find where to post at The forum, sorry need help geting The Daily stop to work, i have propably implemented The code wrong because Daily loss are grater than in The code

  4. xaviert • 10/10/2016 #

    Hi guys ! First, thanks a lot for this code “Max profit and loss each day in a trading strategy”. I would like to add a piece of code in the same idea but a little bit different. Indeed, I try to keep this code “Max profit and loss each day in a trading strategy” but I want to implement a code which will tell the following thing to the machine : If yesterday was a loss of X€, so today you don’t trade… You guess I’m not an expert 😉 Could you please help me ? I’m sure it is just 3 or 4 lines of codes but I didn’t manage to find them… Thanks to everyone

    • Nicolas • 10/10/2016 #

      Please open a new topic in the forums to post this specific custom coding query. Please respect the forum rules for posting, thanks.

avatar
Register or

Top