ChamParticipant
Average
Example:
I am using 2 timeframes, 10 minutes and 1 second. Suppose when OnMarket, after it reaches my stoploss, I don’t want the program to open another position within the same bar my stoploss was reached.
Anybody can help me how to get this done? I searched for it on the forum, but can not find it.
Thanks in advance…
On which TF, 10-minute or 1-second?
On 1-second TF it is impossible to acrivate more than one order each bar, since strategies are executed when a bar closes, so another trade could only be opened the next bar, not the same one.
On a 10-minute TF you should add, at the very beginning of that code (provided UPDATEONCLOSE is used):
IF Not OnMarket THEN
BarCount = 0
ELSE
BarCount = BarCount + 1
ENDIF
Next, at the very beginning of the code on your 1-second TF, add:
ONCE TradeON = 1
IF IntraDayBarIndex = 0 THEN
TradeON = 1
ENDIF
TradeBar = BarCount
IF Not OnMarket AND TradeBar <> TradeBar[1] THEN
TradeON = 1
ENDIF
Then add TradeON to your conditions to enter a trade and clear it to avoid further trading until the next 10-minute bar:
IF MyConditions AND Not OnMarket AND TradeON THEN
BUY/SELLSHORT...
TradeON = 0
ENDIF
edited on May 5th, 2021:
lines
IF Not OnMarket THEN
BarCount = 0
ELSE
BarCount = BarCount + 1
ENDIF
do not work properly and should be replaced by this single line:
BarCount = BarIndex
ChamParticipant
Average
Thank you, Roberto…
I am using 5 timeframes, but just used 10 minutes and 1 sec. as an example. Thank you for the code.
The first lines of code I posted;
IF Not OnMarket THEN
BarCount = 0
ELSE
BarCount = BarCount + 1
ENDIF
should be added to only one TF, i.e. if you are using Daily+h4+h1+10-minute+default(1-second), then if you add that code on the 10-minute TF your next trade would not open till the next 10-minute bar.
If you add it, instead, to your 1-hour TF, only one trade per hour will be allowed, and so on…
I added to here
Snippet Link Library
Please could one reader say if you see the link above as the words … ‘Snippet Link Library’ … or something else?
We see correctly the link GraHal , do not worry 😉
“Snippet Link Library“
Actually lines:
IF Not OnMarket THEN
BarCount = 0
ELSE
BarCount = BarCount + 1
ENDIF
do not work properly (thanks to MauroPro at https://www.prorealcode.com/topic/singola-operazione-multitimeframe/) and should be replaced by this single line:
BarCount = BarIndex
I also edited in RED the original post above (so the link in the Snippet Library is still valid).