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.
-
-
05/03/2023 at 1:10 PM #214064
Well, normally you code a strategy where you have the feeling that it generates stable profits over a long period of time. So… correct me… I thought that was your goal?
1 user thanked author for this post.
05/03/2023 at 11:58 PM #214101I start this topic to discuss this strategy and understand it and why not improve it and at the same time learn to program
that is the goal of this thread : learn to program , I think that if you have a good command of programming and consequently good money management rules and a precise management of inputs and outputs (or at least understand why you are executing favourably or unfavourably) you can then transform a losing strategy into a winning strategy
As far as winning or not winning strategies are concerned, I think there are plenty of them on the Internet, but how can you test them if you don’t master programming properly, and as GraHal says, you can sometimes end up with good strategies by making mistakes
I hope I have answered your question
05/08/2023 at 2:44 PM #214299hello
I’m going to go back to version 21 and remove the functions with the IntraDayBarIndex and replace them with the Time functions, I think it will make my head hurt less while I improve the code a bit,
Also I’ll remove the DST issue temporarily until I find a good solution
And to include some money management ideas that we will call idea B that you can find on this thread
05/09/2023 at 3:02 AM #214331Nothing exceptional but I will use the time function TIME instead of the INTRADAYBARINDEX function for my indicator Tokyo Box v3 and also my strategy :
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253// Indicator Name : Tokyo Box v3// Date : 09/05/2023// 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// The candles that are crossed by the frame are not included in the Tokyo session// https://www.timeanddate.com/time/europe/// Work on the DST is not yet complete// ########################################################################FranceDST = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24)FranceWinTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24)IF FranceDST THENEndOfBoxTime = 080500BeginBoxTime = 020000ELSIF FranceWinTime THENEndOfBoxTime = 070000BeginBoxTime = 010000ENDIFIF Time = EndOfBoxTime THENx2 = BarIndex[0]x1 = BarIndex[73]yH = Highest[72](High[1])yL = Lowest [72](Low[1])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 >= EndOfBoxTime THENDrawSegment(BarIndex, yH, x2, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)DrawSegment(BarIndex, yL, x2, yL) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)ENDIFIF DayOfWeek <> 5 AND Time = 200500 THENDRAWSEGMENT(barindex, yL, barindex, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)ELSIF DayOfWeek = 5 AND Time = 170500 THENDRAWSEGMENT(barindex, yL, barindex, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)ENDIFReturn05/12/2023 at 12:39 PM #214602Hi everyone, I hope you are well,
Here is as promised a version 21, it is not exceptional and you will see that on my code there is a lot of redundancy I know it is not the top but for me it suits me for the moment and it allows me not to make mistakes, we will see later to improve the code
I would like to thank all the people who responded and helped me directly or indirectly (@phoentzs , @GraHal , @Nicolas , @PeterSt , @robertogozzi , …. 😊)
In this code and so I hope it works well anyway I checked several times and it seems to be OK, it’s to calculate the losses generated by the losing trades between 8:05am until 8:05am the next day, so I can count my daily losses and for example put a condition :
– stop buying for the day if I exceed 10€ of loss (C6)
– stop buying for the week if I exceed 40€ of loss (C7)The next step will be to calculate the losses per month and stop buying if we lose more than 100€.
The other steps will be to calculate the real gain and the latent gain in order to reallocate a part each week for the next week if we are in the positive to allow ourselves to lose more while protecting our realized gains 😊
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409// Strategy Name : END OF DAY - YEN // Version : 21.0// Stroks : USD/JPY Mini // indicator associate : Tokyo Box v3// Time Zone / TF : Paris-France (GTM+2) / M5 // Pip Value : 1 Pip = 100 JPY// Tokyo Session : 9Am - 3Pm (UTC+9) //// Spread : 2 //// Information ://#******************************************************************#//# VariableS #//#******************************************************************#Once Capital = 100000Once Equity = CapitalOnce TrailinStop = 0 // 1 on - 0 off // Needs to be improvedOnce BreakEaven = 1 // 1 on - 0 offOnce BreakRange = 1 // 1 on - 0 offOnce MFE = 0 // 1 on - 0 off // Needs to be improvedOnce QuitStrategy = 0 // 1 on - 0 off // Needs to be improvedOnce MaxBuyPerDay = 15 // Maximum shares we can buy per day // Z2Once MaxLostPerDay = 10 // We can buy until we don't lost 10€ per Day // Unit : €Once MaxLostPerWeek = 40 // We can buy until we don't lost 40€ per week// Unit : €Once MaxLostPerMonth= 100// Stop Strategy if we Lost 100€ per month // Needs to be improvedOnce 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 2MedianPriceJPY = Average[10](MedianPrice)FranceDST = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24) // Z5FranceWinTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24) // Z5IF (DayOfWeek = 1 AND Time > 080500) THENMyMondayPeriod = 1MyFridayPeriod = 0ENDIFIF (DayOfWeek = 2 AND Time > 080500) THENMyMondayPeriod = 0MyTuesdayPeriod = 1ENDIFIF (DayOfWeek = 3 AND Time > 080500) THENMyTuesdayPeriod = 0MyWednesdayPeriod = 1ENDIFIF (DayOfWeek = 4 AND Time > 080500) THENMyWednesdayPeriod = 0MyThursdayPeriod = 1ENDIFIF (DayOfWeek = 5 AND Time > 080500) THENMyThursdayPeriod = 0MyFridayPeriod = 1ENDIF//#******************************************************************#//# FonctionS #//#******************************************************************#IF FranceDST THENEndOfBoxTime = 080500BeginBoxTime = 020000ELSIF FranceWinTime THENEndOfBoxTime = 070000BeginBoxTime = 010000ENDIFIF Time = EndOfBoxTime THENx2 = BarIndex[0]x1 = BarIndex[73]yH = Highest[72](High[1])yL = Lowest [72](Low[1])os = 4*pipsizeDayRange = (yH - yL) / pipsizeENDIFIF NOT OnMarket THEN // DcFirstSL = 0NotOnMArket = 1ENDIF//#******************************************************************#//# Money Management #//#******************************************************************#IF Time = 080500 THEN // Ec // #97LastDayCountOfPosition = CountOfPositionFlag = 1ENDIFMoreMathFlag = LastDayCountOfPosition>0 AND Not OnMArket AND OnMarket[1] AND Flag=1IF MoreMathFlag THEN // #97TodayStrategyProfit = StrategyProfitCountOfMyPosition = CountOfPosition[1] - LastDayCountOfPositionLastEntryPrice = TradePrice(CountOfPosition[1]+1)LastExitPrice = TradePriceDiffEntryExitJPY = (((LastEntryPrice - LastExitPrice )/Pipsize)*PointValue)*CountOfMyPositionFlag = 0ENDIFIF MyMondayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenMondayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0MondayLosingTrades = MondayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenMondayLossesJPY = MondayLossesJPY + (StrategyProfit[1] - StrategyProfit)MondayLosingTrades = MondayLosingTrades + 1endifENDIFIF MyTuesdayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenTuesdayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0TuesdayLosingTrades = TuesdayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenTuesdayLossesJPY = TuesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)TuesdayLosingTrades = TuesdayLosingTrades + 1endifENDIFIF MyWednesdayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenWednesdayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0WednesdayLosingTrades = WednesdayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenWednesdayLossesJPY = WednesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)WednesdayLosingTrades = WednesdayLosingTrades + 1endifENDIFIF MyThursdayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenThursdayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0ThursdayLosingTrades = ThursdayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenThursdayLossesJPY = ThursdayLossesJPY + (StrategyProfit[1] - StrategyProfit)ThursdayLosingTrades = ThursdayLosingTrades + 1endifENDIFIF MyFridayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenFridayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0FridayLosingTrades = FridayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenFridayLossesJPY = FridayLossesJPY + (StrategyProfit[1] - StrategyProfit)FridayLosingTrades = FridayLosingTrades + 1endifENDIFMondayLossesEuro = MondayLossesJPY / MedianPriceJPYTuesdayLossesEuro = TuesdayLossesJPY / MedianPriceJPYWednesdayLossesEuro = WednesdayLossesJPY / MedianPriceJPYThursdayLossesEuro = ThursdayLossesJPY / MedianPriceJPYFridayLossesEuro = FridayLossesJPY / MedianPriceJPYWeekLossesJPY = MondayLossesJPY + TuesdayLossesJPY + WednesdayLossesJPY + ThursdayLossesJPY + FridayLossesJPY // PcWeekLossesEuro = WeekLossesJPY/ MedianPriceJPYWeekLosingTrades = MondayLosingTrades+TuesdayLosingTrades+WednesdayLosingTrades+ThursdayLosingTrades+FridayLosingTradesIF MyMondayPeriod THENDayLossesEuro = MondayLossesEuroENDIFIF MyTuesdayPeriod THENDayLossesEuro = TuesdayLossesEuroENDIFIF MyWednesdayPeriod THENDayLossesEuro = WednesdayLossesEuroENDIFIF MyThursdayPeriod THENDayLossesEuro = ThursdayLossesEuroENDIFIF MyFridayPeriod THENDayLossesEuro = FridayLossesEuroENDIFIF DayOfWeek = 0 THENMondayLossesJPY = 0TuesdayLossesJPY = 0WednesdayLossesJPY = 0ThursdayLossesJPY = 0FridayLossesJPY = 0MondayLosingTrades = 0TuesdayLosingTrades = 0WednesdayLosingTrades = 0ThursdayLosingTrades = 0FridayLosingTrades = 0WeekLosingTrades = 0ENDIF//#******************************************************************#//# Long Condition Signals #//#******************************************************************#TradingTimeCondition = (Time >= 080500 AND Time <= 200000 AND DayOfWeek < 5) OR (Time >= 080500 AND Time < 170000 AND DayOfWeek = 5) // TcC1 = TradingTimeConditionLongSignal = Close Crosses Over yHC2 = LongSignalIF LongSignal Then // LcFirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // HcLastFirstSL = FirstSLENDIFIF Time = 080500 AND CountOfPOsition >= 1 THEN // Condition to force the first purchase even if we are in position since yesterdayNotOnMArket = 1ENDIFC3 = NotOnMArketC4 = CountOfPurchase < MaxBuyPerDayC5 = CountOfLongShares < MaxBuyShareDayLostCondition = DayLossesEuro < MaxLostPerDay // Jc & Z7C6 = DayLostConditionWeekLostCondition = WeekLossesEuro < MaxLostPerWeek // QcC7 = WeekLostConditionLongSignalAllCondition = C1 AND C2 AND C3 AND C4 AND C5 AND C6 AND C7IF LongSignalAllCondition THENBuy N Contract AT MarketSET STOP PRICE FirstSLENDIFIF LongSignalAllCondition [1] AND NotOnMArket[1] AND CountOfPosition > 0 THEN // can be improved ?NotOnMArket = 0ENDIFIF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THEN // Wc // // can be improved ?CountOfPurchase = CountOfPurchase + 1ENDIF//#******************************************************************#//# Trailing & BreakEven & Range Stop Loss & MFE #//#******************************************************************#Once trailingstart = 140 // Trailing start after X pips profitOnce trailingstep = 10 // Trailing step to move the "stoploss"Once StartBERatio = 5 // BE Start for the hole position when the RR(FirstSL) = 5Once StartBreakRangePercent = 20 // Close > Last entry + 20% of the Tokyo BoxOnce 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// Range Stop Lossif BreakRange > 0 then // FcIF Not OnMarket THENBreakRangeLevel = 0ENDIFIF LongOnMarket THENBreakRangeMath = TradePrice + (((yH-yL)/100)*StartBreakRangePercent)ENDIFIF LongOnMarket AND Close Crosses Over BreakRangeMath THEN // Z1BreakRangeLevel = yH - 2*Pipsize // Gc//FirstSL = 0ENDIFIF BreakRangeLevel > 0 THEN //Z8SELL AT BreakRangeLevel STOPENDIFendif// BreakEven Stop Lossif BreakEaven>0 thenIF Not OnMarket THENBreakEvenLevel = 0ENDIFyHplusFirstSL = yH + (StartBERatio*(yH-LastFirstSL))IF LongOnMarket AND Close Crosses Over yHplusFirstSL THENBreakEvenLevel = TradePrice + PointsToKeep*pipsizeENDIFIF BreakEvenLevel > 0 THENSELL AT BreakEvenLevel STOPENDIFendifif 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 #//#******************************************************************#// Blue Azur (0, 127, 255) & Maya (115, 194, 251)// Green Sinople (20, 148, 20) &IF 0 THENGraph MyMondayPeriod AS "My Monday Period" Coloured (20, 0, 20)Graph MyTuesdayPeriod AS "My Tuesday Period" Coloured (148, 10, 20)Graph MyWednesdayPeriod AS "My Wednesday Period" Coloured (5, 148, 2)Graph MyThursdayPeriod AS "My Thursday Period" Coloured (20, 18, 20)Graph MyFridayPeriod AS "My Friday Period" Coloured (20, 0, 220)ENDIFIF 0 THENGraph MondayLossesJPY AS "Day-1 Losses ¥ / Monday" Coloured (20, 0, 20)Graph TuesdayLossesJPY AS "Day-2 Losses ¥ / Tuesday" Coloured (148, 10, 20)Graph WednesdayLossesJPY AS "Day-3 Losses ¥ / Wednesday" Coloured (5, 148, 2)Graph ThursdayLossesJPY AS "Day-4 Losses ¥ / Thursday" Coloured (20, 18, 20)Graph FridayLossesJPY AS "Day-5 Losses ¥ / Friday" Coloured (20, 0, 220)Graph WeekLossesJPY AS "All Week Losses ¥ / Week"ENDIFIF 1 THENGraph MondayLossesEuro AS "Day-1 Losses € / Monday" Coloured (20, 0, 20)Graph TuesdayLossesEuro AS "Day-2 Losses € / Tuesday" Coloured (148, 10, 20)Graph WednesdayLossesEuro AS "Day-3 Losses € / Wednesday" Coloured (5, 148, 2)Graph ThursdayLossesEuro AS "Day-4 Losses € / Thursday" Coloured (20, 18, 20)Graph FridayLossesEuro AS "Day-5 Losses € / Friday" Coloured (20, 0, 220)Graph WeekLossesEuro AS "All Week Losses € / Week"ENDIFIF 0 THENGraph MondayLosingTrades Coloured (20, 0, 20)Graph TuesdayLosingTrades Coloured (148, 10, 20)Graph WednesdayLosingTrades Coloured (5, 148, 2)Graph ThursdayLosingTrades Coloured (20, 18, 20)Graph FridayLosingTrades Coloured (20, 0, 220)Graph WeekLosingTradesENDIF//#******************************************************************#//# Stop Strategy #//#******************************************************************#if QuitStrategy thenIF 1 THEN // Nc & Z9if (StrategyProfit / MedianPrice) < MaxLostPerMonth*(-1) thenQuitendifENDIFIF 0 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 ThenQuitENDIFENDIFendif//#******************************************************************#//# Hello ToTo #//#******************************************************************#// _ _ _ _ _______ _______// | | | | | | | |__ __|__ __|// | |__| | ___| | | ___ | | ___ | | ___// | __ |/ _ \ | |/ _ \ | |/ _ \| |/ _ \// | | | | __/ | | (_) | | | (_) | | (_) |// |_| |_|\___|_|_|\___/ |_|\___/|_|\___/// 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 / Winter05/12/2023 at 6:53 PM #214630I forgot to set a variable to 0, sorry
I just finished what I wanted to do for the monthly losses, next step I will try to count the gains to make some variables dynamic and not static anymore
I know that the code is a bit long and it can be optimised but for that you need experience
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439// Strategy Name : END OF DAY - YEN // Version : 21.0// Stroks : USD/JPY Mini // indicator associate : Tokyo Box v3// Time Zone / TF : Paris-France (GTM+2) / M5 // Pip Value : 1 Pip = 100 JPY// Tokyo Session : 9Am - 3Pm (UTC+9) //// Spread : 2 //// Information ://#******************************************************************#//# VariableS #//#******************************************************************#Once Capital = 100000Once Equity = CapitalOnce TrailinStop = 0 // 1 on - 0 off // Needs to be improvedOnce BreakEaven = 1 // 1 on - 0 offOnce BreakRange = 1 // 1 on - 0 offOnce MFE = 0 // 1 on - 0 off // Needs to be improvedOnce QuitStrategy = 0 // 1 on - 0 off // Needs to be improvedOnce MaxBuyPerDay = 15 // Maximum shares we can buy per day // Z2Once MaxLostPerDay = 10 // We can buy until we don't lost 10€ per Day // Unit : €Once MaxLostPerWeek = 40 // We can buy until we don't lost 40€ per week// Unit : €Once MaxLostPerMonth= 100// Stop Strategy if we Lost 100€ per month // Needs to be improvedOnce 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 2MedianPriceJPY = Average[10](MedianPrice)//FranceDST = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24) // Z5FranceDST = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR Month=10 // Z5//FranceWinTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24) // Z5FranceWinTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR Month=3 // Z5IF (DayOfWeek = 1 AND Time > 080500) THENMyMondayPeriod = 1MyFridayPeriod = 0ENDIFIF (DayOfWeek = 2 AND Time > 080500) THENMyMondayPeriod = 0MyTuesdayPeriod = 1ENDIFIF (DayOfWeek = 3 AND Time > 080500) THENMyTuesdayPeriod = 0MyWednesdayPeriod = 1ENDIFIF (DayOfWeek = 4 AND Time > 080500) THENMyWednesdayPeriod = 0MyThursdayPeriod = 1ENDIFIF (DayOfWeek = 5 AND Time > 080500) THENMyThursdayPeriod = 0MyFridayPeriod = 1ENDIF//#******************************************************************#//# FonctionS #//#******************************************************************#IF FranceDST THENEndOfBoxTime = 080500BeginBoxTime = 020000ELSIF FranceWinTime THENEndOfBoxTime = 070000BeginBoxTime = 010000ENDIFIF Time = EndOfBoxTime THENx2 = BarIndex[0]x1 = BarIndex[73]yH = Highest[72](High[1])yL = Lowest [72](Low[1])os = 4*pipsizeDayRange = (yH - yL) / pipsizeENDIFIF NOT OnMarket THEN // DcFirstSL = 0NotOnMArket = 1ENDIF//#******************************************************************#//# Money Management #//#******************************************************************#IF Time = 080500 THEN // Ec // #97CountOfPurchase = 0 // Vc & Z3LastDayCountOfPosition = CountOfPositionFlag = 1ENDIFMoreMathFlag = LastDayCountOfPosition>0 AND Not OnMArket AND OnMarket[1] AND Flag=1IF MoreMathFlag THEN // #97TodayStrategyProfit = StrategyProfitCountOfMyPosition = CountOfPosition[1] - LastDayCountOfPositionLastEntryPrice = TradePrice(CountOfPosition[1]+1)LastExitPrice = TradePriceDiffEntryExitJPY = (((LastEntryPrice - LastExitPrice )/Pipsize)*PointValue)*CountOfMyPositionFlag = 0ENDIFIF MyMondayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenMondayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0MondayLosingTrades = MondayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenMondayLossesJPY = MondayLossesJPY + (StrategyProfit[1] - StrategyProfit)MondayLosingTrades = MondayLosingTrades + 1endifENDIFIF MyTuesdayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenTuesdayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0TuesdayLosingTrades = TuesdayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenTuesdayLossesJPY = TuesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)TuesdayLosingTrades = TuesdayLosingTrades + 1endifENDIFIF MyWednesdayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenWednesdayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0WednesdayLosingTrades = WednesdayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenWednesdayLossesJPY = WednesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)WednesdayLosingTrades = WednesdayLosingTrades + 1endifENDIFIF MyThursdayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenThursdayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0ThursdayLosingTrades = ThursdayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenThursdayLossesJPY = ThursdayLossesJPY + (StrategyProfit[1] - StrategyProfit)ThursdayLosingTrades = ThursdayLosingTrades + 1endifENDIFIF MyFridayPeriod THENif LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] thenFridayLossesJPY = DiffEntryExitJPYDiffEntryExitJPY = 0LastDayCountOfPosition = 0FridayLosingTrades = FridayLosingTrades + 1endifif StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 thenFridayLossesJPY = FridayLossesJPY + (StrategyProfit[1] - StrategyProfit)FridayLosingTrades = FridayLosingTrades + 1endifENDIFMondayLossesEuro = MondayLossesJPY / MedianPriceJPYTuesdayLossesEuro = TuesdayLossesJPY / MedianPriceJPYWednesdayLossesEuro = WednesdayLossesJPY / MedianPriceJPYThursdayLossesEuro = ThursdayLossesJPY / MedianPriceJPYFridayLossesEuro = FridayLossesJPY / MedianPriceJPYWeekLossesJPY = MondayLossesJPY + TuesdayLossesJPY + WednesdayLossesJPY + ThursdayLossesJPY + FridayLossesJPY // PcWeekLossesEuro = WeekLossesJPY/ MedianPriceJPYWeekLosingTrades = MondayLosingTrades+TuesdayLosingTrades+WednesdayLosingTrades+ThursdayLosingTrades+FridayLosingTradesMonthLossesEuro = (LastWeekLossesJPY / MedianPriceJPY) + WeekLossesEuroIF MyMondayPeriod THENDayLossesEuro = MondayLossesEuroENDIFIF MyTuesdayPeriod THENDayLossesEuro = TuesdayLossesEuroENDIFIF MyWednesdayPeriod THENDayLossesEuro = WednesdayLossesEuroENDIFIF MyThursdayPeriod THENDayLossesEuro = ThursdayLossesEuroENDIFIF MyFridayPeriod THENDayLossesEuro = FridayLossesEuroENDIFIF DayOfWeek = 1 AND Time = 080000 THEN // Reset Mnday AT 8:00 => 080500LastWeekLossesJPY = WeekLossesJPY // to get net week for Moth LossesMondayLossesJPY = 0TuesdayLossesJPY = 0WednesdayLossesJPY = 0ThursdayLossesJPY = 0FridayLossesJPY = 0MondayLosingTrades = 0TuesdayLosingTrades = 0WednesdayLosingTrades = 0ThursdayLosingTrades = 0FridayLosingTrades = 0WeekLosingTrades = 0ENDIFif Month <> Month[1] thenMonthFlag = 1endifif MonthFlag = 1 AND DayOfWeek = 1 AND Time = 080500 thenLastWeekLossesJPY = 0MonthFlag = 0endif//#******************************************************************#//# Long Condition Signals #//#******************************************************************#TradingTimeCondition = (Time >= 080500 AND Time <= 200000 AND DayOfWeek < 5) OR (Time >= 080500 AND Time < 170000 AND DayOfWeek = 5) // TcC1 = TradingTimeConditionLongSignal = Close Crosses Over yHC2 = LongSignalIF LongSignal Then // LcFirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // HcLastFirstSL = FirstSLENDIFIF Time = 080500 AND CountOfPOsition >= 1 THEN // Condition to force the first purchase even if we are in position since yesterdayNotOnMArket = 1ENDIFC3 = NotOnMArketC4 = CountOfPurchase < MaxBuyPerDayC5 = CountOfLongShares < MaxBuyShareDayLostCondition = DayLossesEuro < MaxLostPerDay // Jc & Z7C6 = DayLostConditionWeekLostCondition = WeekLossesEuro < MaxLostPerWeek // QcC7 = WeekLostConditionMonthLostCondition = MonthLossesEuro < MaxLostPerMonthC8 = MonthLostConditionLongSignalAllCondition = C1 AND C2 AND C3 AND C4 AND C5 AND C6 AND C7 AND C8IF LongSignalAllCondition THENBuy N Contract AT MarketSET STOP PRICE FirstSLENDIFIF LongSignalAllCondition [1] AND NotOnMArket[1] AND CountOfPosition > 0 THEN // can be improved ?NotOnMArket = 0ENDIFIF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THEN // Wc // // can be improved ?CountOfPurchase = CountOfPurchase + 1ENDIF//#******************************************************************#//# Trailing & BreakEven & Range Stop Loss & MFE #//#******************************************************************#Once trailingstart = 140 // Trailing start after X pips profitOnce trailingstep = 10 // Trailing step to move the "stoploss"Once StartBERatio = 5 // BE Start for the hole position when the RR(FirstSL) = 5Once StartBreakRangePercent = 20 // Close > Last entry + 20% of the Tokyo BoxOnce 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// Range Stop Lossif BreakRange > 0 then // FcIF Not OnMarket THENBreakRangeLevel = 0ENDIFIF LongOnMarket THENBreakRangeMath = TradePrice + (((yH-yL)/100)*StartBreakRangePercent)ENDIFIF LongOnMarket AND Close Crosses Over BreakRangeMath THEN // Z1BreakRangeLevel = yH - 2*Pipsize // Gc//FirstSL = 0ENDIFIF BreakRangeLevel > 0 THEN //Z8SELL AT BreakRangeLevel STOPENDIFendif// BreakEven Stop Lossif BreakEaven>0 thenIF Not OnMarket THENBreakEvenLevel = 0ENDIFyHplusFirstSL = yH + (StartBERatio*(yH-LastFirstSL))IF LongOnMarket AND Close Crosses Over yHplusFirstSL THENBreakEvenLevel = TradePrice + PointsToKeep*pipsizeENDIFIF BreakEvenLevel > 0 THENSELL AT BreakEvenLevel STOPENDIFendifif 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 #//#******************************************************************#// Blue Azur (0, 127, 255) & Maya (115, 194, 251)// Green Sinople (20, 148, 20) &IF 0 THENGraph MyMondayPeriod AS "My Monday Period" Coloured (20, 0, 20)Graph MyTuesdayPeriod AS "My Tuesday Period" Coloured (148, 10, 20)Graph MyWednesdayPeriod AS "My Wednesday Period" Coloured (5, 148, 2)Graph MyThursdayPeriod AS "My Thursday Period" Coloured (20, 18, 20)Graph MyFridayPeriod AS "My Friday Period" Coloured (20, 0, 220)ENDIFIF 0 THENGraph MondayLossesJPY AS "Day-1 Losses ¥ / Monday" Coloured (20, 0, 20)Graph TuesdayLossesJPY AS "Day-2 Losses ¥ / Tuesday" Coloured (148, 10, 20)Graph WednesdayLossesJPY AS "Day-3 Losses ¥ / Wednesday" Coloured (5, 148, 2)Graph ThursdayLossesJPY AS "Day-4 Losses ¥ / Thursday" Coloured (20, 18, 20)Graph FridayLossesJPY AS "Day-5 Losses ¥ / Friday" Coloured (20, 0, 220)Graph WeekLossesJPY AS "All Week Losses ¥ / Week"ENDIFIF 0 THENGraph MondayLossesEuro AS "Day-1 Losses € / Monday" Coloured (255, 255, 0)Graph TuesdayLossesEuro AS "Day-2 Losses € / Tuesday" Coloured (148, 10, 20)Graph WednesdayLossesEuro AS "Day-3 Losses € / Wednesday" Coloured (5, 148, 2)Graph ThursdayLossesEuro AS "Day-4 Losses € / Thursday" Coloured (20, 18, 20)Graph FridayLossesEuro AS "Day-5 Losses € / Friday" Coloured (20, 0, 220)Graph WeekLossesEuro AS "All Week Losses € / Week" Coloured (253, 63, 146)Graph MonthLossesEuro AS "All Month Losses € / Month"ENDIFIF 0 THENGraph MondayLosingTrades Coloured (20, 0, 20)Graph TuesdayLosingTrades Coloured (148, 10, 20)Graph WednesdayLosingTrades Coloured (5, 148, 2)Graph ThursdayLosingTrades Coloured (20, 18, 20)Graph FridayLosingTrades Coloured (20, 0, 220)Graph WeekLosingTradesENDIFIF 1 THENGraph C1Graph C2Graph C3Graph C4Graph C5Graph C6Graph C7Graph C8Graph LongSignalAllCondition Coloured (0,0,240)ENDIF//#******************************************************************#//# Stop Strategy #//#******************************************************************#if QuitStrategy thenIF 1 THEN // Nc & Z9 // Needs to be improvedif (StrategyProfit / MedianPriceJPY) < MaxLostPerMonth*(-1) thenQuitendifENDIFIF 0 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 ThenQuitENDIFENDIFendif//#******************************************************************#//# Hello ToTo #//#******************************************************************#// _ _ _ _ _______ _______// | | | | | | | |__ __|__ __|// | |__| | ___| | | ___ | | ___ | | ___// | __ |/ _ \ | |/ _ \ | |/ _ \| |/ _ \// | | | | __/ | | (_) | | | (_) | | (_) |// |_| |_|\___|_|_|\___/ |_|\___/|_|\___/// 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 -
AuthorPosts
Find exclusive trading pro-tools on