Hello,
Would someone help me with the code that will make the strategy pause until tomorrow when a target profit is hit. I want to use it in timeframe 5 minutes.
The system will take trades but when a certain amount of profit is reached, the system will pause for the rest of the day and will continue tomorrow.
Thank you
Moderation message: Topic moved from “platform support” forum to the more appropriate “pro order” forum
a certain amount of profit is reached
You mean profit of the current day?
Yes, I was meaning the current day, something like:
if todayProfit > X then
pause strategy until tomorrow
endif
and the strategy will continue the day after because the todayProfit variable will be reinitialised to zero
Thank you
Hi Youngus,
I think you could use this
// STRATEGYPROFIT per DAY //////////////////////////////////////////////////////////////////////////////
// It resets the variable each new day
IF INTRADAYBARINDEX = 0 THEN
stratprofit = STRATEGYPROFIT //saves the previous day Profit
nomoretrading = 0
ENDIF
// Finishing DAILY operations when reaching target profit/loss
IF (STRATEGYPROFIT-stratprofit)>=40 THEN //current day's profit
SELL AT MARKET
EXITSHORT AT MARKET
nomoretrading=1
ENDIF
IF (STRATEGYPROFIT-stratprofit)<=-40 THEN //current day's loss
SELL AT MARKET
EXITSHORT AT MARKET
nomoretrading=1
ENDIF
In this case, when your operation is closed and your benefit is >=40 (currency, not points) your code will not launch any more orders. It also works for daily losses.
In order to do that you should include in every BUYING/SELLING order nometrading=0
IF yourconditions AND nomoretrading=0 THEN
BUY 1 contract at market
ENDIF
I hope it is what you are looking for.
Regards
Hello Juan,
Thanks for the code. I’ll try implement it.
Cheers