Hi all, i am new to this forum and still rather new to coding automated strategies.
I was wondering if it was possible to set a profit/target limit for each day of trading.
For example within a day i may have numerous trades but do not want to open any more trades once a certain total pipcount/profit or loss is reached. however i do not want to have to restart the program every day. (So that i can use as back test and also have running if i am away, which i am a lot)
Is this possible and could one of you kind folk show me how.
many thanks
WingParticipant
Veteran
Example:
MaxDailyProfit=1000
MaxDailyLoss=1000
once TradeAllowed=1
If time<010000 then
MyProfit=STRATEGYPROFIT
TradeAllowed=1
endif
If StrategyProfit>MyProfit+MaxDailyProfit or Strategyprofit<MyProfit-MaxDailyLoss then
TradeAllowed=0
endif
if TradeAllowed=1 and buyconditions then
buy 1 lot at market
endif
This will count only closed positions. To count running positions, you need to add the check to you selling conditions, and change ‘strategyprofit’ to ‘strategyprofit+positionperf(0)’. I have not tested this code, but tell me if it works or not.
That’s perfect thankyou. I will test it out and let you know the results. Thanks again
@Wing
Thanks, I’ll add this in the blog, since it is commonly requested and your code is great.