AbzParticipant
Veteran
// Definition of code parameters
DEFPARAM Preloadbars = 10000
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
//DEFPARAM FLATBEFORE = 090000
//DEFPARAM FLATAFTER = 220000
// indicators
timeframe(default)
rs = RSI[7](close)
ema50 = ExponentialAverage[50](close)
ema200 = ExponentialAverage[200](close)
Positions = 1
//Exit Long
if longonmarket and rs crosses under 75 then
sell at market
endif
//Exit Short
if shortonmarket and rs crosses over 25 then
exitshort at market
endif
//
// Conditions to enter Long positions
TIMEFRAME (1 hour, updateonclose)
a = ema50 > ema200
timeframe(default)
b = rs crosses over 25
x1 = ema50 > ema200
IF a and b and x1 THEN
buy Positions shares AT MARKET
ENDIF
// Conditions to enter Short positions
TIMEFRAME (1 hour, updateonclose)
c = ema50 < ema200
timeframe(default)
d = rs crosses under 75
x2 = ema50 < ema200
//
IF c and d and x2 THEN
sellshort Positions shares AT MARKET
ENDIF
anyone have any idea why not the timeframe 1hour condition not working? from the attached screen it is clearly that “c = ema50 < ema200” is not valid and still it is taking a short trade however it is valid on the 15 min timeframe that is default and it looks for me that it is following the default time frame and igonring the 1 hour timeframe.
You’re are absolutely right!
It ignores your 1-hour TF because no indicator is defined within THAT time frame. You only set conditions based on the indicators written in your default TF.
Move lines 9-11 to just after line 26.
Indicators only work in the TF they are declared, though you can read them from anywhere else.
AbzParticipant
Veteran
i only want the ema50 and ema200 to be checked in 1 hour timeframe so it shoud be like this then?
// Definition of code parameters
DEFPARAM Preloadbars = 10000
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
//DEFPARAM FLATBEFORE = 090000
//DEFPARAM FLATAFTER = 220000
// indicators
timeframe(default)
rs = RSI[7](close)
Positions = 1
//Exit Long
if longonmarket and rs crosses under 75 then
sell at market
endif
//Exit Short
if shortonmarket and rs crosses over 25 then
exitshort at market
endif
//
// Conditions to enter Long positions
TIMEFRAME (1 hour, updateonclose)
a = ema50 > ema200
ema50 = ExponentialAverage[50](close)
ema200 = ExponentialAverage[200](close)
timeframe(default)
b = rs crosses over 25
x1 = ema50 > ema200
IF a and b and x1 THEN
buy Positions shares AT MARKET
ENDIF
// Conditions to enter Short positions
TIMEFRAME (1 hour, updateonclose)
c = ema50 < ema200
ema50 = ExponentialAverage[50](close)
ema200 = ExponentialAverage[200](close)
timeframe(default)
d = rs crosses under 75
x2 = ema50 < ema200
//
IF c and d and x2 THEN
sellshort Positions shares AT MARKET
ENDIF
//SET STOP ploss 75
//SET TARGET pPROFIT 25
Line 25 needs to be moved below line 27, before line 28.
Lines 39-40 can be removed, they are a duplicate of lines 26-27.