ProRealCode - Trading & Coding with ProRealTime™
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?? 🙂
I will try to share a scheme tonight, it will be more clear 😊
I’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
@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
What does your backtest look like over 200,000 bars? Just for expressiveness. 😉
Ok, 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
That sounds a bit like a gimmick…
@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
That 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 😁
Well Done Mr Decaff … and all with zero caffeine!! 😉
Just 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
Let’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 more
I 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
// 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 = 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 DrawDownQuit = 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 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
//#******************************************************************#
//# FonctionS #
//#******************************************************************#
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
MyLastDayProfit = StrategyProfit // Unit : JPY
LastDayCountOfPosition = CountOfPosition // Kc
ENDIF
MyJPYDayProfit = StrategyProfit - MyLastDayProfit // Unit : JPY
MyEuroDayProfit = MyJPYDayProfit / Medianprice // Unit : €
DayLostCondition = MyEuroDayProfit > MaxLostPerDay*(-1) // Jc & Z7
// Ex : (-300JPY/143) > 10€ x -1 ==> -2,10€ > -10€ => Boolen = True / -15€ > -10€ => False
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
OldFirstSL = FirstSL
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) AND ((((Close - FirstSL)*100) / pipsize) / MedianPrice < MaxLostPerDay)
IF LongSignalAllCondition 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 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-OldFirstSL))
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
yHplusFirstSL = 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"
ENDIF
IF 1 THEN
LosingPerTrade = (((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 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
//#******************************************************************#
//# 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 #
//#******************************************************************#
//
Here 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 :
// 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 = 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 DrawDownQuit = 0 // 1 on - 0 off // Needs to be improved
Once MaxLostPerMonth= 100// if we Lost about 100€ per month we stop Strategy
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 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
//#******************************************************************#
//# FonctionS #
//#******************************************************************#
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
LastStrategyProfit = StrategyProfit // Unit : JPY
LastDayCountOfPosition = CountOfPosition // Kc
ENDIF
IF 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ée
ENDIF
DayProfitJPY = StrategyProfit - LastStrategyProfit // Unit : JPY
DayProfitEuro = DayProfitJPY / Medianprice // Unit : €
DayLostCondition = DayProfitEuro > MaxLostPerDay*(-1) // Jc & Z7
// Ex : (-300JPY/143) > 10€ x -1 ==> -2,10€ > -10€ => Boolen = True / -15€ > -10€ => False
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
LastFirstSL = FirstSL
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) //AND ((((Close - FirstSL)*100) / pipsize) / MedianPrice < MaxLostPerDay)
IF LongSignalAllCondition 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 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
IF Day = 1 THEN
MondayProfit = DayProfitEuro
ELSIF Day = 2 THEN
TuesdayProfit = DayProfitEuro
ELSIF Day = 3 THEN
WednesdayProfit = DayProfitEuro
ELSIF Day = 4 THEN
ThursdayProfit = DayProfitEuro
ELSIF Day = 5 THEN
FridayProfit = DayProfitEuro
ELSIF Day = 7 THEN
MondayProfit = 0
TuesdayProfit = 0
WednesdayProfit = 0
ThursdayProfit = 0
FridayProfit = 0
ENDIF
//#******************************************************************#
//# Graph #
//#******************************************************************#
// Blue Azur (0, 127, 255) & Maya (115, 194, 251)
// Green Sinople (20, 148, 20) &
IF 0 THEN
yHplusFirstSL = 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"
ENDIF
IF 0 THEN
LosingPerTrade = (((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"
ENDIF
IF 1 THEN
Graph 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 // Nc
if (StrategyProfit / MedianPrice) < MaxLostPerMonth*(-1) then
Quit
endif
ENDIF
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
//#******************************************************************#
//# 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 #
//#******************************************************************#
//
200000 bars? Or at least 10000bars as a report?
I 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 😊
End Of Day – YEN M15 Strategy
This topic contains 95 replies,
has 8 voices, and was last updated by ZeroCafeine
2 years, 9 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 03/24/2023 |
| Status: | Active |
| Attachments: | 39 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.