Dear Team,
I really appreciate that you are reading 🙂 can someone please write me a trading program, so I can backtest that? with the following conditions
usd/jpy maximum 1% per operation
I use Fibonacci as the extension of the first impulse, to define my entry and exit point. Namely:
entry at 61.8%
exit at 38.20 (if it is against the trend) or at the level of 23.60 or 0.00% if it is in favor of the trend
I use the 35 and 70 period EMAs as a kind of confirmation although I honestly think they are not very reliable
any kind of help is welcome!
Beforehand thank you very much 🙂
No body? or is there something not clear?
Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.
Be patient, someone will help you as soon as possible, sometimes earlier, sometimes later.
Thank you 🙂
How would you define “if it is against the trend” ?
Ciao Roberto, Buone feste 🙂
I define “against the trend” when you enter a trade that goes against the main trend, be it 1 day or 1h, entering minor planes to take advantage of the short-term correction but, I think it is quite subjective and somewhat complicated so this condition can be eliminated.
Grazie!
There you go:
DEFPARAM CumulateOrders = false
ONCE p = 100
ONCE PositionSize = 1
ONCE PerCent = 1
IF Not OnMarket THEN
SL = close * PerCent / 100
Ema35 = average[35,1](close)
Ema70 = average[70,1](close)
UPtrend = Ema35 > Ema70
DNtrend = Ema35 < Ema70
//
HH = highest[p](high)
LL = lowest[p](low)
Diff = HH - LL
// determine if the Fibonacci is Descending or Rising
UP = 0
DN = 0
FOR i = 0 TO (p - 1)
IF high[i] = HH THEN
UP = 1
BREAK
ENDIF
IF low[i] = LL THEN
DN = 1
BREAK
ENDIF
NEXT
// standard Fibonacci levels
IF UP THEN
Fib0236 = HH - Diff * 0.236
Fib0382 = HH - Diff * 0.382
Fib0500 = HH - Diff * 0.500
Fib0618 = HH - Diff * 0.618
Fib0764 = HH - Diff * 0.764
ELSIF DN THEN
Fib0236 = LL + Diff * 0.236
Fib0382 = LL + Diff * 0.382
Fib0500 = LL + Diff * 0.500
Fib0618 = LL + Diff * 0.618
Fib0764 = LL + Diff * 0.764
ENDIF
ENDIF
// entry
LongCond = Not OnMarket AND UP AND close CROSSES OVER Fib0618
ShortCond = Not OnMarket AND DN AND close CROSSES UNDER Fib0618
IF LongCond THEN
BUY PositionSize CONTRACTS AT MARKET
SET STOP LOSS SL
Exit1 = Fib0236
Exit2 = Fib0382
IF UPtrend THEN
SELL AT Exit1 LIMIT
ELSIF DNtrend THEN
SELL AT Exit2 LIMIT
ENDIF
ENDIF
IF ShortCond THEN
SELLSHORT PositionSize CONTRACTS AT MARKET
SET STOP LOSS SL
Exit1 = Fib0236
Exit2 = Fib0382
IF DNtrend THEN
EXITSHORT AT Exit1 LIMIT
ELSIF UPtrend THEN
EXITSHORT AT Exit2 LIMIT
ENDIF
ENDIF
// exit
IF LongOnMarket THEN
IF UPtrend THEN
SELL AT Exit1 LIMIT
ELSIF DNtrend THEN
SELL AT Exit2 LIMIT
ENDIF
ELSIF ShortOnMarket THEN
IF DNtrend THEN
EXITSHORT AT Exit1 LIMIT
ELSIF UPtrend THEN
EXITSHORT AT Exit2 LIMIT
ENDIF
ENDIF
//
//graph UP coloured("Green")
//graph DN coloured("Red")
//graph UPtrend coloured("Green")
//graph DNtrend coloured("Red")
//graphonprice Exit1 coloured("Gold")
//graphonprice Exit2 coloured("Grey")
Ciao Roberto!
I have been testing the code and it shows interesting results in a short time, the one that caught my attention the most was in the USD/CAD pair in 15 minutes, which for a period of 10 months was able to maintain consecutive positive results.
I’m just wondering about the drawdowns; and how risk management and results can be improved before putting the strategy to work in real.
I realized that the losses correspond to 1% of the price movement (relative perf %). Maybe it can be modified so that they are only between 1% and 3% of the capital of the account per operation?
***It is worth highlighting your deep knowledge and great help!!! I will be infinitely grateful to you from my heart since this means a lot to me and you are the only one who has been able to solidify my idea***
Grazie 🙂
This version sets a max 3% SL on a given Capital:
// my FIBO system 2
//
// https://www.prorealcode.com/topic/fibonacci-trading-backtest/
//
DEFPARAM CumulateOrders = False
DEFPARAM PreLoadBars = 0
ONCE p = 100
ONCE Capital= 10000
ONCE MaxSL = Capital / 100 * 3 //max 3% stop loss
ONCE UPflag = 0
ONCE DNflag = 0
IF Not onMarket THEN
HH = highest[p](high)
LL = lowest[p](low)
Diff = HH - LL
IF Diff <> Diff[1] THEN
UPflag = 0
DNflag = 0
ENDIF
Fib0236 = Diff * 0.236
Fib0382 = Diff * 0.382
Fib0500 = Diff * 0.500
Fib0618 = Diff * 0.618
Fib0764 = Diff * 0.764
Fib0850 = Diff * 0.850
Fib1272 = Diff * 1.272
Fib1382 = Diff * 1.382
UP = 0
DN = 0
FOR i = 0 TO (p - 1)
IF high[i] = HH THEN
UP = 1
LastBar = BarIndex[i]
BREAK
ENDIF
IF low[i] = LL THEN
DN = 1
LastBar = BarIndex[i]
BREAK
ENDIF
NEXT
BarsAfterFIBO = max(1,BarIndex - LastBar)
IF UP THEN
Fib0236 = HH - Fib0236
Fib0382 = HH - Fib0382
Fib0500 = HH - Fib0500
Fib0618 = HH - Fib0618
Fib0764 = HH - Fib0764
Fib0850 = HH - Fib0850
Fib1272 = LL + Fib1272
Fib1382 = LL + Fib1382
LastHH = lowest[BarsAfterFIBO](min(open,close))
IF LastHH < Fib0850 THEN
UPflag = -1
ENDIF
ELSIF DN THEN
Fib0236 = LL + Fib0236
Fib0382 = LL + Fib0382
Fib0500 = LL + Fib0500
Fib0618 = LL + Fib0618
Fib0764 = LL + Fib0764
Fib0850 = LL + Fib0850
Fib1272 = HH - Fib1272
Fib1382 = HH - Fib1382
LastLL = highest[BarsAfterFIBO](max(open,close))
IF LastHH > Fib0850 THEN
DNflag = -1
ENDIF
ENDIF
IF UP AND (UPflag = 0) THEN
IF (close < Fib0500) AND (BarsAfterFIBO >= 2) THEN
UPflag = 1
ENDIF
ELSIF DN AND (DNflag = 0) THEN
IF (close > Fib0500) AND (BarsAfterFIBO >= 2) THEN
DNflag = 1
ENDIF
ENDIF
ELSE
UPflag = 0
DNflag = 0
UP = 0
DN = 0
ENDIF
IF UP AND (UPflag = 1) AND (close >= Fib0382) AND Not OnMarket THEN
BUY 2 Contract at Market
//
MySL = abs((close - Fib0500) / PipSize)
MySL = min(MaxSL,MySL)
SET STOP $LOSS MySL //SELL AT Fib0500 STOP //SL
//
MyTP = abs(close - Fib1382) //SELL AT Fib1382 LIMIT //TP
SET TARGET PROFIT MyTP
ENDIF
IF DN AND (DNflag = 1) AND (close <= Fib0382) AND Not OnMarket THEN
SELLSHORT 2 Contract at Market
//
MySL = abs((close - Fib0500) / PipSize)
MySL = min(MaxSL,MySL)
SET STOP $LOSS MySL //SELL AT Fib0500 STOP //SL
//
MyTP = abs(close - Fib1382) //EXITSHORT AT Fib1382 LIMIT //TP
SET TARGET PROFIT MyTP
ENDIF
IF LongOnMarket THEN
//SELL AT Fib0500 STOP //SL
//SELL AT Fib1382 LIMIT //TP
IF close >= Fib1272 AND abs(CountOfPosition) = 2 THEN
SELL 1 Contract at Market //exit 50%
ENDIF
ELSIF ShortOnMarket THEN
//EXITSHORT AT Fib0500 STOP //SL
//EXITSHORT AT Fib1382 LIMIT //TP
IF close <= Fib1272 AND abs(CountOfPosition) = 2 THEN
EXITSHORT 1 Contract at Market //exit 50%
ENDIF
ENDIF
//graphonprice Fib1272 coloured("Red") AS "TP 1"
//graphonprice Fib1382 coloured("Blue") AS "TP 2"
//graphonprice Fib0500 coloured("Black") AS "SL"
//graph UP
//graph DN
//graph Diff <> Diff[1]
//graph UPflag
//graph DNflag
//graph LastBar
//graph BarsAfterFIBO
//graph MySL
//graph PositionPrice * PositionPerf
//graph abs(close - Fib0500) / pipsize