i wil try.. i’m confused
//-------------------------------------------------------------------------
// Code principal : CANDLE
//-------------------------------------------------------------------------
Defparam cumulateorders = false
n =1
timeframe(15 minute,updateonclose)
c160m = open > open[1] and close > close[1] and close > open
timeframe(1 minute,updateonclose)
c11m = open > open[1] and close > close[1]
c21m = abs(close-open) >= 17
c31m = abs(close[1]-open[1])
c41m = c31m > c21m
timeframe(default)
c1def = open > open[1] and close > close[1]
c2def = abs(close-open) >= 1
IF not longonmarket and c1def and c11m and c21m and c41m and c2def and c1def and c160m then
BUY N contracts at market
set stop ploss 300
ENDIF
//if longonmarket and close crosses under st then
//sell at market
//endif
//************************************************************************
//trailing stop function
trailingstart = 19 //trailing will start @trailinstart points profit
trailingstep = 7 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
Also try putting a barindex number in the System to start … so that both backtest and Forward Test start on the same bar number or even a time?? (to nearest second) e.g. 100001
Taking into account conditions in your code … unless both backtest and forward test start at EXACTLY the same bar or time then there will be differences?
Let us know how you get on please?
always the same things after some init/click and so one
for the backtest, i took a spread set to 6
MIssing in either version (backtest / demo)
ok, i will add bardindex
PaulParticipant
Master
to get in in sync backtest & demo, perhaps focus on trading times outside market hours with low(est) spread on dji.
I use this & spread 6
defparam cumulateorders = false
defparam preloadbars = 10000
defparam flatbefore = 080000
defparam flatafter = 153000
then perhaps another code from inside market hours, this has about the same spread but market behaves different.
Most important, dont take any trade in the time range with highest spread. Stoploss & trailing stop will likely be out of sync compared to backtest.
Hi
I need help in order to find the best way.. for the moment the strategy wins as long as we are in the trend.
of course, sometimes, rarely, under 1s, despite the security in place on higher timeframe, the initial SL may can be reached
So, in this case, i’m trying to find the best way to go out cleanly by limiting losses..
i have already tried several types of stoploss or exit way..
Do you an interesting idea about SL or so one ? under 1s, the it’s very hard to control the trend.
i also tried with an initial target profit based on ATR to limite damage and to reache the sl when pullback…
If you post latest code as an .itf then we can be trying to make improvements also?
Be quicker than us suggesting to you and you having to do it all?
yes grahal, for the moment, i just want to resolve this part
it’s the code above (with sl 300) that i’m testing
PaulParticipant
Master
was the trade with exit on stoploss anytime in profit and if so how much?
i’m testing in live since yesterday in order to check already that the positions in live are the same in backtest.. for the moment it’s good on 1s (6 trades/6 wins)
in example, sl not reached but as soon as the numbers of candle is very long it may can reach the sl.. of course, a test according to the number of candles would be easy but not the best way
PaulParticipant
Master
indeed it would be too much curve-fitting. About 7 hours in a trade on 1s and you ended positive, you can call it luck!
If the trade was positive at any time, then you can use a breakeven to lower the stoploss, say from 300 points stoploss to 150 points.
Also, would this from fifi743 be usefull? and/or maybe modify it to suite a lower timeframe?
// point pivot [fifi743]
if dayofweek < dayofweek[1] then
weeklyhigh = prevweekhigh
weeklylow = prevweeklow
weeklyclose = prevweekclose
prevweekhigh = high
prevweeklow = low
weeklypivot = (weeklyhigh + weeklylow + weeklyclose) / 3
endif
prevweekhigh = max(prevweekhigh, high)
prevweeklow = min(prevweeklow, low)
prevweekclose = close
if dayofweek = 1 then
dayhigh = dhigh(2)
daylow = dlow(2)
dayclose = dclose(2)
endif
if dayofweek >=2 and dayofweek < 6 then
dayhigh = dhigh(1)
daylow = dlow(1)
dayclose = dclose(1)
endif
pivot = (dayhigh + daylow + dayclose) / 3
ecart=2
ecartwp=3
yes, thx Paul.. but the luck smiles.. in demo (no sl reached since 2 weeks..)
of course, i’m try to confirm the trend by a pivot and indeed sl would be divide by 2 , i already thought about it.. for the moment, i tried on pivot 1H..
i’m going to test your proposal.. just a question, how are managed the variable ecart et ecartwp ?
i’m also trying to apply at the same time an exitshort when there is a reverse signal according to the summation and number of red candle in order to gain wheen it starts to lose