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/30/2023 at 6:40 PM #213910
SL-3 = BreakRangeLevel (green) SL-2 = BreakRangeStarter (blue) SL-1 = FirstSL (Red)
I’ve scanned up and down the code 3 times during the afternoon and still can’t see above.
For example, what Line number is SL-1 shown on (if indeed it is) or am I missing the point?? 🙂
1 user thanked author for this post.
04/30/2023 at 7:06 PM #213912I will try to share a scheme tonight, it will be more clear 😊
04/30/2023 at 8:46 PM #213917I’m not sure but I think I’ve found it, I think I have too many Stop Losses in my code so I’ll try to make one and only one and change the value each time, I mean one line of code
04/30/2023 at 8:50 PM #213918@phoentzs
yes indeed I think I am complicating things too much I will try to simplify in version 16,Asking if I ran the code over several months, are you talking real or backtest?
because I am only in backtest
04/30/2023 at 9:57 PM #21392004/30/2023 at 11:00 PM #213923Ok, I understand, Now I’m not doing backtest on 200k history but only 1 or 3k,
For the moment what I’m trying to do is to master my programming, I don’t even look at the results of the strategy anymore
04/30/2023 at 11:22 PM #213924That sounds a bit like a gimmick…
1 user thanked author for this post.
05/01/2023 at 9:50 PM #213943@phoentzs I just did the test on 200k units with version 16 which is a copy of version 17, I put you the result in picture, but personally it does not impress me, I tell myself anyway that it is a good start because the backtest is positive while I do not yet manage my profit taking but only but stop loss exit
05/01/2023 at 9:53 PM #213945That sounds a bit like a gimmick…
If you have any suggestions or thoughts they are all welcome, even an algorithm that makes money for sure so I stop programming 😁
05/01/2023 at 10:10 PM #213946Well Done Mr Decaff … and all with zero caffeine!! 😉
1 user thanked author for this post.
05/01/2023 at 10:18 PM #213947Just to answer as I promised with a Small Diagram, I think I have solved my problem as my conditions were running all the time at each candle, I have transformed them with a Crosses Over condition
05/01/2023 at 10:57 PM #213950Let’s start today on version 17, I try to control the gains and losses per day in order to compare them to my daily risk which in this example is 10€ with the following variable : MyJPYDayProfit
it is first transformed into euros in the variable MyEuroDayProfit and then used in the DayLostCondition on line 57
A very simple example:
If for example during the day I have lost 15 € then I compare with my variable MaxLostPerDay who is 10 € :
DayLostCondition = -15 >= -10€ = FALSE, So I can’t buy moreI get the StrategyProfit value of the last day in the variable MyLastDayProfit to compare it to the candlestick profit today,
My problem is : when I have been in a position for the last day so I can’t count today’s gains and profits only, without including last days gains
I have attached a picture and you can see that I have circled the first trade of the day, the variable MyJPYDayProfit should be losing but it is positive ( MyJPYDayProfit = 5130) because it takes into account the gains of the positions opened yesterday
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330// Strategy Name : END OF DAY - YEN // Version : 17.0// Stroks : USD/JPY Mini // indicator associate : Tokyo Box v2// 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 DrawDownQuit = 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 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//#******************************************************************#//# FonctionS #//#******************************************************************#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 // Z3MyLastDayProfit = StrategyProfit // Unit : JPYLastDayCountOfPosition = CountOfPosition // KcENDIFMyJPYDayProfit = StrategyProfit - MyLastDayProfit // Unit : JPYMyEuroDayProfit = MyJPYDayProfit / Medianprice // Unit : €DayLostCondition = MyEuroDayProfit > MaxLostPerDay*(-1) // Jc & Z7// Ex : (-300JPY/143) > 10€ x -1 ==> -2,10€ > -10€ => Boolen = True / -15€ > -10€ => FalseTimeCondition = (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) // HcOldFirstSL = FirstSLENDIFIF TimeCondition AND Not OnMarket THENLastDayCountOfPosition = 0ENDIFif TimeCondition then // TcLongSignalAllCondition = LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND (CountOfPosition <= LastDayCountOfPosition) AND ((((Close - FirstSL)*100) / pipsize) / MedianPrice < MaxLostPerDay)IF LongSignalAllCondition 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 & 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-OldFirstSL))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 THENyHplusFirstSL = yH + (5*(yH-OldFirstSL))GraphOnPrice BreakEvenLevel AS "BreakEvenLevel" Coloured (20, 148, 20)GraphOnPrice yHplusFirstSL AS "yHplusFirstSL"Coloured (20, 148, 20)GraphOnPrice BreakRangeMath AS "BreakRangeMath" Coloured (115, 194, 251)GraphOnPrice BreakRangeLevel AS "BreakRangeLevel" Coloured (115, 194, 251)GraphOnPrice FirstSL AS "FirstSL" Coloured (233, 56, 63)//GraphOnPrice OldFirstSL AS "OldFirstSL"ENDIFIF 1 THENLosingPerTrade = (((Close - FirstSL)*100) / pipsize) / MedianPrice//Graph LosingPerTrade AS "Calculeeee"//Graph 10+MyEuroDayProfit AS "Mes 10€"//Graph LongSignalAllCondition AS "LongSignalAllCondition"//Graph LongSignal AS "LongSignal"//Graph yH AS "yH"//Graph TimeCondition AS "TimeCondition"Graph MyJPYDayProfit AS "MyJPYDayProfit"Graph MyLastDayProfit AS "MyLastDayProfit"Graph StrategyProfit AS "StrategyProfit"//Graph MyEuroDayProfit AS "My Euro Day Profit"//Graph DayLostCondition AS "DayLostCondition"//Graph MaxLostPerDay*(-1) AS "MaxLostPerDay"ENDIF//#******************************************************************#//# Stop Strategy #//#******************************************************************#IF 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//#******************************************************************#//# 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// 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 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 BreakRangeMath"// 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 : I have to do a check of the orders executed before each other, Like only one Line of// code like : SEll AT SL STOP and try to manage the value of SL//#******************************************************************#//# 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//// Code : ((((Close - FirstSL)*100) / pipsize) / MedianPrice < MaxLostPerDay)// We Calculate the distance between the Close and the FirstSL,// and This amount should be smaller than what you are willing to lose per day, exemple :// Close-FirstSL = 18Pips but we can lost maximum 10€/Day => 10€ = 14,3 Pips//#******************************************************************#//# Last programming where I stopped at #//#******************************************************************#//05/03/2023 at 12:29 PM #214061Here is the version 18 with a new rule Nc, It allows us to leave the strategy if we lose more than 100 €.
There is also some code I added for money management and daily loss calculation which is not finished yet but you can follow it on this post
the is the code of v18 :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379// Strategy Name : END OF DAY - YEN // Version : 18.0// Stroks : USD/JPY Mini // indicator associate : Tokyo Box v2// 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 DrawDownQuit = 0 // 1 on - 0 off // Needs to be improvedOnce MaxLostPerMonth= 100// if we Lost about 100€ per month we stop StrategyOnce 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 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//#******************************************************************#//# FonctionS #//#******************************************************************#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 // Z3LastStrategyProfit = StrategyProfit // Unit : JPYLastDayCountOfPosition = CountOfPosition // KcENDIFIF IntraDayBarIndex = IntraDayBarIndexStart-1 THEN// ici je suis à la IntradayBarIndex = 97 ou 85 soit à 8:05// je doit voir ici si je suis en position ou pas pour faire mon calcule de benefice dans la jounéeENDIFDayProfitJPY = StrategyProfit - LastStrategyProfit // Unit : JPYDayProfitEuro = DayProfitJPY / Medianprice // Unit : €DayLostCondition = DayProfitEuro > MaxLostPerDay*(-1) // Jc & Z7// Ex : (-300JPY/143) > 10€ x -1 ==> -2,10€ > -10€ => Boolen = True / -15€ > -10€ => FalseTimeCondition = (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) // HcLastFirstSL = FirstSLENDIFIF TimeCondition AND Not OnMarket THENLastDayCountOfPosition = 0ENDIFif TimeCondition then // TcLongSignalAllCondition = LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND (CountOfPosition <= LastDayCountOfPosition) //AND ((((Close - FirstSL)*100) / pipsize) / MedianPrice < MaxLostPerDay)IF LongSignalAllCondition 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 & 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 STOPendifendifIF Day = 1 THENMondayProfit = DayProfitEuroELSIF Day = 2 THENTuesdayProfit = DayProfitEuroELSIF Day = 3 THENWednesdayProfit = DayProfitEuroELSIF Day = 4 THENThursdayProfit = DayProfitEuroELSIF Day = 5 THENFridayProfit = DayProfitEuroELSIF Day = 7 THENMondayProfit = 0TuesdayProfit = 0WednesdayProfit = 0ThursdayProfit = 0FridayProfit = 0ENDIF//#******************************************************************#//# Graph #//#******************************************************************#// Blue Azur (0, 127, 255) & Maya (115, 194, 251)// Green Sinople (20, 148, 20) &IF 0 THENyHplusFirstSL = yH + (5*(yH-LastFirstSL))GraphOnPrice BreakEvenLevel AS "BreakEvenLevel" Coloured (20, 148, 20)GraphOnPrice yHplusFirstSL AS "yHplusFirstSL"Coloured (20, 148, 20)GraphOnPrice BreakRangeMath AS "BreakRangeMath" Coloured (115, 194, 251)GraphOnPrice BreakRangeLevel AS "BreakRangeLevel" Coloured (115, 194, 251)GraphOnPrice FirstSL AS "FirstSL" Coloured (233, 56, 63)//GraphOnPrice LastFirstSL AS "LastFirstSL"ENDIFIF 0 THENLosingPerTrade = (((Close - FirstSL)*100) / pipsize) / MedianPrice//Graph LosingPerTrade AS "Calculeeee"//Graph 10+DayProfitEuro AS "Mes 10€"//Graph LongSignalAllCondition AS "LongSignalAllCondition"//Graph LongSignal AS "LongSignal"//Graph yH AS "yH"//Graph TimeCondition AS "TimeCondition"Graph DayProfitJPY AS "DayProfitJPY"Graph LastStrategyProfit AS "LastStrategyProfit"Graph StrategyProfit AS "StrategyProfit"Graph MondayProfit AS "Monday Profit €"//Graph DayProfitEuro AS "My Euro Day Profit"//Graph DayLostCondition AS "DayLostCondition"//Graph MaxLostPerDay*(-1) AS "MaxLostPerDay"ENDIFIF 1 THENGraph MondayProfit AS "Monday Profit €"Graph TuesdayProfit AS "TuesdayProfit"Graph WednesdayProfit AS "WednesdayProfit"Graph ThursdayProfit AS "ThursdayProfit"Graph FridayProfit AS "FridayProfit"ENDIF//#******************************************************************#//# Stop Strategy #//#******************************************************************#IF 1 THEN // Ncif (StrategyProfit / MedianPrice) < MaxLostPerMonth*(-1) thenQuitendifENDIFIF 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//#******************************************************************#//# 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// 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 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// Lc : Long signal if we Close > the Tokyo Box and we are in TimeCondition (Tc)// 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// Nc : If we lost more the xx€, we stop strategy, Exemple if 100€, if we 102€ = QUIT// this is not a DrawDown// 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//#******************************************************************#//# 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 BreakRangeMath"// 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 : I have to do a check of the orders executed before each other, Like only one Line of// code like : SEll AT SL STOP and try to manage the value of SL//#******************************************************************#//# 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//// Code : ((((Close - FirstSL)*100) / pipsize) / MedianPrice < MaxLostPerDay)// We Calculate the distance between the Close and the FirstSL,// and This amount should be smaller than what you are willing to lose per day, exemple :// Close-FirstSL = 18Pips but we can lost maximum 10€/Day => 10€ = 14,3 Pips//#******************************************************************#//# Last programming where I stopped at #//#******************************************************************#//05/03/2023 at 12:46 PM #21406205/03/2023 at 12:53 PM #214063I don’t understood your question ?
It doesn’t matter how many bars there are, even if the strategy is losing, what I’m looking for is to master the code so that it reflects as much as possible the ideas and rules I have in mind, if that can answer your questions 😊,
If I am wrong then please rephrase your question and I will be happy to answer it 😊
-
AuthorPosts
Find exclusive trading pro-tools on