Write a code to automate my trading strategy
Forums › ProRealTime English forum › ProOrder support › Write a code to automate my trading strategy
- This topic has 6 replies, 2 voices, and was last updated 2 years ago by robertogozzi.
-
-
12/13/2022 at 10:13 AM #205692
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 reliableany kind of help is welcome!
Beforehand thank you very much 🙂12/14/2022 at 8:46 AM #20573112/14/2022 at 7:02 PM #205761Do 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” ?
12/26/2022 at 10:35 AM #206315Ciao 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!
01/11/2023 at 1:22 PM #207227There you go:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788DEFPARAM CumulateOrders = falseONCE p = 100ONCE PositionSize = 1ONCE PerCent = 1IF Not OnMarket THENSL = close * PerCent / 100Ema35 = average[35,1](close)Ema70 = average[70,1](close)UPtrend = Ema35 > Ema70DNtrend = Ema35 < Ema70//HH = highest[p](high)LL = lowest[p](low)Diff = HH - LL// determine if the Fibonacci is Descending or RisingUP = 0DN = 0FOR i = 0 TO (p - 1)IF high[i] = HH THENUP = 1BREAKENDIFIF low[i] = LL THENDN = 1BREAKENDIFNEXT// standard Fibonacci levelsIF UP THENFib0236 = HH - Diff * 0.236Fib0382 = HH - Diff * 0.382Fib0500 = HH - Diff * 0.500Fib0618 = HH - Diff * 0.618Fib0764 = HH - Diff * 0.764ELSIF DN THENFib0236 = LL + Diff * 0.236Fib0382 = LL + Diff * 0.382Fib0500 = LL + Diff * 0.500Fib0618 = LL + Diff * 0.618Fib0764 = LL + Diff * 0.764ENDIFENDIF// entryLongCond = Not OnMarket AND UP AND close CROSSES OVER Fib0618ShortCond = Not OnMarket AND DN AND close CROSSES UNDER Fib0618IF LongCond THENBUY PositionSize CONTRACTS AT MARKETSET STOP LOSS SLExit1 = Fib0236Exit2 = Fib0382IF UPtrend THENSELL AT Exit1 LIMITELSIF DNtrend THENSELL AT Exit2 LIMITENDIFENDIFIF ShortCond THENSELLSHORT PositionSize CONTRACTS AT MARKETSET STOP LOSS SLExit1 = Fib0236Exit2 = Fib0382IF DNtrend THENEXITSHORT AT Exit1 LIMITELSIF UPtrend THENEXITSHORT AT Exit2 LIMITENDIFENDIF// exitIF LongOnMarket THENIF UPtrend THENSELL AT Exit1 LIMITELSIF DNtrend THENSELL AT Exit2 LIMITENDIFELSIF ShortOnMarket THENIF DNtrend THENEXITSHORT AT Exit1 LIMITELSIF UPtrend THENEXITSHORT AT Exit2 LIMITENDIFENDIF////graph UP coloured("Green")//graph DN coloured("Red")//graph UPtrend coloured("Green")//graph DNtrend coloured("Red")//graphonprice Exit1 coloured("Gold")//graphonprice Exit2 coloured("Grey")4 users thanked author for this post.
01/15/2023 at 3:51 PM #207462Ciao 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 🙂
01/18/2023 at 4:31 PM #207628This version sets a max 3% SL on a given Capital:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130// my FIBO system 2//// https://www.prorealcode.com/topic/fibonacci-trading-backtest///DEFPARAM CumulateOrders = FalseDEFPARAM PreLoadBars = 0ONCE p = 100ONCE Capital= 10000ONCE MaxSL = Capital / 100 * 3 //max 3% stop lossONCE UPflag = 0ONCE DNflag = 0IF Not onMarket THENHH = highest[p](high)LL = lowest[p](low)Diff = HH - LLIF Diff <> Diff[1] THENUPflag = 0DNflag = 0ENDIFFib0236 = Diff * 0.236Fib0382 = Diff * 0.382Fib0500 = Diff * 0.500Fib0618 = Diff * 0.618Fib0764 = Diff * 0.764Fib0850 = Diff * 0.850Fib1272 = Diff * 1.272Fib1382 = Diff * 1.382UP = 0DN = 0FOR i = 0 TO (p - 1)IF high[i] = HH THENUP = 1LastBar = BarIndex[i]BREAKENDIFIF low[i] = LL THENDN = 1LastBar = BarIndex[i]BREAKENDIFNEXTBarsAfterFIBO = max(1,BarIndex - LastBar)IF UP THENFib0236 = HH - Fib0236Fib0382 = HH - Fib0382Fib0500 = HH - Fib0500Fib0618 = HH - Fib0618Fib0764 = HH - Fib0764Fib0850 = HH - Fib0850Fib1272 = LL + Fib1272Fib1382 = LL + Fib1382LastHH = lowest[BarsAfterFIBO](min(open,close))IF LastHH < Fib0850 THENUPflag = -1ENDIFELSIF DN THENFib0236 = LL + Fib0236Fib0382 = LL + Fib0382Fib0500 = LL + Fib0500Fib0618 = LL + Fib0618Fib0764 = LL + Fib0764Fib0850 = LL + Fib0850Fib1272 = HH - Fib1272Fib1382 = HH - Fib1382LastLL = highest[BarsAfterFIBO](max(open,close))IF LastHH > Fib0850 THENDNflag = -1ENDIFENDIFIF UP AND (UPflag = 0) THENIF (close < Fib0500) AND (BarsAfterFIBO >= 2) THENUPflag = 1ENDIFELSIF DN AND (DNflag = 0) THENIF (close > Fib0500) AND (BarsAfterFIBO >= 2) THENDNflag = 1ENDIFENDIFELSEUPflag = 0DNflag = 0UP = 0DN = 0ENDIFIF UP AND (UPflag = 1) AND (close >= Fib0382) AND Not OnMarket THENBUY 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 //TPSET TARGET PROFIT MyTPENDIFIF DN AND (DNflag = 1) AND (close <= Fib0382) AND Not OnMarket THENSELLSHORT 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 //TPSET TARGET PROFIT MyTPENDIFIF LongOnMarket THEN//SELL AT Fib0500 STOP //SL//SELL AT Fib1382 LIMIT //TPIF close >= Fib1272 AND abs(CountOfPosition) = 2 THENSELL 1 Contract at Market //exit 50%ENDIFELSIF ShortOnMarket THEN//EXITSHORT AT Fib0500 STOP //SL//EXITSHORT AT Fib1382 LIMIT //TPIF close <= Fib1272 AND abs(CountOfPosition) = 2 THENEXITSHORT 1 Contract at Market //exit 50%ENDIFENDIF//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) / pipsize1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on