How to buy at close?
Forums › ProRealTime English forum › ProOrder support › How to buy at close?
- This topic has 5 replies, 2 voices, and was last updated 5 years ago by robertogozzi.
Tagged: mtf
-
-
12/13/2018 at 3:17 PM #87021
Hello!
I’m new to PRT and having some problems with the code.
I want to apply this on a daily chart.
I want to buy at the close in the daily chart. But now it´s buying the next day.
1234567891011121314151617181920212223// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Stochastic[2,1](close)c1 = (indicator1 <= 10)indicator2 = BollingerBandWidth[20](close)c2 = (indicator2 >= 0.10)IF c1 and c2 THENBUY 1 CONTRACT AT MARKETENDIF//ExitIF LONGONMARKET AND (BarIndex-TradeIndex) >= 4 THENSELL AT MARKETENDIF//SäljIF LONGONMARKET AND CLOSE > 1.001 * TRADEPRICE THENSELL AT MARKETENDIFGrateful for any help with this issue 🙂
12/13/2018 at 3:51 PM #87028Strategies are always run at each candle close, so any trade AT MARKET is immediately open, which is the day following the setup bar.
12/13/2018 at 11:10 PM #8706012/14/2018 at 1:10 AM #87067There you are, like I said in my previous post:
<pre class=”lang:probuilder decode:true “>IF MyConditions AND Not OnMarket THEN
BUY AT MARKET
ENDIF
On a daily chart, If your conditions are true when the Monday bar closes, then a trade will be opened as soon as the Tuesday bar opens.To open a trade on any bar your conditions must be true the previous bar.
You cannot open a trade on the same bar where conditions are true, simply because strategies are executed ALWAYS when a bar closes.
If you are using higher TF’s, you can mitigate the (micro) delay using Multiple Time Frames, a feature introduced a few months ago and still being beta tested on demo accounts only.
This will allow you to enter a trade on a smaller TF while checking conditions on a higher TF. But… no matter what, trades will be opened when a candle closes.
If your conditions are true on the DAILY chart you may use a 1-Minute TF to enter the trade the same day, even just 1 minute before the daily chart closes, but still when 1-minute chart closes not while it is being formed.
https://www.prorealcode.com/blog/learning/approach-multi-timeframe-trading-prorealtime/
https://www.prorealcode.com/documentation/timeframe-probacktest-proorder/
https://www.prorealcode.com/topic/betatesting-multitimeframe-support-automatic-trading/
12/18/2018 at 7:06 PM #87391I´m not getting this to work. I´m getting this error no mather what i do.(See Attachment)
I also tried copy/paste of the first code on this link: https://www.prorealcode.com/blog/learning/approach-multi-timeframe-trading-prorealtime/ It´s still the same error message.
This is my current code:
1234567891011121314151617181920212223// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedtimeframe(daily)// Conditions to enter long positionsindicator1 = Stochastic[2,1](close)c1 = (indicator1 <= 10)indicator2 = BollingerBandWidth[20](close)c2 = (indicator2 >= 0.10)timeframe(1 minute,updateonclose)IF c1 and c2 THENBUY 1 CONTRACT AT MARKETENDIFtimeframe(daily)//Exit on day fiveIF LONGONMARKET AND (BarIndex-TradeIndex) >= 4 THENSELL AT MARKETENDIF//Dstat ?IF LONGONMARKET AND CLOSE > 1.001 * TRADEPRICE THENSELL AT MARKETENDIF12/18/2018 at 7:40 PM #87397When using Multiple Time Frames, the main TF (the default one, which is on the chart and from which the strategy is launched) MUST be the lowest TF, in this case 1-minute TF.
All other TF’s need to be multiple of this main TF.
You strategy can be launched from 1-minute or lower TF, say 10 seconds or 20 seconds, but NOT 7 seconds because 1-minute, which is 60 seconds, is not a multiple of 7 seconds!
-
AuthorPosts
Find exclusive trading pro-tools on