End Of Day – YEN M15 Strategy

Viewing 6 posts - 91 through 96 (of 96 total)
  • Author
    Posts
  • #214064 quote
    phoentzs
    Participant
    Master

    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?

    ZeroCafeine thanked this post
    #214101 quote
    ZeroCafeine
    Participant
    Senior

    I 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

    #214299 quote
    ZeroCafeine
    Participant
    Senior

    hello

    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

    #214331 quote
    ZeroCafeine
    Participant
    Senior

    Nothing exceptional but I will use the time function TIME instead of the INTRADAYBARINDEX function for my indicator Tokyo Box v3 and also my strategy :

    // 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 THEN
    EndOfBoxTime = 080500
    BeginBoxTime = 020000
    ELSIF FranceWinTime THEN
    EndOfBoxTime = 070000
    BeginBoxTime = 010000
    ENDIF
    
    IF Time = EndOfBoxTime THEN
    x2 = BarIndex[0]
    x1 = BarIndex[73]
    yH = Highest[72](High[1])
    yL = Lowest [72](Low[1])
    os = 4*pipsize
    DayRange = (yH - yL) / pipsize
    DrawRectangle(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)
    ENDIF
    
    IF Time >= EndOfBoxTime THEN
    DrawSegment(BarIndex, yH, x2, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    DrawSegment(BarIndex, yL, x2, yL) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    ENDIF
    
    IF DayOfWeek <> 5 AND Time = 200500 THEN
    DRAWSEGMENT(barindex, yL, barindex, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    ELSIF DayOfWeek = 5 AND Time = 170500 THEN
    DRAWSEGMENT(barindex, yL, barindex, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    ENDIF
    
    Return
    
    #214602 quote
    ZeroCafeine
    Participant
    Senior

    Hi 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 😊

    // 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        = 100000
    Once Equity         = Capital
    Once TrailinStop    = 0  // 1 on - 0 off // Needs to be improved
    Once BreakEaven     = 1  // 1 on - 0 off
    Once BreakRange     = 1  // 1 on - 0 off
    Once MFE            = 0  // 1 on - 0 off // Needs to be improved
    Once QuitStrategy   = 0  // 1 on - 0 off // Needs to be improved
    Once MaxBuyPerDay   = 15 // Maximum shares we can buy per day // Z2
    Once 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 improved
    Once MaxBuyShare    = 10 // Maximum of shares we can buy (Marging math)
    Once PercentOfBoxSL = 10 // Percent of Tokyo Box for Initialization the First Stop Loss
    Once N              = 1  // Buy N Shares
    Once Spread         = 2  // Spread fees x 2
    MedianPriceJPY = 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) // Z5
    FranceWinTime       = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24) // Z5
    
    IF (DayOfWeek = 1 AND Time > 080500) THEN
    MyMondayPeriod = 1
    MyFridayPeriod = 0
    ENDIF
    IF (DayOfWeek = 2 AND Time > 080500) THEN
    MyMondayPeriod = 0
    MyTuesdayPeriod = 1
    ENDIF
    IF (DayOfWeek = 3 AND Time > 080500) THEN
    MyTuesdayPeriod = 0
    MyWednesdayPeriod = 1
    ENDIF
    IF (DayOfWeek = 4 AND Time > 080500) THEN
    MyWednesdayPeriod = 0
    MyThursdayPeriod = 1
    ENDIF
    IF (DayOfWeek = 5 AND Time > 080500) THEN
    MyThursdayPeriod = 0
    MyFridayPeriod = 1
    ENDIF
    
    //#******************************************************************#
    //#                              FonctionS                           #
    //#******************************************************************#
    IF FranceDST THEN
    EndOfBoxTime = 080500
    BeginBoxTime = 020000
    ELSIF FranceWinTime THEN
    EndOfBoxTime = 070000
    BeginBoxTime = 010000
    ENDIF
    
    IF Time = EndOfBoxTime THEN
    x2 = BarIndex[0]
    x1 = BarIndex[73]
    yH = Highest[72](High[1])
    yL = Lowest [72](Low[1])
    os = 4*pipsize
    DayRange = (yH - yL) / pipsize
    ENDIF
    
    IF NOT OnMarket THEN // Dc
    FirstSL = 0
    NotOnMArket = 1
    ENDIF
    
    //#******************************************************************#
    //#                         Money Management                         #
    //#******************************************************************#
    
    IF Time = 080500 THEN // Ec // #97
    LastDayCountOfPosition = CountOfPosition
    Flag = 1
    ENDIF
    
    MoreMathFlag = LastDayCountOfPosition>0 AND Not OnMArket AND OnMarket[1] AND Flag=1
    
    IF MoreMathFlag THEN // #97
    TodayStrategyProfit = StrategyProfit
    CountOfMyPosition    = CountOfPosition[1] - LastDayCountOfPosition
    LastEntryPrice  = TradePrice(CountOfPosition[1]+1)
    LastExitPrice  = TradePrice
    DiffEntryExitJPY = (((LastEntryPrice - LastExitPrice )/Pipsize)*PointValue)*CountOfMyPosition
    Flag = 0
    ENDIF
    
    IF MyMondayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    MondayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    MondayLosingTrades = MondayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    MondayLossesJPY = MondayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    MondayLosingTrades = MondayLosingTrades + 1
    endif
    ENDIF
    
    IF MyTuesdayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    TuesdayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    TuesdayLosingTrades = TuesdayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    TuesdayLossesJPY = TuesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    TuesdayLosingTrades = TuesdayLosingTrades + 1
    endif
    ENDIF
    
    IF MyWednesdayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    WednesdayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    WednesdayLosingTrades = WednesdayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    WednesdayLossesJPY = WednesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    WednesdayLosingTrades = WednesdayLosingTrades + 1
    endif
    ENDIF
    
    IF MyThursdayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    ThursdayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    ThursdayLosingTrades = ThursdayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    ThursdayLossesJPY = ThursdayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    ThursdayLosingTrades = ThursdayLosingTrades + 1
    endif
    ENDIF
    
    IF MyFridayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    FridayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    FridayLosingTrades = FridayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    FridayLossesJPY = FridayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    FridayLosingTrades = FridayLosingTrades + 1
    endif
    ENDIF
    
    MondayLossesEuro    = MondayLossesJPY    / MedianPriceJPY
    TuesdayLossesEuro   = TuesdayLossesJPY   / MedianPriceJPY
    WednesdayLossesEuro = WednesdayLossesJPY / MedianPriceJPY
    ThursdayLossesEuro  = ThursdayLossesJPY  / MedianPriceJPY
    FridayLossesEuro    = FridayLossesJPY    / MedianPriceJPY
    
    WeekLossesJPY  = MondayLossesJPY + TuesdayLossesJPY + WednesdayLossesJPY + ThursdayLossesJPY + FridayLossesJPY // Pc
    
    WeekLossesEuro  = WeekLossesJPY/ MedianPriceJPY
    
    WeekLosingTrades = MondayLosingTrades+TuesdayLosingTrades+WednesdayLosingTrades+ThursdayLosingTrades+FridayLosingTrades
    
    IF MyMondayPeriod THEN
    DayLossesEuro = MondayLossesEuro
    ENDIF
    IF MyTuesdayPeriod THEN
    DayLossesEuro = TuesdayLossesEuro
    ENDIF
    IF MyWednesdayPeriod THEN
    DayLossesEuro = WednesdayLossesEuro
    ENDIF
    IF MyThursdayPeriod THEN
    DayLossesEuro = ThursdayLossesEuro
    ENDIF
    IF MyFridayPeriod THEN
    DayLossesEuro = FridayLossesEuro
    ENDIF
    
    IF DayOfWeek = 0 THEN
    MondayLossesJPY    = 0
    TuesdayLossesJPY   = 0
    WednesdayLossesJPY = 0
    ThursdayLossesJPY  = 0
    FridayLossesJPY    = 0
    
    MondayLosingTrades    = 0
    TuesdayLosingTrades   = 0
    WednesdayLosingTrades = 0
    ThursdayLosingTrades  = 0
    FridayLosingTrades    = 0
    WeekLosingTrades      = 0
    ENDIF
    
    //#******************************************************************#
    //#                   Long Condition Signals                         #
    //#******************************************************************#
    
    TradingTimeCondition = (Time >= 080500 AND Time <= 200000 AND DayOfWeek < 5) OR  (Time >= 080500 AND Time < 170000 AND DayOfWeek = 5) // Tc
    C1 = TradingTimeCondition
    
    LongSignal = Close Crosses Over yH
    C2 = LongSignal
    
    IF LongSignal Then // Lc
    FirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // Hc
    LastFirstSL = FirstSL
    ENDIF
    
    IF Time = 080500 AND CountOfPOsition >= 1 THEN // Condition to force the first purchase even if we are in position since yesterday
    NotOnMArket = 1
    ENDIF
    
    C3 = NotOnMArket
    
    C4 = CountOfPurchase < MaxBuyPerDay
    
    C5 = CountOfLongShares < MaxBuyShare
    
    DayLostCondition  = DayLossesEuro < MaxLostPerDay // Jc & Z7
    C6 = DayLostCondition
    
    WeekLostCondition = WeekLossesEuro  < MaxLostPerWeek // Qc
    C7 = WeekLostCondition
    
    LongSignalAllCondition = C1 AND C2 AND C3 AND C4 AND C5 AND C6 AND C7
    
    IF LongSignalAllCondition THEN
    Buy N Contract AT Market
    SET STOP PRICE FirstSL
    ENDIF
    
    IF LongSignalAllCondition [1] AND NotOnMArket[1] AND CountOfPosition > 0 THEN // can be improved ?
    NotOnMArket = 0
    ENDIF
    
    IF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THEN // Wc // // can be improved ?
    CountOfPurchase = CountOfPurchase + 1
    ENDIF
    
    //#******************************************************************#
    //#         Trailing & BreakEven & Range Stop Loss & MFE             #
    //#******************************************************************#
    Once trailingstart   = 140       // Trailing start after X pips profit
    Once trailingstep    = 10        // Trailing step to move the "stoploss"
    Once StartBERatio    = 5         // BE Start for the hole position when the RR(FirstSL) = 5
    Once StartBreakRangePercent = 20 // Close > Last entry + 20% of the Tokyo Box
    Once PointsToKeep    = 2*Spread  // Spread to add to BE price
    Once TRAILINGMFE     = 20        // Trailing stop with the Max Favorable Excursion
    
    // Trailing
    if TrailinStop > 0 then // Needs to be improved
    IF NOT ONMARKET THEN
    NewSL=0
    ENDIF
    IF LONGONMARKET THEN
    // Trailing Start
    IF NewSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    NewSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    // Trailing Step Move
    IF NewSL>0 AND close-NewSL>=trailingstep*pipsize THEN
    NewSL = NewSL+trailingstep*pipsize
    ENDIF
    ENDIF
    //stop order to exit the positions
    IF NewSL>0 THEN
    SELL AT NewSL STOP
    ENDIF
    endif
    
    // Range Stop Loss
    if BreakRange > 0 then // Fc
    IF Not OnMarket THEN
    BreakRangeLevel = 0
    ENDIF
    IF LongOnMarket THEN
    BreakRangeMath  = TradePrice + (((yH-yL)/100)*StartBreakRangePercent)
    ENDIF
    IF LongOnMarket AND Close Crosses Over BreakRangeMath THEN // Z1
    BreakRangeLevel = yH - 2*Pipsize // Gc
    //FirstSL = 0
    ENDIF
    IF BreakRangeLevel > 0 THEN //Z8
    SELL AT BreakRangeLevel STOP
    ENDIF
    endif
    
    // BreakEven Stop Loss
    if BreakEaven>0 then
    IF Not OnMarket THEN
    BreakEvenLevel = 0
    ENDIF
    yHplusFirstSL = yH + (StartBERatio*(yH-LastFirstSL))
    IF LongOnMarket AND Close Crosses Over yHplusFirstSL THEN
    BreakEvenLevel  = TradePrice + PointsToKeep*pipsize
    ENDIF
    IF BreakEvenLevel > 0 THEN
    SELL AT BreakEvenLevel STOP
    ENDIF
    endif
    
    if MFE > 0 then // Needs to be improved
    if not onmarket then
    MAXPRICEMFE = 0
    MINPRICEMFE = close
    priceexitMFE = 0
    endif
    if longonmarket then
    MAXPRICEMFE = MAX(MAXPRICEMFE,close) //saving the MFE of the current trade
    if MAXPRICEMFE-tradeprice(1)>=TRAILINGMFE*pointsize then //if the MFE is higher than the trailingstop then
    priceexitMFE = MAXPRICEMFE-TRAILINGMFE*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    if onmarket and priceexitMFE>0 then
    SELL AT priceexitMFE STOP
    endif
    endif
    
    //#******************************************************************#
    //#                              Graph                               #
    //#******************************************************************#
    // Blue  Azur    (0, 127, 255) & Maya (115, 194, 251)
    // Green Sinople (20, 148, 20) &
    
    IF 0 THEN
    Graph 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)
    ENDIF
    
    IF 0 THEN
    Graph 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"
    ENDIF
    
    IF 1 THEN
    Graph 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"
    ENDIF
    
    IF 0 THEN
    Graph 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 WeekLosingTrades
    ENDIF
    
    //#******************************************************************#
    //#                           Stop Strategy                          #
    //#******************************************************************#
    
    if QuitStrategy then
    IF 1 THEN // Nc & Z9
    if (StrategyProfit / MedianPrice) < MaxLostPerMonth*(-1) then
    Quit
    endif
    ENDIF
    
    IF 0 Then // Needs to be improved
    MaxDrawDownPercentage = 10 // Max DrawDown of x%
    Equity = Capital + StrategyProfit
    HighestEquity = Max (HighestEquity,Equity) // Save the Maximum Equity we got
    MaxDrawdown = HighestEquity * (MaxDrawDownPercentage/100)
    ExitFromMarketCond = Equity <= HighestEquity - MaxDrawdown
    IF ExitFromMarketCond Then
    Quit
    ENDIF
    ENDIF
    endif
    
    //#******************************************************************#
    //#                           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
    
    
    
    Capture-decran-2023-05-12-a-13.40.06.png Capture-decran-2023-05-12-a-13.40.06.png
    #214630 quote
    ZeroCafeine
    Participant
    Senior

    I 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

    // 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        = 100000
    Once Equity         = Capital
    Once TrailinStop    = 0  // 1 on - 0 off // Needs to be improved
    Once BreakEaven     = 1  // 1 on - 0 off
    Once BreakRange     = 1  // 1 on - 0 off
    Once MFE            = 0  // 1 on - 0 off // Needs to be improved
    Once QuitStrategy   = 0  // 1 on - 0 off // Needs to be improved
    Once MaxBuyPerDay   = 15 // Maximum shares we can buy per day // Z2
    Once 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 improved
    Once MaxBuyShare    = 10 // Maximum of shares we can buy (Marging math)
    Once PercentOfBoxSL = 10 // Percent of Tokyo Box for Initialization the First Stop Loss
    Once N              = 1  // Buy N Shares
    Once Spread         = 2  // Spread fees x 2
    MedianPriceJPY = 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) // Z5
    FranceDST           = 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) // Z5
    FranceWinTime       = Month=11 OR Month=12 OR Month=1 OR Month=2 OR Month=3 // Z5
    
    IF (DayOfWeek = 1 AND Time > 080500) THEN
    MyMondayPeriod = 1
    MyFridayPeriod = 0
    ENDIF
    IF (DayOfWeek = 2 AND Time > 080500) THEN
    MyMondayPeriod = 0
    MyTuesdayPeriod = 1
    ENDIF
    IF (DayOfWeek = 3 AND Time > 080500) THEN
    MyTuesdayPeriod = 0
    MyWednesdayPeriod = 1
    ENDIF
    IF (DayOfWeek = 4 AND Time > 080500) THEN
    MyWednesdayPeriod = 0
    MyThursdayPeriod = 1
    ENDIF
    IF (DayOfWeek = 5 AND Time > 080500) THEN
    MyThursdayPeriod = 0
    MyFridayPeriod = 1
    ENDIF
    
    //#******************************************************************#
    //#                              FonctionS                           #
    //#******************************************************************#
    IF FranceDST THEN
    EndOfBoxTime = 080500
    BeginBoxTime = 020000
    ELSIF FranceWinTime THEN
    EndOfBoxTime = 070000
    BeginBoxTime = 010000
    ENDIF
    
    IF Time = EndOfBoxTime THEN
    x2 = BarIndex[0]
    x1 = BarIndex[73]
    yH = Highest[72](High[1])
    yL = Lowest [72](Low[1])
    os = 4*pipsize
    DayRange = (yH - yL) / pipsize
    ENDIF
    
    IF NOT OnMarket THEN // Dc
    FirstSL = 0
    NotOnMArket = 1
    ENDIF
    
    //#******************************************************************#
    //#                         Money Management                         #
    //#******************************************************************#
    
    IF Time = 080500 THEN // Ec // #97
    CountOfPurchase        = 0 // Vc & Z3
    LastDayCountOfPosition = CountOfPosition
    Flag = 1
    ENDIF
    
    MoreMathFlag = LastDayCountOfPosition>0 AND Not OnMArket AND OnMarket[1] AND Flag=1
    
    IF MoreMathFlag THEN // #97
    TodayStrategyProfit = StrategyProfit
    CountOfMyPosition    = CountOfPosition[1] - LastDayCountOfPosition
    LastEntryPrice  = TradePrice(CountOfPosition[1]+1)
    LastExitPrice  = TradePrice
    DiffEntryExitJPY = (((LastEntryPrice - LastExitPrice )/Pipsize)*PointValue)*CountOfMyPosition
    Flag = 0
    ENDIF
    
    IF MyMondayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    MondayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    MondayLosingTrades = MondayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    MondayLossesJPY = MondayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    MondayLosingTrades = MondayLosingTrades + 1
    endif
    ENDIF
    
    IF MyTuesdayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    TuesdayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    TuesdayLosingTrades = TuesdayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    TuesdayLossesJPY = TuesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    TuesdayLosingTrades = TuesdayLosingTrades + 1
    endif
    ENDIF
    
    IF MyWednesdayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    WednesdayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    WednesdayLosingTrades = WednesdayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    WednesdayLossesJPY = WednesdayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    WednesdayLosingTrades = WednesdayLosingTrades + 1
    endif
    ENDIF
    
    IF MyThursdayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    ThursdayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    ThursdayLosingTrades = ThursdayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    ThursdayLossesJPY = ThursdayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    ThursdayLosingTrades = ThursdayLosingTrades + 1
    endif
    ENDIF
    
    IF MyFridayPeriod THEN
    if LastDayCountOfPosition > 0 AND StrategyProfit <> StrategyProfit[1] then
    FridayLossesJPY = DiffEntryExitJPY
    DiffEntryExitJPY = 0
    LastDayCountOfPosition = 0
    FridayLosingTrades = FridayLosingTrades + 1
    endif
    if StrategyProfit < StrategyProfit[1] AND LastDayCountOfPosition = 0 then
    FridayLossesJPY = FridayLossesJPY + (StrategyProfit[1] - StrategyProfit)
    FridayLosingTrades = FridayLosingTrades + 1
    endif
    ENDIF
    
    MondayLossesEuro    = MondayLossesJPY    / MedianPriceJPY
    TuesdayLossesEuro   = TuesdayLossesJPY   / MedianPriceJPY
    WednesdayLossesEuro = WednesdayLossesJPY / MedianPriceJPY
    ThursdayLossesEuro  = ThursdayLossesJPY  / MedianPriceJPY
    FridayLossesEuro    = FridayLossesJPY    / MedianPriceJPY
    
    WeekLossesJPY  = MondayLossesJPY + TuesdayLossesJPY + WednesdayLossesJPY + ThursdayLossesJPY + FridayLossesJPY // Pc
    
    WeekLossesEuro  = WeekLossesJPY/ MedianPriceJPY
    
    WeekLosingTrades = MondayLosingTrades+TuesdayLosingTrades+WednesdayLosingTrades+ThursdayLosingTrades+FridayLosingTrades
    
    MonthLossesEuro = (LastWeekLossesJPY / MedianPriceJPY) +  WeekLossesEuro
    
    IF MyMondayPeriod THEN
    DayLossesEuro = MondayLossesEuro
    ENDIF
    IF MyTuesdayPeriod THEN
    DayLossesEuro = TuesdayLossesEuro
    ENDIF
    IF MyWednesdayPeriod THEN
    DayLossesEuro = WednesdayLossesEuro
    ENDIF
    IF MyThursdayPeriod THEN
    DayLossesEuro = ThursdayLossesEuro
    ENDIF
    IF MyFridayPeriod THEN
    DayLossesEuro = FridayLossesEuro
    ENDIF
    
    IF DayOfWeek = 1 AND Time = 080000 THEN // Reset Mnday AT 8:00 => 080500
    LastWeekLossesJPY  = WeekLossesJPY // to get net week for Moth Losses
    MondayLossesJPY    = 0
    TuesdayLossesJPY   = 0
    WednesdayLossesJPY = 0
    ThursdayLossesJPY  = 0
    FridayLossesJPY    = 0
    MondayLosingTrades    = 0
    TuesdayLosingTrades   = 0
    WednesdayLosingTrades = 0
    ThursdayLosingTrades  = 0
    FridayLosingTrades    = 0
    WeekLosingTrades      = 0
    ENDIF
    
    if Month <> Month[1] then
    MonthFlag = 1
    endif
    
    if MonthFlag = 1 AND DayOfWeek = 1 AND Time = 080500 then
    LastWeekLossesJPY = 0
    MonthFlag = 0
    endif
    
    //#******************************************************************#
    //#                   Long Condition Signals                         #
    //#******************************************************************#
    
    TradingTimeCondition = (Time >= 080500 AND Time <= 200000 AND DayOfWeek < 5) OR  (Time >= 080500 AND Time < 170000 AND DayOfWeek = 5) // Tc
    C1 = TradingTimeCondition
    
    LongSignal = Close Crosses Over yH
    C2 = LongSignal
    
    IF LongSignal Then // Lc
    FirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // Hc
    LastFirstSL = FirstSL
    ENDIF
    
    IF Time = 080500 AND CountOfPOsition >= 1 THEN // Condition to force the first purchase even if we are in position since yesterday
    NotOnMArket = 1
    ENDIF
    
    C3 = NotOnMArket
    
    C4 = CountOfPurchase < MaxBuyPerDay
    
    C5 = CountOfLongShares < MaxBuyShare
    
    DayLostCondition  = DayLossesEuro < MaxLostPerDay // Jc & Z7
    C6 = DayLostCondition
    
    WeekLostCondition = WeekLossesEuro  < MaxLostPerWeek // Qc
    C7 = WeekLostCondition
    
    MonthLostCondition = MonthLossesEuro < MaxLostPerMonth
    C8 = MonthLostCondition
    
    LongSignalAllCondition = C1 AND C2 AND C3 AND C4 AND C5 AND C6 AND C7 AND C8
    
    IF LongSignalAllCondition THEN
    Buy N Contract AT Market
    SET STOP PRICE FirstSL
    ENDIF
    
    IF LongSignalAllCondition [1] AND NotOnMArket[1] AND CountOfPosition > 0 THEN // can be improved ?
    NotOnMArket = 0
    ENDIF
    
    IF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THEN // Wc // // can be improved ?
    CountOfPurchase = CountOfPurchase + 1
    ENDIF
    
    //#******************************************************************#
    //#         Trailing & BreakEven & Range Stop Loss & MFE             #
    //#******************************************************************#
    Once trailingstart   = 140       // Trailing start after X pips profit
    Once trailingstep    = 10        // Trailing step to move the "stoploss"
    Once StartBERatio    = 5         // BE Start for the hole position when the RR(FirstSL) = 5
    Once StartBreakRangePercent = 20 // Close > Last entry + 20% of the Tokyo Box
    Once PointsToKeep    = 2*Spread  // Spread to add to BE price
    Once TRAILINGMFE     = 20        // Trailing stop with the Max Favorable Excursion
    
    // Trailing
    if TrailinStop > 0 then // Needs to be improved
    IF NOT ONMARKET THEN
    NewSL=0
    ENDIF
    IF LONGONMARKET THEN
    // Trailing Start
    IF NewSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    NewSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    // Trailing Step Move
    IF NewSL>0 AND close-NewSL>=trailingstep*pipsize THEN
    NewSL = NewSL+trailingstep*pipsize
    ENDIF
    ENDIF
    //stop order to exit the positions
    IF NewSL>0 THEN
    SELL AT NewSL STOP
    ENDIF
    endif
    
    // Range Stop Loss
    if BreakRange > 0 then // Fc
    IF Not OnMarket THEN
    BreakRangeLevel = 0
    ENDIF
    IF LongOnMarket THEN
    BreakRangeMath  = TradePrice + (((yH-yL)/100)*StartBreakRangePercent)
    ENDIF
    IF LongOnMarket AND Close Crosses Over BreakRangeMath THEN // Z1
    BreakRangeLevel = yH - 2*Pipsize // Gc
    //FirstSL = 0
    ENDIF
    IF BreakRangeLevel > 0 THEN //Z8
    SELL AT BreakRangeLevel STOP
    ENDIF
    endif
    
    // BreakEven Stop Loss
    if BreakEaven>0 then
    IF Not OnMarket THEN
    BreakEvenLevel = 0
    ENDIF
    yHplusFirstSL = yH + (StartBERatio*(yH-LastFirstSL))
    IF LongOnMarket AND Close Crosses Over yHplusFirstSL THEN
    BreakEvenLevel  = TradePrice + PointsToKeep*pipsize
    ENDIF
    IF BreakEvenLevel > 0 THEN
    SELL AT BreakEvenLevel STOP
    ENDIF
    endif
    
    if MFE > 0 then // Needs to be improved
    if not onmarket then
    MAXPRICEMFE = 0
    MINPRICEMFE = close
    priceexitMFE = 0
    endif
    if longonmarket then
    MAXPRICEMFE = MAX(MAXPRICEMFE,close) //saving the MFE of the current trade
    if MAXPRICEMFE-tradeprice(1)>=TRAILINGMFE*pointsize then //if the MFE is higher than the trailingstop then
    priceexitMFE = MAXPRICEMFE-TRAILINGMFE*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    if onmarket and priceexitMFE>0 then
    SELL AT priceexitMFE STOP
    endif
    endif
    
    //#******************************************************************#
    //#                              Graph                               #
    //#******************************************************************#
    // Blue  Azur    (0, 127, 255) & Maya (115, 194, 251)
    // Green Sinople (20, 148, 20) &
    
    IF 0 THEN
    Graph 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)
    ENDIF
    
    IF 0 THEN
    Graph 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"
    ENDIF
    
    IF 0 THEN
    Graph 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"
    ENDIF
    
    IF 0 THEN
    Graph 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 WeekLosingTrades
    ENDIF
    
    IF 1 THEN
    Graph C1
    Graph C2
    Graph C3
    Graph C4
    Graph C5
    Graph C6
    Graph C7
    Graph C8
    Graph LongSignalAllCondition Coloured (0,0,240)
    ENDIF
    
    //#******************************************************************#
    //#                           Stop Strategy                          #
    //#******************************************************************#
    
    if QuitStrategy then
    IF 1 THEN // Nc & Z9 // Needs to be improved
    if (StrategyProfit / MedianPriceJPY) < MaxLostPerMonth*(-1) then
    Quit
    endif
    ENDIF
    
    IF 0 Then // Needs to be improved
    MaxDrawDownPercentage = 10 // Max DrawDown of x%
    Equity = Capital + StrategyProfit
    HighestEquity = Max (HighestEquity,Equity) // Save the Maximum Equity we got
    MaxDrawdown = HighestEquity * (MaxDrawDownPercentage/100)
    ExitFromMarketCond = Equity <= HighestEquity - MaxDrawdown
    IF ExitFromMarketCond Then
    Quit
    ENDIF
    ENDIF
    endif
    
    //#******************************************************************#
    //#                           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
    
    PeterSt and pavix thanked this post
Viewing 6 posts - 91 through 96 (of 96 total)
  • You must be logged in to reply to this topic.

End Of Day – YEN M15 Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 95 replies,
has 8 voices, and was last updated by ZeroCafeine
2 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/24/2023
Status: Active
Attachments: 39 files
Logo Logo
Loading...