Resetting each day the daily target profit and maximum allowed loss.
This code snippet that can be added to any trading strategy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// ---parameters MaxDailyProfit=1000 //Max daily profit allowed (in money) MaxDailyLoss=1000 //Max daily loss allowed (in money) // first time we launch the code, the trading is allowed once TradeAllowed=1 // reset the current state of the strateygprofit each new day If intradaybarindex=0 then MyProfit=STRATEGYPROFIT TradeAllowed=1 endif // test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowed If StrategyProfit>=MyProfit+MaxDailyProfit or Strategyprofit<=MyProfit-MaxDailyLoss then TradeAllowed=0 endif // initiate a new BUY order if TradeAllowed=1 and buyconditions then buy 1 lot at market endif |
Hi Wing
Thank you, just come across your code … I will incorporate into my strategies … very useful code!
Cheers
GraHal
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
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.
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
Help for what please? Open a new topic in the forums to get help for coding, it is not an appropriate place here!
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
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
Please open a new topic in the forums to post this specific custom coding query. Please respect the forum rules for posting, thanks.