if i back test this simple code, entry and exit are 2 bars late. i want position to open or close on OPEN as the conditions are met.
new to this! any advice much appreciated
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = MACD[12,26,9](Open )
c1 = (indicator1 >= 0)
IF c1 THEN
BUY 1 PERPOINT AT MARKET
ENDIF
// Conditions to exit long positions
indicator2 = MACD[12,26,9](Open )
c2 = (indicator2 < 0)
IF c2 THEN
SELL AT MARKET
ENDIF
Code is read at the end of each bar and positions are opened or closed at the Open of the next bar … which is only a few miliiseconds after close of previous bar.
Hope above helps, if not just say.
thank you for feed back.
if i replace with close, is still 1 bar late.
i would like to enter position on market open.
i attach screen shot of graph showing that MACD histogram positive on oct 1 but position doesnt open till nov 1.
how do i trigger open on oct 1 when macd is positive?
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = MACD[12,26,9](close)
c1 = (indicator1 >= 0)
IF c1 THEN
BUY 1 PERPOINT AT MARKET
ENDIF
// Conditions to exit long positions
indicator2 = MACD[12,26,9](close)
c2 = (indicator2 < 0)
IF c2 THEN
SELL AT MARKET
ENDIF
If this is a monthly time frame, then the “close” of a monthly bar is at the end of the month…
how do i trigger open on oct 1 when macd is positive?
Use multi-Timeframe.
For example, conditions could be satisfied on a monthly timeframe, but the trade could be opened on a 1 minute timeframe … so 1 minute into the October bar or said another way … 1 minute after the end of the September bar.
Multi timeframe – MTF indicators for ProRealTime