End Of Day – YEN M15 Strategy
Forums › ProRealTime English forum › ProOrder support › End Of Day – YEN M15 Strategy
- This topic has 95 replies, 8 voices, and was last updated 1 year ago by ZeroCafeine.
-
-
04/08/2023 at 11:09 PM #213038
let’s do the V11 with only Long position, now I will try on M5 with 200k :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164// Strategy Name : END OF DAY - YEN// Version : 11.0// Information : Adding Box BreakOut in M5// Stroks : USD/JPY Mini// Time Frame : M5// Initial Capital : 100 000 JPY// Test on : 200K Candles// Spread : 2// ########################################################################Defparam cumulateorders = falsedefparam flatafter = 210000Once Capital = 100000Once Equity = CapitalOnce trailinstop= 1 //1 on - 0 offOnce breakeaven = 1 //1 on - 0 offOnce MFE=0 //1 on - 0 offN = 1 // Buy N SharesSL = 12 // Stop Loss = SL pipsSpread = 2 // Spread fees x 2TRAILINGMFE = 20// ########################################################################// ______ _ __//| ____| | | / \//| |__ ___ _ __ ___| || () |//| __/ _ \| '_ \ / __| __\__///| | | (_) | | | | (__| |_//|_| \___/|_| |_|\___|\__|if longonmarket thenAlreadyBuy=1endifif intradaybarindex=0 thenAlreadyBuy=0MyProfits = strategyprofitendifif time = 081000 thenyh = highest[74](high)yL=lowest[74](low)os = 2*pipsizeendifTimeCondition = time>081000 and time<200000// LONGSif TimeCondition and strategyprofit <= MyProfits thenif close<yh+os and not AlreadyBuy thenbuy 1 contract at yh+os stopendifendifIF LongOnMarket ThenSet Stop pLoss SLENDIF// ########################################################################// _______ _ _ _ _//|__ __| (_) | (_)// | |_ __ __ _ _| | |_ _ __ __ _// | | '__/ _<code>| | | | | '_ \ / _</code> |// | | | | (_| | | | | | | | | (_| |// |_|_| \__,_|_|_|_|_|_| |_|\__, |// __/ |// |___/trailingstart = 140 //trailing start after X pips profittrailingstep = 10 //trailing step to move the "stoploss"startBreakeven = 30 // Activate BE after startBreakeven pipsPointsToKeep = 5 // Spread to add to BE priceif trailinstop>0 thenIF NOT ONMARKET THENnewSL=0ENDIFIF LONGONMARKET THEN// Trailing StartIF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF// Trailing Step MoveIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFendifif breakeaven>0 thenIF NOT ONMARKET THENbreakevenLevel=0ENDIF//first move (breakeven)IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFendifif MFE>0 thenif not onmarket thenMAXPRICEMFE = 0MINPRICEMFE = closepriceexitMFE = 0endifif longonmarket thenMAXPRICEMFE = MAX(MAXPRICEMFE,close) //saving the MFE of the current tradeif MAXPRICEMFE-tradeprice(1)>=TRAILINGMFE*pointsize then //if the MFE is higher than the trailingstop thenpriceexitMFE = MAXPRICEMFE-TRAILINGMFE*pointsize //set the exit price at the MFE - trailing stop price levelendifendifif onmarket and priceexitMFE>0 thenSELL AT priceexitMFE STOPendifendif// ########################################################################// _____ _// / ____| | |// | | __ _ __ __ _ _ __ | |__// | | |_ | '__/ _` | '_ \| '_ \// | |__| | | | (_| | |_) | | | |// \_____|_| \__,_| .__/|_| |_|// | |// |_|//Graph floatingprofit AS "floatingprofit"//Graph PositionPerf * 100 AS "PositionPerf"//Graph PositionPerf(1) * 100 AS "PositionPerf[1]"//Graph floatingprofit AS "floatingprofit"//GraphOnPrice TradePricecoloured(0,220,0) AS "Long Trade Price"// Draw Equity//Graph Equity AS "Equity"//Graph Capital AS "Capital"// ########################################################################// _____ _ _____ _// / ____| | / ____| | |// | (___ | |_ ___ _ __ | (___ _ __ __ _| |_ ___ __ _ _ _// \___ \| __/ _ \| '_ \ \___ \| '__/ _<code>| __/ _ \/ _</code> | | | |// ____) | || (_) | |_) | ____) | | | (_| | || __/ (_| | |_| |// |_____/ \__\___/| .__/ |_____/|_| \__,_|\__\___|\__, |\__, |// | | __/ | __/ |// |_| |___/ |___/MaxDrawDownPercentage = 20 // Max DrawDown of x%Equity = Capital + StrategyProfitHighestEquity = Max (HighestEquity,Equity) // Save the Maximum Equity we gotMaxDrawdown = HighestEquity * (MaxDrawDownPercentage/100)ExitFromMarketCond = Equity <= HighestEquity - MaxDrawdownIF ExitFromMarketCond ThenQuitENDIFNext step is to add Short position and try do control this drawdown problem, and maybe next time is to control the quantity of share for enter with more share if the trade is positif and with more share if the equity is positif
1 user thanked author for this post.
04/21/2023 at 3:20 PM #213583Before continuing let’s set some good rules about the GTM schedule and the Tokyo session which opens from 09Am to 3Pm local time in Tokyo, If you think I’m wrong or that the code is not good, please participate 😉 :
123456789101112131415161718192021222324// Paris : 02H ================== 8H / UTC + 2// London : 01H ================== 7H / UTC + 1// GTM : 00H ================== 6H / UTC// Tokyo : 09H ================== 15H / UTC + 9// My UTC Time = UTC + 2if time = 081000 then //x1= barindex[0] //x2 = barindex[74] //yh = highest[74](high)yL=lowest[74](low)DRAWRECTANGLE(x1, yh, x2,yL ) COLOURED(0,0,0)os = 4*pipsizedrawtext("#yh#",x2,yh+os,SansSerif,bold,10) coloured(0,0,0)drawtext("#yL#",x2,yL-os,SansSerif,bold,10) coloured(0,0,0)endifif (time >= 061000 AND time <= 230000) thendrawsegment(x1,yh,barindex,yh) coloured (0,0,255) STYLE(DOTTEDLINE3,1)drawsegment(x1,yL,barindex,yL) coloured (0,0,255) STYLE(DOTTEDLINE3,1)endifreturn1 user thanked author for this post.
04/22/2023 at 6:12 PM #213614Thank you for sharing your code.
I only want to point out that those time offsets from UTC are valid when DST is active, when it is not, then 1 hour has to be subtracted from them.
In addition, with GTM you probably meant GMT, right?
1 user thanked author for this post.
04/22/2023 at 7:15 PM #213617Let’s say here is the new code, I reduced the size of the segments so that it stops just before the box, and I added the size of the range :
1234567891011121314151617181920212223242526// Indicator Name : Tokyo Box v2// Paris : 02H ================== 8H / UTC + 2// London : 01H ================== 7H / UTC + 1// GMT : 00H ================== 6H / UTC// Tokyo : 09H ================== 15H / UTC + 9// My UTC Time = UTC + 2IF Time = 081000 THENx2 = BarIndex[0]x1 = BarIndex[74]yH = Highest[74](High)yL = Lowest [74](Low)os = 4*pipsizeDayRange = (yH - yL) / pipsizeDrawRectangle(x2, yH, x1, yL) Coloured(0,0,0)DrawText("#yH#", x1, yH+os, SansSerif, Bold, 10) Coloured(0,0,0)DrawText("Range : #DayRange# Pips",((x2-x1)/2)+x1,yH+os,SansSerif,Bold,10) Coloured(0,0,0)DrawText("#yL#", x1, yL-os, SansSerif, Bold, 10) Coloured(0,0,0)ENDIFIF (Time >= 061000 AND Time <= 230000) thenDrawSegment(x2, yH, BarIndex-72, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)DrawSegment(x2, yL, BarIndex-72, yL) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)ENDIFReturn04/22/2023 at 7:20 PM #213619tks you @robertogozzi for your tips, what is DST Active or Not pls ?
and yes GTM it’s my French mistake, it’s GMT = UTC
04/23/2023 at 4:12 AM #213622DST stands for Daylight Saving Time (heure d’été).
In most EU it starts on the last Sunday of March at 02:00 (2am) and ends on the last Sunday of October at 02:00 (2am). In EU not all countries are at UTC+2 (UTC+1 when DST is not active), Portuga share the TZ with UK (now UTC+1), Greece, Finland, Rumenia etc… are now in UTC+3 (https://www.timeanddate.com/time/europe/).
Not all countries, across the world, as well as some states in USA, support DST.
1 user thanked author for this post.
04/23/2023 at 1:45 PM #213631Thank you very much for your answer and your tip, at first I thought it was an option I could enable or disable directly on the ProRealTime software, I think this is not the case, please correct me if I am wrong
So I had to think differently about my indicator and it made my head hurt 😅 but anyway I hope to make progress thanks to you 😊,
Here is a first version of the indicator with the summer hours and others
I don’t know yet how to manipulate the dates for the weekend when the time change, For the moment I stop before the last week of March and October (< day 24)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Indicator Name : Tokyo Box v2// GTM : 00H ================== 6H / UTC// Tokyo : 09H ================== 15H / UTC + 9 / JST (Japan Standard Time)// Paris : 02H ================== 8H / UTC + 2 / DST (Daylight Saving Time)// Paris : 01H ================== 7H / UTC + 1 / Winter// London : 01H ================== 7H / UTC + 1 / DST (Daylight Saving Time)// London : 00H ================== 6H / UTC + 0 / Winter// for Paris with Time Frame M5 :// When is DST : IntraDayBarIndex of 8:10H = 98// When Winter : IntraDayBarIndex of 7:10H = 86// https://www.timeanddate.com/time/europe/// ########################################################################FranceDstTime = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24)FranceWinterTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day <24)// this is the out of Tokyo-Box IntraDayBarIndex for FranceIF FranceDstTime THENIntraDayBarIndexStart = 98IntraDayBarIndexEnd = 23ELSIF FranceWinterTime THENIntraDayBarIndexStart = 86IntraDayBarIndexEnd = 11ENDIFIF IntraDayBarIndex = IntraDayBarIndexStart THENx2 = BarIndex[0]x1 = BarIndex[74]yH = Highest[74](High)yL = Lowest [74](Low)os = 4*pipsizeDayRange = (yH – yL) / pipsizeDrawRectangle(x2-1, yH, x1, yL) Coloured(0,0,0)DrawText(“#yH#”, x1, yH+os, SansSerif, Bold, 10) Coloured(0,0,0)DrawText(“Range : #DayRange# Pips”,((x2-x1)/2)+x1,yH+os,SansSerif,Bold,10) Coloured(0,0,0)DrawText(“#yL#”, x1, yL-os, SansSerif, Bold, 10) Coloured(0,0,0)ENDIFIF IntraDayBarIndex >= IntraDayBarIndexStart OR IntraDayBarIndex < IntraDayBarIndexEnd THENDrawSegment(BarIndex, yH, x2-1, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)DrawSegment(BarIndex, yL, x2-1, yL) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)ENDIFReturnif you have a link on the forum or an example it would be appreciated 😊
04/24/2023 at 9:24 PM #213700hi everyone
I am progressing slowly but surely, nothing exceptional, here is a draft in version 12, I’ll try to sort it out for version 13,
also I made the choice deliberately to be only long on the market, the programming of a strategy is already complicated so we are not going to complicate it even more with only one code for the Long and Short position at the same time, for the Short I let you reverse the code
at the moment I am trying to manage and control just the entries and their stop loss, I notice that if I have a position with more than one stock then the FirstSL is not well managed, this will be the next step
I also noted some notes in the code at the end just after the “Hello ToTo” logo, it allows me to remember what I’m doing and to find my notes in the code, if you have other origanisation solutions I’m interested
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232// Strategy Name : END OF DAY - YEN // Version : 12.0// Stroks : USD/JPY Mini // indicator associate : Tokyo Box v2// Time Zone / TF : Paris-France (GTM+2) / M5 //// Tokyo Session : 9Am - 3Pm (UTC+9) //// Spread : 2 //// Information :// ########################################################################Defparam cumulateorders = TrueOnce Capital = 100000Once Equity = CapitalOnce TrailinStop = 0 //1 on - 0 offOnce BreakEaven = 0 //1 on - 0 offOnce BreakRange = 1 //1 on - 0 offOnce MFE = 0 //1 on - 0 offOnce DrawDownQuit = 0 //1 on - 0 offOnce MaxBuyPerDay = 15 // Maximum shares we can buy per day // Z2MaxLostPerDay = 10 // We can buy until we don't lost 10€ per DayOnce MaxBuyShare = 10 // Maximum of shares we can buy (Marging)Once TRAILINGMFE = 20 // Trailing stop with the Max Favorable ExcursionOnce N = 1 // Buy N SharesOnce Spread = 2 // Spread fees x 2FranceDstTime = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24)FranceWinterTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24)// ########################################################################// Fonct°IF FranceDstTime THEN // CcIntraDayBarIndexStart = 98IntraDayBarIndexEnd = 23ELSIF FranceWinterTime THENIntraDayBarIndexStart = 86IntraDayBarIndexEnd = 11ENDIFIF IntraDayBarIndex = IntraDayBarIndexStart THEN // Ac & Ccx2 = BarIndex[0]x1 = BarIndex[74]yH = Highest[72](High[2])yL = Lowest [72](Low[2])DayRange = (yH - yL) / pipsizeENDIFIF NOT OnMarket THEN // DcFirstSL = 0ENDIFIF IntraDayBarIndex = 24 THEN // EcCountOfPurchase = 0 // Z3AlreadyBought = 0MyProfitInTheBeginingOfDay = StrategyProfitLastCountOfPosition = CountOfPositionENDIFMyDayProfit = StrategyProfit - MyProfitInTheBeginingOfDayDayLostCondition = (MyDayProfit/Medianprice) > MaxLostPerDay*(-1)TimeCondition = (Time > 081000 AND Time < 200000 AND DayOfWeek < 5) OR (Time > 081000 AND Time < 170000 AND DayOfWeek = 5) // TcLongSignal = TimeCondition AND Close Crosses Over yH // LcIF LongSignal AND Not OnMarket Then // LcFirstSL = yH - ((yH-yL)/10)// HcENDIFif TimeCondition then // TIF LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND CountOfPosition = LastCountOfPosition THENBuy N Contract AT MarketSET STOP PRICE FirstSLENDIFendifIF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THENCountOfPurchase = CountOfPurchase + 1ENDIF// ########################################################################// Trailing & BreakEven & Range Stop Loss & MFEOnce trailingstart = 140 //trailing start after X pips profitOnce trailingstep = 10 //trailing step to move the "stoploss"Once startBreakeven = 30Once StartBreakRangePercent = 20Once PointsToKeep = 2*Spread // Spread to add to BE price// Trailingif TrailinStop > 0 then // Needs to be improvedIF NOT ONMARKET THENNewSL=0ENDIFIF LONGONMARKET THEN// Trailing StartIF NewSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENNewSL = tradeprice(1)+trailingstep*pipsizeENDIF// Trailing Step MoveIF NewSL>0 AND close-NewSL>=trailingstep*pipsize THENNewSL = NewSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF NewSL>0 THENSELL AT NewSL STOPENDIFendif// BreakEvenif breakeaven>0 then // Needs to be improvedIF NOT ONMARKET THENbreakevenLevel=0ENDIF//first move (breakeven)IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFendif// Range Stop Lossif BreakRange > 0 then // FcIF Not OnMarket THENBreakRangeLevel = 0ENDIFIF LongOnMarket THENStartBreakRange = yH + (((yH-yL)/100 )*StartBreakRangePercent)ENDIFIF LongOnMarket AND Close >= StartBreakRange THEN // Z1BreakRangeLevel = yH - 2*Pipsize // GcENDIFIF BreakRangeLevel>0 THENSET STOP PRICE BreakRangeLevelENDIFendifif MFE > 0 then // Needs to be improvedif not onmarket thenMAXPRICEMFE = 0MINPRICEMFE = closepriceexitMFE = 0endifif longonmarket thenMAXPRICEMFE = MAX(MAXPRICEMFE,close) //saving the MFE of the current tradeif MAXPRICEMFE-tradeprice(1)>=TRAILINGMFE*pointsize then //if the MFE is higher than the trailingstop thenpriceexitMFE = MAXPRICEMFE-TRAILINGMFE*pointsize //set the exit price at the MFE - trailing stop price levelendifendifif onmarket and priceexitMFE>0 thenSELL AT priceexitMFE STOPendifendif// ########################################################################// Graph// ########################################################################// Stop StrategyIF DrawDownQuit Then // Needs to be improvedMaxDrawDownPercentage = 10 // Max DrawDown of x%Equity = Capital + StrategyProfitHighestEquity = Max (HighestEquity,Equity) // Save the Maximum Equity we gotMaxDrawdown = HighestEquity * (MaxDrawDownPercentage/100)ExitFromMarketCond = Equity <= HighestEquity - MaxDrawdownIF ExitFromMarketCond ThenQuitENDIFENDIF// ########################################################################// _ _ _ _ _______ _______// | | | | | | | |__ __|__ __|// | |__| | ___| | | ___ | | ___ | | ___// | __ |/ _ \ | |/ _ \ | |/ _ \| |/ _ \// | | | | __/ | | (_) | | | (_) | | (_) |// |_| |_|\___|_|_|\___/ |_|\___/|_|\___/// GMT : 00H ================== 6H / UTC// Tokyo : 09H ================== 15H / UTC + 9 / JST (Japan Standard Time)// Paris : 02H ================== 8H / UTC + 2 / DST (Daylight Saving Time)// Paris : 01H ================== 7H / UTC + 1 / Winter// London : 01H ================== 7H / UTC + 1 / DST (Daylight Saving Time)// London : 00H ================== 6H / UTC + 0 / Winter// for Paris with Time Frame M5 :// When is DST : IntraDayBarIndex of 8:10H = 98// When Winter : IntraDayBarIndex of 7:10H = 86// https://www.timeanddate.com/time/europe/// Rules : Xc = X-Condition// Ac : Tokyo Box mean Tokyo trading session from 9Am to 3Pm Local time (JST// Means from 00 to 6Am GMT, you have to addapt with your contry// Bc : Our Trading it's from 3Pm at Tokoy so from 8:10Am in Prais when DST and 7:10Am when Winter// Cc : When we are in DST and when we are in Winter// Dc : IF Not On Market, I reset the First Stop Loss// Ec : We reset the Count of some variable we need to use at 2Am = IntraDayBarIndex = 24// So in the first candle of Tokyo Box// And we store some variable that we will need// Fc : Initialise the StartBreakRange with a dynmic value and not static one,// the math is the Range value + StartBreakRangePercent%,// Exmeple :// Range (yH-yL) = 60Pips & yH = 142,219 & StartBreakRangePercent = 20%// means we set the NewSL below the Highest - 2 pips (yH -2)// 142,219 + (60Pips x 20%) = 142,219 + 12Pips = 142,339 JPY// Gc : the idea is to put a stop loss 2 pips down then the highest value of the range// Hc : Initialisation du First Stop Loss, We assume that the box will be broken// and that the break is real, so in this case we put a stop loss at 10% below the high// Tc : Time condition, we bay only after Tokyo Box (A) and before 8Pm for all the day of week exept the Day 5 = Friday we stop at 5Pm// Lc : initialise the First Stop Loss if we get a Close > the Tokyo Box// and we are in TimeCondition (Tc)// #################// Z1 : I have to find a better solutoion the the Close option// Z2 : better to control the value of this variable : MaxBuyPerDay by the money// we can lose in 1 days, So I have to count my Profit per day// Z3 : I noticed when the Buy and Sell order is in the same candle so the CountOfPurchase// still the same and it's not incremented with +104/25/2023 at 12:45 PM #213716no need answers now, just speack to myself 😁
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263// Strategy Name : END OF DAY - YEN // Version : 13.0// Stroks : USD/JPY Mini // indicator associate : Tokyo Box v2// Time Zone / TF : Paris-France (GTM+2) / M5 //// Tokyo Session : 9Am - 3Pm (UTC+9) //// Spread : 2 //// Information : le SET STOP PRICE FirstSL et que ma position est superieur à 1 shares// ########################################################################Once Capital = 100000Once Equity = CapitalOnce TrailinStop = 0 //1 on - 0 offOnce BreakEaven = 0 //1 on - 0 offOnce BreakRange = 1 //1 on - 0 offOnce MFE = 0 //1 on - 0 offOnce DrawDownQuit = 0 //1 on - 0 offOnce MaxBuyPerDay = 15 // Maximum shares we can buy per day // Z2Once MaxLostPerDay = 10 // We can buy until we don't lost 10€ per DayOnce MaxBuyShare = 10 // Maximum of shares we can buy (Marging math)Once PercentOfBoxSL = 10 // Percent of Tokyo Box for Initialization the First Stop LossOnce N = 1 // Buy N SharesOnce Spread = 2 // Spread fees x 2FranceDstTime = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24) // Z5FranceWinterTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24) // Z5// ########################################################################// Fonct°IF FranceDstTime THEN // CcIntraDayBarIndexStart = 98IntraDayBarIndexEnd = 23ELSIF FranceWinterTime THENIntraDayBarIndexStart = 86IntraDayBarIndexEnd = 11ENDIFIF IntraDayBarIndex = IntraDayBarIndexStart THEN // Ac & Ccx2 = BarIndex[0]x1 = BarIndex[74]yH = Highest[72](High[2])yL = Lowest [72](Low[2])DayRange = (yH - yL) / pipsizeENDIFIF NOT OnMarket THEN // DcFirstSL = 0ENDIFIF IntraDayBarIndex = 24 THEN // EcCountOfPurchase = 0 // Z3MyProfitInTheBeginingOfDay = StrategyProfitLastDayCountOfPosition = CountOfPosition // KcENDIFMyDayProfit = StrategyProfit - MyProfitInTheBeginingOfDayDayLostCondition = (MyDayProfit/Medianprice) > MaxLostPerDay*(-1) // JcTimeCondition = (Time > 081000 AND Time < 200000 AND DayOfWeek < 5) OR (Time > 081000 AND Time < 170000 AND DayOfWeek = 5) // TcLongSignal = TimeCondition AND Close Crosses Over yH // LcIF LongSignal Then // LcFirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // HcENDIFif TimeCondition then // TcLongSignalAllCondition = LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND (CountOfPosition = LastDayCountOfPosition OR Not OnMarket)IF LongSignalAllCondition THENBuy N Contract AT MarketSET STOP PRICE FirstSLENDIFendifIF LongOnMarket AND CountOfPosition > 1 THEN // Z6Sell CountOfPosition Shares AT FirstSL STOPENDIFIF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THENCountOfPurchase = CountOfPurchase + 1ENDIF// ########################################################################// Trailing & BreakEven & Range Stop Loss & MFEOnce trailingstart = 140 //trailing start after X pips profitOnce trailingstep = 10 //trailing step to move the "stoploss"Once startBreakeven = 30Once StartBreakRangePercent = 20Once PointsToKeep = 2*Spread // Spread to add to BE priceOnce TRAILINGMFE = 20 // Trailing stop with the Max Favorable Excursion// Trailingif TrailinStop > 0 then // Needs to be improvedIF NOT ONMARKET THENNewSL=0ENDIFIF LONGONMARKET THEN// Trailing StartIF NewSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENNewSL = tradeprice(1)+trailingstep*pipsizeENDIF// Trailing Step MoveIF NewSL>0 AND close-NewSL>=trailingstep*pipsize THENNewSL = NewSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF NewSL>0 THENSELL AT NewSL STOPENDIFendif// BreakEvenif breakeaven>0 then // Needs to be improvedIF NOT ONMARKET THENbreakevenLevel=0ENDIF//first move (breakeven)IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFendif// Range Stop Lossif BreakRange > 0 then // FcIF Not OnMarket THENBreakRangeLevel = 0ENDIFIF LongOnMarket THENStartBreakRange = yH + (((yH-yL)/100)*StartBreakRangePercent)ENDIFIF LongOnMarket AND Close >= StartBreakRange THEN // Z1BreakRangeLevel = yH - 2*Pipsize // GcENDIFIF BreakRangeLevel>0 THENSET STOP PRICE BreakRangeLevelENDIFendifif MFE > 0 then // Needs to be improvedif not onmarket thenMAXPRICEMFE = 0MINPRICEMFE = closepriceexitMFE = 0endifif longonmarket thenMAXPRICEMFE = MAX(MAXPRICEMFE,close) //saving the MFE of the current tradeif MAXPRICEMFE-tradeprice(1)>=TRAILINGMFE*pointsize then //if the MFE is higher than the trailingstop thenpriceexitMFE = MAXPRICEMFE-TRAILINGMFE*pointsize //set the exit price at the MFE - trailing stop price levelendifendifif onmarket and priceexitMFE>0 thenSELL AT priceexitMFE STOPendifendif// ########################################################################// Graph// ########################################################################// Stop StrategyIF DrawDownQuit Then // Needs to be improvedMaxDrawDownPercentage = 10 // Max DrawDown of x%Equity = Capital + StrategyProfitHighestEquity = Max (HighestEquity,Equity) // Save the Maximum Equity we gotMaxDrawdown = HighestEquity * (MaxDrawDownPercentage/100)ExitFromMarketCond = Equity <= HighestEquity - MaxDrawdownIF ExitFromMarketCond ThenQuitENDIFENDIF// ########################################################################// _ _ _ _ _______ _______// | | | | | | | |__ __|__ __|// | |__| | ___| | | ___ | | ___ | | ___// | __ |/ _ \ | |/ _ \ | |/ _ \| |/ _ \// | | | | __/ | | (_) | | | (_) | | (_) |// |_| |_|\___|_|_|\___/ |_|\___/|_|\___/// GMT : 00H ================== 6H / UTC// Tokyo : 09H ================== 15H / UTC + 9 / JST (Japan Standard Time)// Paris : 02H ================== 8H / UTC + 2 / DST (Daylight Saving Time)// Paris : 01H ================== 7H / UTC + 1 / Winter// London : 01H ================== 7H / UTC + 1 / DST (Daylight Saving Time)// London : 00H ================== 6H / UTC + 0 / Winter// for Paris with Time Frame M5 :// When is DST : IntraDayBarIndex of 8:10H = 98// When Winter : IntraDayBarIndex of 7:10H = 86// https://www.timeanddate.com/time/europe/// Rules : Xc = X-Condition// Ac : Tokyo Box : 9Am to 3Pm Local time (JST) = 00 to 6Am GMT// Bc : Our Trading it's from 3Pm at Tokoy so from 8:10Am in Paris when DST / 7:10Am when Winter// Cc : Tokyo Box based on IntraDayBarIndex with DST and Winter Time// Dc : IF Not On Market, I reset the First Stop Loss to 0// Ec : We reset the Count of some variable we need to use at 2Am = IntraDayBarIndex = 24// So in the first candle of Tokyo Box// And we store some variable that we will need the day after// Fc : Initialise the StartBreakRange with a dynmic value and not static one,// the math is the Range value + StartBreakRangePercent%,// Exmeple :// Range (yH-yL) = 60Pips & yH = 142,219 & StartBreakRangePercent = 20%// means we set the NewSL below the Highest - 2 pips (yH -2)// 142,219 + (60Pips x 20%) = 142,219 + 12Pips = 142,339 JPY// Gc : the idea is to put a stop loss 2 pips down then the highest value of the range// Hc : Initialization of the First Stop Loss, We assume that the box will be broken// and that the break is real, so in this case we put a stop loss at 10%// below the highest of the Tokyo Box// Jc : if we lost more then MaxLostPerDay € (exemple 10€) per day, we can't buy more,// fees not include// Kc : We memorise the last count to position to compair to the one of today// Tc : Time Conditions, we bay only after Tokyo Box (A) and before 8Pm for all the day of week// exept the Day 5 = Friday we stop at 5Pm// Lc : Long signal if we Close > the Tokyo Box and we are in TimeCondition (Tc)// ################# Idea to be developed and questions #################// Z1 : I have to find a better solutoion the the Close option// Z2 : better to control the value of this variable : MaxBuyPerDay by the money// we can lose in 1 days, So I have to count my Profit per day// Z3 : I noticed when the Buy and Sell order is in the same candle so the CountOfPurchase// still the same and it's not incremented with +1// Z5 : I have to finish this DST and Winter works// Z6 : I add this code : "Sell CountOfPosition Shares AT FirstSL STOP" for exeit from position// when my countofposition is more the 1, I noticed the code : "SET STOP PRICE FirstSL" not// working is my position is more then 1 but the same code working with// the : "SET STOP PRICE BreakRangeLevel"// ################# Explanation of the code #################// Code : (CountOfPosition = LastDayCountOfPosition OR Not OnMarket)// - IF I'm on market I have to compare LastDayCountOfPosition like that I can't// buy more if my Long condition = 1// - IF my LastDayCountOfPosition so I can't compare, that is why I use OR Not OnMarket// ################# Last programming where I stopped at #################// I solved the problem of FirstSL Exit when my position is more the 1 shares but I get the same problem before when the longcondition by many share after breaking the range04/25/2023 at 1:46 PM #213723I also noted some notes in the code at the end just after the “Hello ToTo” logo, it allows me to remember what I’m doing and to find my notes in the code, if you have other origanisation solutions I’m interested
Tip: to find whatever I need to find in long codes (notes, but also groups of code lines far away from each other but related), I often add keyword(s) with //, not used anywhere else in the code, and the CTRL+F (“find”) function applied to said keyword(s), in order to save time scrolling/searching by jumping with “find” from one occurrence to the next.
1 user thanked author for this post.
04/25/2023 at 4:54 PM #213735I found solution to my problem by adding this code at line 63 in v 13 :
123IF TimeCondition AND Not OnMarket THENLastDayCountOfPosition = 0ENDIF04/25/2023 at 4:55 PM #213736@JC_Bywan tks you so much for you tips, but I don’t realy understand the idea, do you have a photo or link pls 😃 ?
04/25/2023 at 7:48 PM #213745Photo of your code inside an editor window: click on magnifying glass (or click mouse inside code area and press CTRL+F), then let’s say you want to find fast your “needs to be improved” comments not wasting time scrolling, you type it next to “find”/”rechercher”, then click on “next”/suivant, and it will jump from one to the next, and when reaching last one if clicking next again it goes back up to first one.
1 user thanked author for this post.
04/30/2023 at 1:31 PM #213889Hello everyone, I hope you are well
By the way, thank you very much @JC_Bywan for your answer 😊
Here is version 15 of my code, before I start trying to make money I mainly want to try and control my losses, and I run into a small problem when I have multiple levels of stop output sometimes I get run on a worse level I guess it’s a programming issue,
You can see a capture with three output levels respectively, I renamed for ease in SL 1,2 and 3
SL-3 = BreakRangeLevel (green)
SL-2 = BreakRangeStarter (blue)
SL-1 = FirstSL (Red)Sometimes my long position is taken out only at the SL-1 level while the other levels are already there, I don’t know what to do?
As I know it’s a bit complicated for some people to reread all the code and understand I also opened a new post where I phrased the question differently and so here’s the link you might be able to answer me on that post instead of this one I hope I don’t get rapped for a double post
once I have mastered this problem of the three levels of SL I think I will move on to the calculation of daily losses, and latent losses or gains
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317// Strategy Name : END OF DAY - YEN // Version : 14.0// Stroks : USD/JPY Mini // indicator associate : Tokyo Box v2// Time Zone / TF : Paris-France (GTM+2) / M5 //// Tokyo Session : 9Am - 3Pm (UTC+9) //// Spread : 2 //// Information : le SET STOP PRICE FirstSL et que ma position est superieur à 1 shares// ########################################################################Once Capital = 100000Once Equity = CapitalOnce TrailinStop = 0 //1 on - 0 offOnce BreakEaven = 1 //1 on - 0 offOnce BreakRange = 1 //1 on - 0 offOnce MFE = 0 //1 on - 0 offOnce DrawDownQuit = 0 //1 on - 0 offOnce MaxBuyPerDay = 15 // Maximum shares we can buy per day // Z2Once MaxLostPerDay = 10 // We can buy until we don't lost 10€ per DayOnce MaxBuyShare = 10 // Maximum of shares we can buy (Marging math)Once PercentOfBoxSL = 10 // Percent of Tokyo Box for Initialization the First Stop LossOnce N = 1 // Buy N SharesOnce Spread = 2 // Spread fees x 2FranceDstTime = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24) // Z5FranceWinterTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24) // Z5// ########################################################################// Fonct°IF FranceDstTime THEN // CcIntraDayBarIndexStart = 98IntraDayBarIndexEnd = 23ELSIF FranceWinterTime THENIntraDayBarIndexStart = 86IntraDayBarIndexEnd = 11ENDIFIF IntraDayBarIndex = IntraDayBarIndexStart THEN // Ac & Ccx2 = BarIndex[0]x1 = BarIndex[74]yH = Highest[72](High[2])yL = Lowest [72](Low[2])DayRange = (yH - yL) / pipsizeENDIFIF NOT OnMarket THEN // DcFirstSL = 0ENDIFIF IntraDayBarIndex = 24 THEN // EcCountOfPurchase = 0 // Z3MyProfitInTheBeginingOfDay = StrategyProfitLastDayCountOfPosition = CountOfPosition // KcENDIFMyDayProfit = StrategyProfit - MyProfitInTheBeginingOfDayDayLostCondition = (MyDayProfit/Medianprice) > MaxLostPerDay*(-1) // Jc & Z7TimeCondition = (Time > 081000 AND Time < 200000 AND DayOfWeek < 5) OR (Time > 081000 AND Time < 170000 AND DayOfWeek = 5) // TcLongSignal = TimeCondition AND Close Crosses Over yH // LcIF LongSignal Then // LcFirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // HcENDIFIF TimeCondition AND Not OnMarket THENLastDayCountOfPosition = 0ENDIFif TimeCondition then // TcLongSignalAllCondition = LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND (CountOfPosition <= LastDayCountOfPosition)IF LongSignalAllCondition THENBuy N Contract AT MarketSET STOP PRICE FirstSLENDIFendifIF LongOnMarket AND CountOfPosition > 1 THEN // Z6Sell CountOfPosition Shares AT FirstSL STOPENDIFIF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THENCountOfPurchase = CountOfPurchase + 1ENDIF// ########################################################################// Trailing & BreakEven & Range Stop Loss & MFEOnce trailingstart = 140 // Trailing start after X pips profitOnce trailingstep = 10 // Trailing step to move the "stoploss"Once StartBreakEven = 30 // BE Start for the hole positionOnce StartBreakRangePercent = 20Once PointsToKeep = 2*Spread // Spread to add to BE priceOnce TRAILINGMFE = 20 // Trailing stop with the Max Favorable Excursion// Trailingif TrailinStop > 0 then // Needs to be improvedIF NOT ONMARKET THENNewSL=0ENDIFIF LONGONMARKET THEN// Trailing StartIF NewSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENNewSL = tradeprice(1)+trailingstep*pipsizeENDIF// Trailing Step MoveIF NewSL>0 AND close-NewSL>=trailingstep*pipsize THENNewSL = NewSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF NewSL>0 THENSELL AT NewSL STOPENDIFendif// BreakEvenif BreakEaven>0 thenIF Not OnMarket THENBreakEvenLevel = 0 // As a StarterENDIF//first move (breakeven)RRMore = (5*(yH-FirstSL))IF LongOnMarket AND Close - yH >= RRMore THENif CountOfPosition = 1 then//calculate the breakevenLevelBreakEvenLevel = PositionPrice+PointsToKeep*pipsizeelsif CountOfPosition > 1 thenBreakEvenLevel = yH + PointsToKeep*pipsizeendifENDIFIF BreakEvenLevel > 0 THENSELL AT BreakEvenLevel STOPENDIFendif// Range Stop Lossif BreakRange > 0 then // FcIF Not OnMarket THENBreakRangeStarter = 0 // As a StarterENDIFIF LongOnMarket THENBreakRangeLevel = TradePrice + (((yH-yL)/100)*StartBreakRangePercent) // Level for StarterENDIFIF LongOnMarket AND Close >= BreakRangeLevel THEN // Z1BreakRangeStarter = yH - 2*Pipsize // GcENDIFIF BreakRangeStarter > 0 AND BreakEvenLevel = 0 THEN //Z8SELL AT BreakRangeStarter STOP // As a StarterSET STOP PRICE BreakRangeStarterENDIFendifif MFE > 0 then // Needs to be improvedif not onmarket thenMAXPRICEMFE = 0MINPRICEMFE = closepriceexitMFE = 0endifif longonmarket thenMAXPRICEMFE = MAX(MAXPRICEMFE,close) //saving the MFE of the current tradeif MAXPRICEMFE-tradeprice(1)>=TRAILINGMFE*pointsize then //if the MFE is higher than the trailingstop thenpriceexitMFE = MAXPRICEMFE-TRAILINGMFE*pointsize //set the exit price at the MFE - trailing stop price levelendifendifif onmarket and priceexitMFE>0 thenSELL AT priceexitMFE STOPendifendifIF BreakRangeStarter = 0 THENSET STOP PRICE 0ENDIF// ########################################################################// Graph //// Blue Azur (0, 127, 255) & Maya (115, 194, 251)// Green Sinople (20, 148, 20) &IF 1 THEN//Graphonprice BreakEvenLevel AS "BreakEvenLevel"//graphonprice FirstSL AS "FirstSL"//Graphonprice BreakEvenLevel AS "BreakEvenLevel"graphonprice PositionPrice AS "PositionPrice" Coloured (0, 0, 255)yHplusFirstSL = yH + (5*(yH-FirstSL))GraphOnPrice BreakEvenLevel AS "BreakEvenLevel" Coloured (20, 148, 20)GraphOnPrice yHplusFirstSL AS "yHplusFirstSL"Coloured (20, 148, 20)GraphOnPrice BreakRangeLevel AS "BreakRangeLevel" Coloured (115, 194, 251)GraphOnPrice BreakRangeStarter AS "BreakRangeStarter" Coloured (115, 194, 251)GraphOnPrice FirstSL AS "FirstSL" Coloured (233, 56, 63)//graphonprice yHplusFirstSL AS "yHplusFirstSL"//graphonprice BreakEvenLevel AS "BreakEvenLevel"Difference = 5*(yH-FirstSL)//graph Difference AS "Difference"ENDIF// ########################################################################// Stop StrategyIF DrawDownQuit Then // Needs to be improvedMaxDrawDownPercentage = 10 // Max DrawDown of x%Equity = Capital + StrategyProfitHighestEquity = Max (HighestEquity,Equity) // Save the Maximum Equity we gotMaxDrawdown = HighestEquity * (MaxDrawDownPercentage/100)ExitFromMarketCond = Equity <= HighestEquity - MaxDrawdownIF ExitFromMarketCond ThenQuitENDIFENDIF// ########################################################################// _ _ _ _ _______ _______// | | | | | | | |__ __|__ __|// | |__| | ___| | | ___ | | ___ | | ___// | __ |/ _ \ | |/ _ \ | |/ _ \| |/ _ \// | | | | __/ | | (_) | | | (_) | | (_) |// |_| |_|\___|_|_|\___/ |_|\___/|_|\___/// GMT : 00H ================== 6H / UTC// Tokyo : 09H ================== 15H / UTC + 9 / JST (Japan Standard Time)// Paris : 02H ================== 8H / UTC + 2 / DST (Daylight Saving Time)// Paris : 01H ================== 7H / UTC + 1 / Winter// London : 01H ================== 7H / UTC + 1 / DST (Daylight Saving Time)// London : 00H ================== 6H / UTC + 0 / Winter// for Paris with Time Frame M5 :// When is DST : IntraDayBarIndex of 8:10H = 98// When Winter : IntraDayBarIndex of 7:10H = 86// https://www.timeanddate.com/time/europe/// ================== Stop Loss Level ==================// Order of Exit :// BreakRangeStarter// FirstSL// ================== Stop Loss Level ==================// Rules : Xc = X-Condition// Ac : Tokyo Box : 9Am to 3Pm Local time (JST) = 00 to 6Am GMT// Bc : Our Trading it's from 3Pm at Tokoy so from 8:10Am in Paris when DST / 7:10Am when Winter// Cc : Tokyo Box based on IntraDayBarIndex with DST and Winter Time// Dc : IF Not On Market, I reset the First Stop Loss to 0// Ec : We reset the Count of some variable we need to use at 2Am = IntraDayBarIndex = 24// So in the first candle of Tokyo Box// And we store some variable that we will need the day after// Fc : Initialise the StartBreakRange with a dynmic value and not static one,// the math is the Range value + StartBreakRangePercent%,// Exmeple :// Range (yH-yL) = 60Pips & yH = 142,219 & StartBreakRangePercent = 20%// means we set the NewSL below the Highest - 2 pips (yH -2)// 142,219 + (60Pips x 20%) = 142,219 + 12Pips = 142,339 JPY// Gc : the idea is to put a First Stop Loss 2 pips down then the highest value of the range// before the BreakEven level// Hc : Initialization of the First Stop Loss, We assume that the box will be broken// and that the break is real, so in this case we put a stop loss at 10%// below the highest of the Tokyo Box// Jc : if we lost more then MaxLostPerDay € (exemple 10€) per day, we Can Not buy more,// fees not include// Kc : We memorise the last count to position to compair to the one of today// Mc : we set the SL to BE level + Fees (I have to chek fees for all position) when the price// reach a RR of 5, we let the trade breath// Tc : Time Conditions, we bay only after Tokyo Box (A) and before 8Pm for all the day of week// exept the Day 5 = Friday we stop at 5Pm// Lc : Long signal if we Close > the Tokyo Box and we are in TimeCondition (Tc)// ################# Idea to be developed and questions #################// Z1 : I have to find a better solutoion the the Close option// Z2 : better to control the value of this variable : MaxBuyPerDay by the money// we can lose in 1 days, So I have to count my Profit per day// Z3 : I noticed when the Buy and Sell order is in the same candle so the CountOfPurchase// still the same and it's not incremented with +1// Z5 : I have to finish this DST and Winter works// Z6 : I add this code : "Sell CountOfPosition Shares AT FirstSL STOP" for exeit from position// when my countofposition is more the 1, I noticed the code : "SET STOP PRICE FirstSL" not// working is my position is more then 1 but the same code working with// the : "SET STOP PRICE BreakRangeLevel"// Z6 : I submit this line (as in but interrogations on the execution of the SL)// that this line does not expect the Close to be off the SL to get me out, but it// is a tick by tick execution// Z7 : if last day we win some money, we can allocate part of these gains to future trades,// which will allow us to take more positions for example (N > 1)// Z8 : je doit faire une verification des ordre exécuté l'un avant lautre// ################# Explanation of the code #################// Code : (CountOfPosition = LastDayCountOfPosition OR Not OnMarket)// - IF I'm on market I have to compare LastDayCountOfPosition like that I can't// buy more if my Long condition = 1// - IF my LastDayCountOfPosition so I can't compare, that is why I use OR Not OnMarket// ################# Last programming where I stopped at #################// problem of entry is ok with the new code : "LastDayCountOfPosition = 0",// I get a new problem, if the price don't CLose the yH so my FirstSL is not working, it have the same value of the last Tokyyo Box yH[1]-10%, exemple in M5 Date 25/04 at 17:52// I have to take a look to the order of SET STOP PRICE, in my case : bcause of the BE Range is below the BELevel, so in this case the BELevel it's not executedtks you
1 user thanked author for this post.
04/30/2023 at 6:08 PM #213907I think they overcomplicate a lot and if in doubt the code is over optimized. Have you tried running the code for at least several months? What does the back test look like?
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on