Hi again
I have watched tutorials but I cant figure out how the code is for closing a position after a candle when a new candle begins. Please can someone help me with that.
Simply add these lines at the beginning of your code, just after DEFPARAM’s:
Sell at Market
Exitshort at Market
when you are not OnMarket they are ignored, otherwise they will close any trade opened the previous candle.
Is it possible too close position after X sec or X min?
You can only count bars, read https://www.prorealcode.com/topic/define-a-time-stop/#post-147903.
If you are using a minute or second TF, yes it’s possible.
You are the best!
But in a one minute TF I cant close a postion after 50 s? In that case i need to work with multiple timeframes?
Yes, “Second” is the smallest TF (and tick isn’t possible yet..)
But if I am in a 1 minute TF I cant define it too stop after x secs?
How do I write that code? I am in 1m TF and want it to stop after 50s.
There you go (run it from a 1-second TF):
TIMEFRAME(1 minute,UpdateOnClose)
IF MyLongConditions THEN
BUY 1 Contract at Market
ENDIF
TIMEFRAME(1 second,UpdateOnclose)
MySecond = opentime - (round((opentime / 100) - 0.5) * 100)
TIMEFRAME(default)
IF MySecond >= 50 AND LongOnMarket THEN
SELL at Market
ENDIF
line 8 checks for MySecond being 50 or greater, since it may happen not to have that candle on such a small TF.
Searching this forum for the words MTF and Multi Time Frame will return many links to examples, documentations, blogs and many topics.