MarkParticipant
Senior
Hello,
Could someone please help me add a bit of code to this strategy.
I would like to only enter the market between 090000 and 210000, however i do not want it to close my positions at 210000, i am happy for open positions to run over night, i just want entries of new positions to be between said time frame.
defparam cumulateorders = false
REM Money Management
Capital = 2500 // initial capital at launch of the strategy
Risk = 3 // risk in percent
REM Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*(Risk/100))
REM defining moving averages
EMA5 = exponentialaverage[5]
EMA100 = exponentialaverage[100]
EMA200 = exponentialaverage[200]
hh = highest[20](high)
ll = lowest[20](low)
// -- case BUY
if EMA5 crosses over EMA200 then
stoploss = (close-ll)/pointsize
stoplevel = (close-ll)
If stoploss < 15 then
stoploss = 15
Endif
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
BUY PositionSize SHARES AT MARKET
endif
// -- case SELL
if EMA5 crosses under EMA200 then
stoploss = (hh-close)/pointsize
stoplevel = (hh-close)
If stoploss < 15 then
stoploss = 15
Endif
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
SELLSHORT PositionSize SHARES AT MARKET
endif
// -- trades exit
if EMA5 crosses under EMA100 then
SELL AT MARKET
endif
if EMA5 crosses over EMA100 then
EXITSHORT AT MARKET
endif
SET STOP LOSS stoplevel
ALEModerator
Master
could you try it?:
defparam cumulateorders = false
REM Money Management
Capital = 2500 // initial capital at launch of the strategy
Risk = 3 // risk in percent
REM Calculate contracts
equity = Capital + StrategyProfit
maxrisk = round(equity*(Risk/100))
REM defining moving averages
EMA5 = exponentialaverage[5]
EMA100 = exponentialaverage[100]
EMA200 = exponentialaverage[200]
hh = highest[20](high)
ll = lowest[20](low)
// -- case BUY
if EMA5 crosses over EMA200 then
stoploss = (close-ll)/pointsize
stoplevel = (close-ll)
If stoploss < 15 then
stoploss = 15
Endif
if (time >=090000 and time < 210000) then
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
BUY PositionSize SHARES AT MARKET
endif
endif
// -- case SELL
if EMA5 crosses under EMA200 then
stoploss = (hh-close)/pointsize
stoplevel = (hh-close)
If stoploss < 15 then
stoploss = 15
Endif
if (time >=090000 and time < 210000) then
PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
SELLSHORT PositionSize SHARES AT MARKET
endif
endif
// -- trades exit
if EMA5 crosses under EMA100 then
SELL AT MARKET
endif
if EMA5 crosses over EMA100 then
EXITSHORT AT MARKET
endif
SET STOP LOSS stoplevel
MarkParticipant
Senior
Thanks for this, i will have a look
Mark