Hi everyone, I was tried differents solutions posted in the forum, but none works in this context.
I have 2 strategy scripts, script 1 running for ticket AAA, and script 2 running for ticket BBB (both in timeframe 1 second).
I need these scripts running at the same time and with the restriction of only one trading for script, so in this context will have 2 trading as max.
First try: using the reserved word ONCE but the script never starts.
ONCE operationLaunched = 0
if operationLaunched = 0 then
buy 10 shares at market
SET STOP %LOSS 1
SET TARGET %PROFIT 1
operationLaunched = 1
endif
ONCE operationLaunched = 0
if operationLaunched = 0 then
buy 10 shares at market
SET STOP %LOSS 1
SET TARGET %PROFIT 1
operationLaunched = 1
endif
Second try, using the solution posted by Nicolas (https://www.prorealcode.com/topic/only-open-1-trade/), instead of 10, using 8*60*60 (8h x 60 sec x 60 sec)
if barindex-tradeindex >=10 and myCondition then
buy 1 contract at market
endif
But the problem with this approach is that if script 1 launchs the operation first, script 2 never start in the same day.
I also try to get the Date, and other feasible variables, but with the same result.
Thanks in advance, for any suggestion.
Replace line 1 with these lines (sometimes ONCE behaves weirdly):
IF strategyprofit = 0 AND Not OnMarket THEN
operationLaunched = 0
ENDIF
Roberto, thanks a lot for the fast answer !
So, with this implementation I suppose that both scripts may stay on market at the same time, isn’t? Because OnMarket it’s true only in the scope of the script, and not return a global position of other scripts.
Tonight I will try your solution. Thank you very much !!
Yes, separate strategies are indipendent of one another. Each one of them doesn’t know about the existance of the others, even if on the same instrument and TF. They can even open positions in different directions.
Tested and it works fine !!
Thank you very much for your help.
Have a good day !