End Of Day – YEN M15 Strategy

Viewing 15 posts - 61 through 75 (of 96 total)
  • Author
    Posts
  • #213038 quote
    ZeroCafeine
    Participant
    Senior

    let’s do the V11 with only Long position, now I will try on M5 with 200k :

    // Strategy Name    : END OF DAY  -  YEN
    // Version          : 11.0
    // Information      : Adding Box BreakOut in M5
    // Stroks           : USD/JPY Mini
    // Time Frame       : M5
    // Initial Capital  : 100 000 JPY
    // Test on          : 200K Candles
    // Spread           : 2
    // ########################################################################
     
    Defparam cumulateorders = false
    defparam flatafter = 210000
    Once Capital    = 100000
    Once Equity     = Capital
    Once trailinstop= 1  //1 on - 0 off
    Once breakeaven = 1  //1 on - 0 off
    Once MFE=0           //1 on - 0 off
    
    N = 1             // Buy N Shares
    SL = 12           // Stop Loss = SL pips
    Spread = 2        // Spread fees x 2
    TRAILINGMFE = 20
    // ########################################################################
    // ______               _   __
    //|  ____|             | | /  \
    //| |__ ___  _ __   ___| || () |
    //|  __/ _ \| '_ \ / __| __\__/
    //| | | (_) | | | | (__| |_
    //|_|  \___/|_| |_|\___|\__|
     
    if longonmarket then
    AlreadyBuy=1
    endif
    
    if intradaybarindex=0 then
    AlreadyBuy=0
    MyProfits = strategyprofit
    endif
    
    
    if time = 081000 then
    yh = highest[74](high)
    yL=lowest[74](low)
    os = 2*pipsize
    endif
    
    TimeCondition = time>081000 and time<200000
    
    // LONGS
    if TimeCondition and strategyprofit <= MyProfits then
    if close<yh+os and not AlreadyBuy  then
    buy 1 contract at yh+os stop
    endif
    endif
    
    IF LongOnMarket Then
    Set Stop pLoss SL
    ENDIF
    
    // ########################################################################
    // _______        _ _ _ _
    //|__   __|      (_) | (_)
    //   | |_ __ __ _ _| | |_ _ __   __ _
    //   | | '__/ _| | | | | '_ \ / _ |
    //   | | | | (_| | | | | | | | | (_| |
    //   |_|_|  \__,_|_|_|_|_|_| |_|\__, |
    //                               __/ |
    //                               |___/
    
    trailingstart = 140 //trailing start after X pips profit
    trailingstep = 10 //trailing step to move the "stoploss"
    
    startBreakeven = 30 // Activate BE after startBreakeven pips
    PointsToKeep = 5 // Spread to add to BE price
    
    if trailinstop>0 then
    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
    
    if breakeaven>0 then
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    //first move (breakeven)
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    endif
    
    if MFE>0 then
    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 floatingprofit AS "floatingprofit"
    //Graph PositionPerf * 100 AS "PositionPerf"
    //Graph PositionPerf(1) * 100 AS "PositionPerf[1]"
    //Graph floatingprofit AS "floatingprofit"
    //GraphOnPrice TradePricecoloured(0,220,0) AS "Long Trade Price"
    
    // Draw Equity
    //Graph Equity AS "Equity"
    //Graph Capital AS "Capital"
    
    // ########################################################################
    //   _____ _                 _____           _
    //  / ____| |               / ____|         | |
    // | (___ | |_ ___  _ __   | (___  _ __ __ _| |_ ___  __ _ _   _
    //  \___ \| __/ _ \| '_ \   \___ \| '__/ _| __/ _ \/ _ | | | |
    //  ____) | || (_) | |_) |  ____) | | | (_| | ||  __/ (_| | |_| |
    // |_____/ \__\___/| .__/  |_____/|_|  \__,_|\__\___|\__, |\__, |
    //                 | |                                __/ | __/ |
    //                 |_|                               |___/ |___/
    MaxDrawDownPercentage = 20 // 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
     
    

    Next step is to add Short position and try do control this drawdown problem, and maybe next time is to control the quantity of share for enter with more share if the trade is positif and with more share if the equity is positif

    GraHal thanked this post
    #213583 quote
    ZeroCafeine
    Participant
    Senior

    Before continuing let’s set some good rules about the GTM schedule and the Tokyo session which opens from 09Am to 3Pm local time in Tokyo, If you think I’m wrong or that the code is not good, please participate 😉 :

    // Paris  : 02H ==================  8H  /  UTC + 2
    // London : 01H ==================  7H  /  UTC + 1
    // GTM    : 00H ==================  6H  /  UTC
    // Tokyo  : 09H ================== 15H  /  UTC + 9
    // My UTC Time = UTC + 2
    
    if time = 081000 then //
    x1= barindex[0] //
    x2 = barindex[74] //
    yh = highest[74](high)
    yL=lowest[74](low)
    
    DRAWRECTANGLE(x1, yh, x2,yL ) COLOURED(0,0,0)
    os = 4*pipsize
    drawtext("#yh#",x2,yh+os,SansSerif,bold,10) coloured(0,0,0)
    drawtext("#yL#",x2,yL-os,SansSerif,bold,10) coloured(0,0,0)
    endif
    
    if (time >= 061000 AND time <= 230000) then
    drawsegment(x1,yh,barindex,yh) coloured (0,0,255) STYLE(DOTTEDLINE3,1)
    drawsegment(x1,yL,barindex,yL) coloured (0,0,255) STYLE(DOTTEDLINE3,1)
    endif
    
    return
    
    robertogozzi thanked this post
    #213614 quote
    robertogozzi
    Moderator
    Master

    Thank you for sharing your code.

    I only want to point out that those time offsets from UTC are valid when DST is active, when it is not, then 1 hour has to be subtracted from them.

    In addition, with GTM you probably meant GMT, right?

    ZeroCafeine thanked this post
    #213617 quote
    ZeroCafeine
    Participant
    Senior

    Let’s say here is the new code, I reduced the size of the segments so that it stops just before the box, and I added the size of the range :

    // Indicator Name : Tokyo Box v2
    // Paris  : 02H ==================  8H  /  UTC + 2
    // London : 01H ==================  7H  /  UTC + 1
    // GMT    : 00H ==================  6H  /  UTC
    // Tokyo  : 09H ================== 15H  /  UTC + 9
    // My UTC Time = UTC + 2
    
    IF Time = 081000 THEN
    x2 = BarIndex[0]
    x1 = BarIndex[74]
    yH = Highest[74](High)
    yL = Lowest [74](Low)
    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 >= 061000 AND Time <= 230000) then
    DrawSegment(x2, yH, BarIndex-72, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    DrawSegment(x2, yL, BarIndex-72, yL) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    ENDIF
    
    Return
    
    t-box-2.png t-box-2.png
    #213619 quote
    ZeroCafeine
    Participant
    Senior

    tks you @robertogozzi for your tips, what is DST Active or Not pls ?

    and yes GTM it’s my French mistake, it’s GMT = UTC

    #213622 quote
    robertogozzi
    Moderator
    Master

    DST stands for Daylight Saving Time (heure d’été).

    In most EU it starts on the last Sunday of March at 02:00 (2am) and ends on the last Sunday of October at 02:00 (2am). In EU not all countries are at UTC+2 (UTC+1 when DST is not active), Portuga share the TZ with UK (now UTC+1), Greece, Finland, Rumenia etc… are now in UTC+3 (https://www.timeanddate.com/time/europe/).

    Not all countries, across the world, as well as some states in USA, support DST.

    ZeroCafeine thanked this post
    #213631 quote
    ZeroCafeine
    Participant
    Senior

    Thank you very much for your answer and your tip, at first I thought it was an option I could enable or disable directly on the ProRealTime software, I think this is not the case, please correct me if I am wrong

    So I had to think differently about my indicator and it made my head hurt 😅 but anyway I hope to make progress thanks to you 😊,

    Here is a first version of the indicator with the summer hours and others

    I don’t know yet how to manipulate the dates for the weekend when the time change, For the moment I stop before the last week of March and October (< day 24)

    // Indicator Name : Tokyo Box v2
    
    // GTM    : 00H ==================  6H  /  UTC
    // Tokyo  : 09H ================== 15H  /  UTC + 9 / JST (Japan Standard Time)
    
    // Paris  : 02H ==================  8H  /  UTC + 2 / DST (Daylight Saving Time)
    // Paris  : 01H ==================  7H  /  UTC + 1 / Winter
    
    // London : 01H ==================  7H  /  UTC + 1 / DST (Daylight Saving Time)
    // London : 00H ==================  6H  /  UTC + 0 / Winter
    
    // for Paris with Time Frame M5 : 
    // When is DST : IntraDayBarIndex of 8:10H = 98
    // When Winter : IntraDayBarIndex of 7:10H = 86
    
    // https://www.timeanddate.com/time/europe/
    // ########################################################################
    
    FranceDstTime    = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24)
    FranceWinterTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day <24)
    
    // this is the out of Tokyo-Box IntraDayBarIndex for France
    IF FranceDstTime THEN
    IntraDayBarIndexStart = 98
    IntraDayBarIndexEnd   = 23
    ELSIF FranceWinterTime THEN
    IntraDayBarIndexStart = 86
    IntraDayBarIndexEnd   = 11
    ENDIF
    
    IF IntraDayBarIndex = IntraDayBarIndexStart THEN
    x2 = BarIndex[0]
    x1 = BarIndex[74]
    yH = Highest[74](High)
    yL = Lowest [74](Low)
    os = 4*pipsize
    DayRange = (yH - yL) / pipsize
    DrawRectangle(x2-1, yH, x1, yL) Coloured(0,0,0)
    DrawText("#yH#", x1, yH+os, SansSerif, Bold, 10) Coloured(0,0,0)
    DrawText("Range : #DayRange# Pips",((x2-x1)/2)+x1,yH+os,SansSerif,Bold,10) Coloured(0,0,0)
    DrawText("#yL#", x1, yL-os, SansSerif, Bold, 10) Coloured(0,0,0)
    ENDIF
    
    IF IntraDayBarIndex >= IntraDayBarIndexStart OR IntraDayBarIndex < IntraDayBarIndexEnd THEN
    DrawSegment(BarIndex, yH, x2-1, yH) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    DrawSegment(BarIndex, yL, x2-1, yL) Coloured (0, 127, 255) STYLE(DOTTEDLINE3,1)
    ENDIF
    
    Return

    if you have a link on the forum or an example it would be appreciated 😊

    #213700 quote
    ZeroCafeine
    Participant
    Senior

    hi everyone

    I am progressing slowly but surely, nothing exceptional, here is a draft in version 12, I’ll try to sort it out for version 13,

    also I made the choice deliberately to be only long on the market, the programming of a strategy is already complicated so we are not going to complicate it even more with only one code for the Long and Short position at the same time, for the Short I let you reverse the code

    at the moment I am trying to manage and control just the entries and their stop loss, I notice that if I have a position with more than one stock then the FirstSL is not well managed, this will be the next step

    I also noted some notes in the code at the end just after the “Hello ToTo” logo, it allows me to remember what I’m doing and to find my notes in the code, if you have other origanisation solutions I’m interested

    // Strategy Name    : END OF DAY  -  YEN           // Version             : 12.0
    // Stroks           : USD/JPY Mini                 // indicator associate : Tokyo Box v2
    // Time Zone / TF   : Paris-France (GTM+2) / M5    //
    // Tokyo Session    : 9Am - 3Pm (UTC+9)            //
    // Spread           : 2                            //
    // Information      :
    // ########################################################################
    Defparam cumulateorders = True
    Once Capital      = 100000
    Once Equity       = Capital
    Once TrailinStop  = 0  //1 on - 0 off
    Once BreakEaven   = 0  //1 on - 0 off
    Once BreakRange   = 1  //1 on - 0 off
    Once MFE          = 0  //1 on - 0 off
    Once DrawDownQuit = 0  //1 on - 0 off
    Once MaxBuyPerDay = 15  // Maximum shares we can buy per day // Z2
    MaxLostPerDay = 10 // We can buy until we don't lost 10€ per Day
    Once MaxBuyShare  = 10 // Maximum of shares we can buy (Marging)
    Once TRAILINGMFE  = 20 // Trailing stop with the Max Favorable Excursion
    Once N            = 1  // Buy N Shares
    Once Spread       = 2  // Spread fees x 2
    FranceDstTime    = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24)
    FranceWinterTime = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24)
    // ########################################################################
    // Fonct°
    IF FranceDstTime THEN // Cc
    IntraDayBarIndexStart = 98
    IntraDayBarIndexEnd   = 23
    ELSIF FranceWinterTime THEN
    IntraDayBarIndexStart = 86
    IntraDayBarIndexEnd   = 11
    ENDIF
    
    IF IntraDayBarIndex = IntraDayBarIndexStart THEN // Ac & Cc
    x2 = BarIndex[0]
    x1 = BarIndex[74]
    yH = Highest[72](High[2])
    yL = Lowest [72](Low[2])
    DayRange = (yH - yL) / pipsize
    ENDIF
    
    IF NOT OnMarket THEN // Dc
    FirstSL = 0
    ENDIF
    
    IF IntraDayBarIndex = 24 THEN // Ec
    CountOfPurchase = 0 // Z3
    AlreadyBought = 0
    MyProfitInTheBeginingOfDay = StrategyProfit
    LastCountOfPosition = CountOfPosition
    ENDIF
    
    MyDayProfit = StrategyProfit - MyProfitInTheBeginingOfDay
    
    DayLostCondition = (MyDayProfit/Medianprice) > MaxLostPerDay*(-1)
    
    TimeCondition = (Time > 081000 AND Time < 200000 AND DayOfWeek < 5) OR  (Time > 081000 AND Time < 170000 AND DayOfWeek = 5) // Tc
    LongSignal  = TimeCondition AND Close Crosses Over yH // Lc
    
    IF LongSignal AND Not OnMarket Then // Lc
    FirstSL = yH - ((yH-yL)/10)// Hc
    ENDIF
    
    if TimeCondition then // T
    IF LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND CountOfPosition = LastCountOfPosition THEN
    Buy N Contract AT Market
    SET STOP PRICE FirstSL
    ENDIF
    endif
    
    IF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THEN
    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 startBreakeven = 30
    Once StartBreakRangePercent = 20
    Once PointsToKeep    = 2*Spread  // Spread to add to BE price
    
    // 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
    
    // BreakEven
    if breakeaven>0 then // Needs to be improved
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    //first move (breakeven)
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    endif
    
    // Range Stop Loss
    if BreakRange > 0 then // Fc
    IF Not OnMarket THEN
    BreakRangeLevel = 0
    ENDIF
    IF LongOnMarket THEN
    StartBreakRange  = yH + (((yH-yL)/100 )*StartBreakRangePercent)
    ENDIF
    IF LongOnMarket AND Close >= StartBreakRange THEN // Z1
    BreakRangeLevel = yH - 2*Pipsize // Gc
    ENDIF
    IF BreakRangeLevel>0 THEN
    SET STOP PRICE BreakRangeLevel
    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
    
    // ########################################################################
    // Stop Strategy
    IF DrawDownQuit 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
    
    // ########################################################################
    //   _    _      _ _         _______ _______
    //  | |  | |    | | |       |__   __|__   __|
    //  | |__| | ___| | | ___      | | ___ | | ___
    //  |  __  |/ _ \ | |/ _ \     | |/ _ \| |/ _ \
    //  | |  | |  __/ | | (_) |    | | (_) | | (_) |
    //  |_|  |_|\___|_|_|\___/     |_|\___/|_|\___/
    
    // GMT    : 00H ==================  6H  /  UTC
    // Tokyo  : 09H ================== 15H  /  UTC + 9 / JST (Japan Standard Time)
    
    // Paris  : 02H ==================  8H  /  UTC + 2 / DST (Daylight Saving Time)
    // Paris  : 01H ==================  7H  /  UTC + 1 / Winter
    
    // London : 01H ==================  7H  /  UTC + 1 / DST (Daylight Saving Time)
    // London : 00H ==================  6H  /  UTC + 0 / Winter
    
    // for Paris with Time Frame M5 :
    // When is DST : IntraDayBarIndex of 8:10H = 98
    // When Winter : IntraDayBarIndex of 7:10H = 86
    
    // https://www.timeanddate.com/time/europe/
    
    
    // Rules : Xc = X-Condition
    
    // Ac : Tokyo Box mean Tokyo trading session from 9Am to 3Pm Local time (JST
    //     Means from 00 to 6Am GMT, you have to addapt with your contry
    
    // Bc : Our Trading it's from 3Pm at Tokoy so from 8:10Am in Prais when DST and 7:10Am when Winter
    
    // Cc : When we are in DST and when we are in Winter
    
    // Dc : IF Not On Market, I reset the First Stop Loss
    
    // Ec : We reset the Count of some variable we need to use at 2Am = IntraDayBarIndex = 24
    //      So in the first candle of Tokyo Box
    //      And we store some variable that we will need
    
    // Fc : Initialise the StartBreakRange with a dynmic value and not static one,
    //      the math is the Range value + StartBreakRangePercent%,
    //      Exmeple :
    //      Range (yH-yL) = 60Pips & yH = 142,219 & StartBreakRangePercent = 20%
    //      means we set the NewSL below the Highest - 2 pips (yH -2)
    //      142,219 + (60Pips x 20%) = 142,219 + 12Pips = 142,339 JPY
    
    // Gc : the idea is to put a stop loss 2 pips down then the highest value of the range
    
    // Hc : Initialisation du First Stop Loss, We assume that the box will be broken 
    //      and that the break is real, so in this case we put a stop loss at 10% below the high
    
    // Tc : Time condition, we bay only after Tokyo Box (A) and before 8Pm for all the day of week exept the Day 5 = Friday we stop at 5Pm
    
    // Lc : initialise the First Stop Loss if we get a Close > the Tokyo Box 
    //      and we are in TimeCondition (Tc)
    
    // #################
    
    // Z1 : I have to find a better solutoion the the Close option
    
    // Z2 : better to control the value of this variable : MaxBuyPerDay by the money
    //      we can lose in 1 days, So I have to count my Profit per day
    
    // Z3 : I noticed when the Buy and Sell order is in the same candle so the CountOfPurchase 
    //      still the same and it's not incremented with +1
                                                
                                                 
    
    #213716 quote
    ZeroCafeine
    Participant
    Senior

    no need answers now, just speack to myself 😁

    // Strategy Name    : END OF DAY  -  YEN           // Version             : 13.0
    // Stroks           : USD/JPY Mini                 // indicator associate : Tokyo Box v2
    // Time Zone / TF   : Paris-France (GTM+2) / M5    //
    // Tokyo Session    : 9Am - 3Pm (UTC+9)            //
    // Spread           : 2                            //
    // Information      : le SET STOP PRICE FirstSL  et que ma position est superieur à 1 shares
    // ########################################################################
    Once Capital        = 100000
    Once Equity         = Capital
    Once TrailinStop    = 0  //1 on - 0 off
    Once BreakEaven     = 0  //1 on - 0 off
    Once BreakRange     = 1  //1 on - 0 off
    Once MFE            = 0  //1 on - 0 off
    Once DrawDownQuit   = 0  //1 on - 0 off
    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
    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
    FranceDstTime       = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24) // Z5
    FranceWinterTime    = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24) // Z5
    // ########################################################################
    // Fonct°
    IF FranceDstTime THEN // Cc
    IntraDayBarIndexStart = 98
    IntraDayBarIndexEnd   = 23
    ELSIF FranceWinterTime THEN
    IntraDayBarIndexStart = 86
    IntraDayBarIndexEnd   = 11
    ENDIF
    
    IF IntraDayBarIndex = IntraDayBarIndexStart THEN // Ac & Cc
    x2 = BarIndex[0]
    x1 = BarIndex[74]
    yH = Highest[72](High[2])
    yL = Lowest [72](Low[2])
    DayRange = (yH - yL) / pipsize
    ENDIF
    
    IF NOT OnMarket THEN // Dc
    FirstSL = 0
    ENDIF
    
    IF IntraDayBarIndex = 24 THEN // Ec
    CountOfPurchase = 0 // Z3
    MyProfitInTheBeginingOfDay = StrategyProfit
    LastDayCountOfPosition     = CountOfPosition // Kc
    ENDIF
    
    MyDayProfit = StrategyProfit - MyProfitInTheBeginingOfDay
    
    DayLostCondition = (MyDayProfit/Medianprice) > MaxLostPerDay*(-1) // Jc
    
    TimeCondition = (Time > 081000 AND Time < 200000 AND DayOfWeek < 5) OR  (Time > 081000 AND Time < 170000 AND DayOfWeek = 5) // Tc
    
    LongSignal  = TimeCondition AND Close Crosses Over yH // Lc
    
    IF LongSignal Then // Lc
    FirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // Hc
    ENDIF
    
    if TimeCondition then // Tc
    LongSignalAllCondition = LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND (CountOfPosition = LastDayCountOfPosition OR Not OnMarket)
    
    IF LongSignalAllCondition THEN
    Buy N Contract AT Market
    SET STOP PRICE FirstSL
    ENDIF
    endif
    
    IF LongOnMarket AND CountOfPosition > 1 THEN // Z6
    Sell CountOfPosition Shares AT FirstSL STOP
    ENDIF
    
    IF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THEN
    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 startBreakeven  = 30
    Once StartBreakRangePercent = 20
    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
    
    // BreakEven
    if breakeaven>0 then // Needs to be improved
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    //first move (breakeven)
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    endif
    
    // Range Stop Loss
    if BreakRange > 0 then // Fc
    IF Not OnMarket THEN
    BreakRangeLevel = 0
    ENDIF
    IF LongOnMarket THEN
    StartBreakRange  = yH + (((yH-yL)/100)*StartBreakRangePercent)
    ENDIF
    IF LongOnMarket AND Close >= StartBreakRange THEN // Z1
    BreakRangeLevel = yH - 2*Pipsize // Gc
    ENDIF
    IF BreakRangeLevel>0 THEN
    SET STOP PRICE BreakRangeLevel
    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
    
    // ########################################################################
    // Stop Strategy
    IF DrawDownQuit 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
    
    // ########################################################################
    //   _    _      _ _         _______ _______
    //  | |  | |    | | |       |__   __|__   __|
    //  | |__| | ___| | | ___      | | ___ | | ___
    //  |  __  |/ _ \ | |/ _ \     | |/ _ \| |/ _ \
    //  | |  | |  __/ | | (_) |    | | (_) | | (_) |
    //  |_|  |_|\___|_|_|\___/     |_|\___/|_|\___/
    
    // GMT    : 00H ==================  6H  /  UTC
    // Tokyo  : 09H ================== 15H  /  UTC + 9 / JST (Japan Standard Time)
    
    // Paris  : 02H ==================  8H  /  UTC + 2 / DST (Daylight Saving Time)
    // Paris  : 01H ==================  7H  /  UTC + 1 / Winter
    
    // London : 01H ==================  7H  /  UTC + 1 / DST (Daylight Saving Time)
    // London : 00H ==================  6H  /  UTC + 0 / Winter
    
    // for Paris with Time Frame M5 :
    // When is DST : IntraDayBarIndex of 8:10H = 98
    // When Winter : IntraDayBarIndex of 7:10H = 86
    
    // https://www.timeanddate.com/time/europe/
    
    
    // Rules : Xc = X-Condition
    
    // Ac : Tokyo Box : 9Am to 3Pm Local time (JST) = 00 to 6Am GMT
    
    // Bc : Our Trading it's from 3Pm at Tokoy so from 8:10Am in Paris when DST / 7:10Am when Winter
    
    // Cc : Tokyo Box based on IntraDayBarIndex with DST and Winter Time
    
    // Dc : IF Not On Market, I reset the First Stop Loss to 0
    
    // Ec : We reset the Count of some variable we need to use at 2Am = IntraDayBarIndex = 24
    //      So in the first candle of Tokyo Box
    //      And we store some variable that we will need the day after
    
    // Fc : Initialise the StartBreakRange with a dynmic value and not static one,
    //      the math is the Range value + StartBreakRangePercent%,
    //      Exmeple :
    //      Range (yH-yL) = 60Pips & yH = 142,219 & StartBreakRangePercent = 20%
    //      means we set the NewSL below the Highest - 2 pips (yH -2)
    //      142,219 + (60Pips x 20%) = 142,219 + 12Pips = 142,339 JPY
    
    // Gc : the idea is to put a stop loss 2 pips down then the highest value of the range
    
    // Hc : Initialization of the First Stop Loss, We assume that the box will be broken
    //      and that the break is real, so in this case we put a stop loss at 10% 
    //      below the highest of the Tokyo Box
    
    // Jc : if we lost more then MaxLostPerDay € (exemple 10€) per day, we can't buy more, 
    //      fees not include
    
    // Kc : We memorise the last count to position to compair to the one of today
    
    // Tc : Time Conditions, we bay only after Tokyo Box (A) and before 8Pm for all the day of week 
    //      exept the Day 5 = Friday we stop at 5Pm
    
    // Lc : Long signal if we Close > the Tokyo Box and we are in TimeCondition (Tc)
    
    
    // ################# Idea to be developed and questions #################
    
    // Z1 : I have to find a better solutoion the the Close option
    
    // Z2 : better to control the value of this variable : MaxBuyPerDay by the money
    //      we can lose in 1 days, So I have to count my Profit per day
    
    // Z3 : I noticed when the Buy and Sell order is in the same candle so the CountOfPurchase
    //      still the same and it's not incremented with +1
                                                
    // Z5 : I have to finish this DST and Winter works                                             
    
    // Z6 : I add this code : "Sell CountOfPosition Shares AT FirstSL STOP" for exeit from position
    //      when my countofposition is more the 1, I noticed the code : "SET STOP PRICE FirstSL" not
    //      working is my position is more then 1 but the same code working with 
    //      the : "SET STOP PRICE BreakRangeLevel"
    
    
    // #################      Explanation of the code       #################
    
    // Code : (CountOfPosition = LastDayCountOfPosition OR Not OnMarket)
    //        - IF I'm on market I have to compare LastDayCountOfPosition like that I can't 
    //        buy more if my Long condition = 1
    //        - IF my LastDayCountOfPosition so I can't compare, that is why I use OR Not OnMarket 
    
    
    // ################# Last programming where I stopped at #################
    // I solved the problem of FirstSL Exit when my position is more the 1 shares but I get the same problem before when the longcondition by many share after breaking the range
    
    #213723 quote
    JC_Bywan
    Moderator
    Master

    I also noted some notes in the code at the end just after the “Hello ToTo” logo, it allows me to remember what I’m doing and to find my notes in the code, if you have other origanisation solutions I’m interested

    Tip: to find whatever I need to find in long codes (notes, but also groups of code lines far away from each other but related), I often add keyword(s) with //, not used anywhere else in the code, and the CTRL+F (“find”) function applied to said keyword(s), in order to save time scrolling/searching by jumping with “find” from one occurrence to the next.

    ZeroCafeine thanked this post
    #213735 quote
    ZeroCafeine
    Participant
    Senior

    I found solution to my problem by adding this code at line 63 in v 13 :

    IF TimeCondition AND Not OnMarket THEN
    LastDayCountOfPosition = 0
    ENDIF
    #213736 quote
    ZeroCafeine
    Participant
    Senior

    @JC_Bywan tks you so much for you tips, but I don’t realy understand the idea, do you have a photo or link pls 😃 ?

    #213745 quote
    JC_Bywan
    Moderator
    Master

    Photo of your code inside an editor window: click on magnifying glass (or click mouse inside code area and press CTRL+F), then let’s say you want to find fast your “needs to be improved” comments not wasting time scrolling, you type it next to “find”/”rechercher”, then click on “next”/suivant, and it will jump from one to the next, and when reaching last one if clicking next again it goes back up to first one.

    ZeroCafeine thanked this post
    CTRL-F-Find-tip.png CTRL-F-Find-tip.png
    #213889 quote
    ZeroCafeine
    Participant
    Senior

    Hello everyone, I hope you are well

    By the way, thank you very much @JC_Bywan for your answer 😊

    Here is version 15 of my code, before I start trying to make money I mainly want to try and control my losses, and I run into a small problem when I have multiple levels of stop output sometimes I get run on a worse level I guess it’s a programming issue,

    You can see a capture with three output levels respectively, I renamed for ease in SL 1,2 and 3
    SL-3 = BreakRangeLevel (green)
    SL-2 = BreakRangeStarter (blue)
    SL-1 = FirstSL (Red)

    Sometimes my long position is taken out only at the SL-1 level while the other levels are already there, I don’t know what to do?

    As I know it’s a bit complicated for some people to reread all the code and understand I also opened a new post where I phrased the question differently and so here’s the link you might be able to answer me on that post instead of this one I hope I don’t get rapped for a double post

    once I have mastered this problem of the three levels of SL I think I will move on to the calculation of daily losses, and latent losses or gains

    // Strategy Name    : END OF DAY  -  YEN           // Version             : 14.0
    // Stroks           : USD/JPY Mini                 // indicator associate : Tokyo Box v2
    // Time Zone / TF   : Paris-France (GTM+2) / M5    //
    // Tokyo Session    : 9Am - 3Pm (UTC+9)            //
    // Spread           : 2                            //
    // Information      : le SET STOP PRICE FirstSL  et que ma position est superieur à 1 shares
    // ########################################################################
    Once Capital        = 100000
    Once Equity         = Capital
    Once TrailinStop    = 0  //1 on - 0 off
    Once BreakEaven     = 1  //1 on - 0 off
    Once BreakRange     = 1  //1 on - 0 off
    Once MFE            = 0  //1 on - 0 off
    Once DrawDownQuit   = 0  //1 on - 0 off
    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
    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
    FranceDstTime       = Month=4 OR Month=5 OR Month=6 OR Month=7 OR Month=8 OR Month=9 OR (Month=9 AND Day < 24) // Z5
    FranceWinterTime    = Month=11 OR Month=12 OR Month=1 OR Month=2 OR (Month=3 AND Day < 24) // Z5
    // ########################################################################
    // Fonct°
    IF FranceDstTime THEN // Cc
    IntraDayBarIndexStart = 98
    IntraDayBarIndexEnd   = 23
    ELSIF FranceWinterTime THEN
    IntraDayBarIndexStart = 86
    IntraDayBarIndexEnd   = 11
    ENDIF
    
    IF IntraDayBarIndex = IntraDayBarIndexStart THEN // Ac & Cc
    x2 = BarIndex[0]
    x1 = BarIndex[74]
    yH = Highest[72](High[2])
    yL = Lowest [72](Low[2])
    DayRange = (yH - yL) / pipsize
    ENDIF
    
    IF NOT OnMarket THEN // Dc
    FirstSL = 0
    ENDIF
    
    IF IntraDayBarIndex = 24 THEN // Ec
    CountOfPurchase = 0 // Z3
    MyProfitInTheBeginingOfDay = StrategyProfit
    LastDayCountOfPosition     = CountOfPosition // Kc
    ENDIF
    
    MyDayProfit = StrategyProfit - MyProfitInTheBeginingOfDay
    
    DayLostCondition = (MyDayProfit/Medianprice) > MaxLostPerDay*(-1) // Jc & Z7
    
    TimeCondition = (Time > 081000 AND Time < 200000 AND DayOfWeek < 5) OR  (Time > 081000 AND Time < 170000 AND DayOfWeek = 5) // Tc
    
    LongSignal  = TimeCondition AND Close Crosses Over yH // Lc
    
    IF LongSignal Then // Lc
    FirstSL = yH - (((yH-yL)/100)*PercentOfBoxSL) // Hc
    ENDIF
    
    IF TimeCondition AND Not OnMarket THEN
    LastDayCountOfPosition = 0
    ENDIF
    
    if TimeCondition then // Tc
    LongSignalAllCondition = LongSignal AND CountOfPurchase < MaxBuyPerDay AND CountOfLongShares < MaxBuyShare AND DayLostCondition AND (CountOfPosition <= LastDayCountOfPosition)
    
    IF LongSignalAllCondition THEN
    Buy N Contract AT Market
    SET STOP PRICE FirstSL
    ENDIF
    endif
    
    IF LongOnMarket AND CountOfPosition > 1 THEN // Z6
    Sell CountOfPosition Shares AT FirstSL STOP
    ENDIF
    
    IF (OnMarket AND Not OnMarket[1]) OR (ABS(CountOfPosition) > ABS(CountOfPosition[1])) THEN
    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 StartBreakEven  = 30        // BE Start for the hole position
    Once StartBreakRangePercent = 20
    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
    
    // BreakEven
    if BreakEaven>0 then
    IF Not OnMarket THEN
    BreakEvenLevel = 0 // As a Starter
    ENDIF
    //first move (breakeven)
    RRMore = (5*(yH-FirstSL))
    IF LongOnMarket AND Close - yH >= RRMore THEN
    if CountOfPosition = 1 then
    //calculate the breakevenLevel
    BreakEvenLevel = PositionPrice+PointsToKeep*pipsize
    elsif CountOfPosition > 1 then
    BreakEvenLevel = yH + PointsToKeep*pipsize
    endif
    ENDIF
    IF BreakEvenLevel > 0 THEN
    SELL AT BreakEvenLevel STOP
    ENDIF
    endif
    
    // Range Stop Loss
    if BreakRange > 0 then // Fc
    IF Not OnMarket THEN
    BreakRangeStarter = 0 // As a Starter
    ENDIF
    IF LongOnMarket THEN
    BreakRangeLevel  = TradePrice + (((yH-yL)/100)*StartBreakRangePercent) // Level for Starter
    ENDIF
    IF LongOnMarket AND Close >= BreakRangeLevel THEN // Z1
    BreakRangeStarter = yH - 2*Pipsize // Gc
    ENDIF
    IF BreakRangeStarter > 0 AND BreakEvenLevel = 0 THEN //Z8
    SELL AT BreakRangeStarter STOP // As a Starter
    SET STOP PRICE BreakRangeStarter
    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
    
    IF BreakRangeStarter = 0 THEN
    SET STOP PRICE 0
    ENDIF
    // ########################################################################
    // Graph // 
    // Blue  Azur    (0, 127, 255) & Maya (115, 194, 251)
    // Green Sinople (20, 148, 20) & 
    IF 1 THEN
    //Graphonprice BreakEvenLevel AS "BreakEvenLevel"
    //graphonprice FirstSL AS "FirstSL"
    //Graphonprice BreakEvenLevel AS "BreakEvenLevel"
    graphonprice PositionPrice AS "PositionPrice" Coloured (0, 0, 255)
    
    yHplusFirstSL = yH + (5*(yH-FirstSL))
    GraphOnPrice BreakEvenLevel AS "BreakEvenLevel" Coloured (20, 148, 20)
    GraphOnPrice yHplusFirstSL AS "yHplusFirstSL"Coloured (20, 148, 20)
    
    GraphOnPrice BreakRangeLevel AS "BreakRangeLevel" Coloured (115, 194, 251)
    GraphOnPrice BreakRangeStarter AS "BreakRangeStarter" Coloured (115, 194, 251)
    
    GraphOnPrice FirstSL AS "FirstSL" Coloured (233, 56, 63)
    
    //graphonprice yHplusFirstSL AS "yHplusFirstSL"
    //graphonprice BreakEvenLevel AS "BreakEvenLevel"
    Difference = 5*(yH-FirstSL)
    //graph Difference AS "Difference"
    ENDIF
    
    // ########################################################################
    // Stop Strategy
    IF DrawDownQuit 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
    
    // ########################################################################
    //   _    _      _ _         _______ _______
    //  | |  | |    | | |       |__   __|__   __|
    //  | |__| | ___| | | ___      | | ___ | | ___
    //  |  __  |/ _ \ | |/ _ \     | |/ _ \| |/ _ \
    //  | |  | |  __/ | | (_) |    | | (_) | | (_) |
    //  |_|  |_|\___|_|_|\___/     |_|\___/|_|\___/
    
    // GMT    : 00H ==================  6H  /  UTC
    // Tokyo  : 09H ================== 15H  /  UTC + 9 / JST (Japan Standard Time)
    
    // Paris  : 02H ==================  8H  /  UTC + 2 / DST (Daylight Saving Time)
    // Paris  : 01H ==================  7H  /  UTC + 1 / Winter
    
    // London : 01H ==================  7H  /  UTC + 1 / DST (Daylight Saving Time)
    // London : 00H ==================  6H  /  UTC + 0 / Winter
    
    // for Paris with Time Frame M5 :
    // When is DST : IntraDayBarIndex of 8:10H = 98
    // When Winter : IntraDayBarIndex of 7:10H = 86
    
    // https://www.timeanddate.com/time/europe/
    
    // ================== Stop Loss Level ==================
    // Order of Exit :
    
    // BreakRangeStarter
    // FirstSL
    // ================== Stop Loss Level ==================
    
    // Rules : Xc = X-Condition
    
    // Ac : Tokyo Box : 9Am to 3Pm Local time (JST) = 00 to 6Am GMT
    
    // Bc : Our Trading it's from 3Pm at Tokoy so from 8:10Am in Paris when DST / 7:10Am when Winter
    
    // Cc : Tokyo Box based on IntraDayBarIndex with DST and Winter Time
    
    // Dc : IF Not On Market, I reset the First Stop Loss to 0
    
    // Ec : We reset the Count of some variable we need to use at 2Am = IntraDayBarIndex = 24
    //      So in the first candle of Tokyo Box
    //      And we store some variable that we will need the day after
    
    // Fc : Initialise the StartBreakRange with a dynmic value and not static one,
    //      the math is the Range value + StartBreakRangePercent%,
    //      Exmeple :
    //      Range (yH-yL) = 60Pips & yH = 142,219 & StartBreakRangePercent = 20%
    //      means we set the NewSL below the Highest - 2 pips (yH -2)
    //      142,219 + (60Pips x 20%) = 142,219 + 12Pips = 142,339 JPY
    
    // Gc : the idea is to put a First Stop Loss 2 pips down then the highest value of the range
    //      before the BreakEven level
    
    // Hc : Initialization of the First Stop Loss, We assume that the box will be broken
    //      and that the break is real, so in this case we put a stop loss at 10%
    //      below the highest of the Tokyo Box
    
    // Jc : if we lost more then MaxLostPerDay € (exemple 10€) per day, we Can Not buy more,
    //      fees not include
    
    // Kc : We memorise the last count to position to compair to the one of today
    
    // Mc : we set the SL to BE level + Fees (I have to chek fees for all position) when the price
    //      reach a RR of 5, we let the trade breath
    
    // Tc : Time Conditions, we bay only after Tokyo Box (A) and before 8Pm for all the day of week
    //      exept the Day 5 = Friday we stop at 5Pm
    
    // Lc : Long signal if we Close > the Tokyo Box and we are in TimeCondition (Tc)
    
    
    // ################# Idea to be developed and questions #################
    
    // Z1 : I have to find a better solutoion the the Close option
    
    // Z2 : better to control the value of this variable : MaxBuyPerDay by the money
    //      we can lose in 1 days, So I have to count my Profit per day
    
    // Z3 : I noticed when the Buy and Sell order is in the same candle so the CountOfPurchase
    //      still the same and it's not incremented with +1
                                                
    // Z5 : I have to finish this DST and Winter works
    
    // Z6 : I add this code : "Sell CountOfPosition Shares AT FirstSL STOP" for exeit from position
    //      when my countofposition is more the 1, I noticed the code : "SET STOP PRICE FirstSL" not
    //      working is my position is more then 1 but the same code working with
    //      the : "SET STOP PRICE BreakRangeLevel"
    // Z6 : I submit this line (as in but interrogations on the execution of the SL)
    //      that this line does not expect the Close to be off the SL to get me out, but it
    //      is a tick by tick execution
    
    // Z7 : if last day we win some money, we can allocate part of these gains to future trades,
    //      which will allow us to take more positions for example (N > 1)
    
    // Z8 : je doit faire une verification des ordre exécuté l'un avant lautre
    // #################      Explanation of the code       #################
    
    // Code : (CountOfPosition = LastDayCountOfPosition OR Not OnMarket)
    //        - IF I'm on market I have to compare LastDayCountOfPosition like that I can't
    //        buy more if my Long condition = 1
    //        - IF my LastDayCountOfPosition so I can't compare, that is why I use OR Not OnMarket
    
    
    // ################# Last programming where I stopped at #################
    // problem of entry is ok with the new code : "LastDayCountOfPosition = 0",
    // I get a new problem, if the price don't CLose the yH so my FirstSL is not working, it have the same value of the last Tokyyo Box yH[1]-10%, exemple in M5 Date 25/04 at 17:52
    
    // I have to take a look to the order of SET STOP PRICE, in my case : bcause of the BE Range is below the BELevel, so in this case the BELevel it's not executed
    

    tks you

    JC_Bywan thanked this post
    Capture-decran-2023-04-30-a-14.18.19.png Capture-decran-2023-04-30-a-14.18.19.png
    #213907 quote
    phoentzs
    Participant
    Master

    I think they overcomplicate a lot and if in doubt the code is over optimized. Have you tried running the code for at least several months? What does the back test look like?

    ZeroCafeine thanked this post
Viewing 15 posts - 61 through 75 (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...