Strategyprofit again
Maybe the question is already answered and someone can answer me with a link to it?
Question is.
Every trade I win should increase my capital in 1%.
If I lose a trade, the next trade should increase my capital by a total of 2%. If I lose the next trade, the next trade should increase my capital by a total of 3%, and so on until I win a trade. If this is the 4th trade that wins, I then have 104% capital and this should then be set to 100% capital and game starts again.
So far so good and for the cracks here certainly no problem.
But now, how does it look if I work with a fixed TakeProfit from trade with 1.5% and only with a time stop?
Here now the quite simple strategy in which the Strategy-Proft problem could be integrated.
//-------------------------------------------------------
// late noon trade
// instrument dax40
// timezone europe, berlin
// timeframe 30m
// created and coded by JohnScher
//-------------------------------------------------------
defparam cumulateorders = false
defparam flatafter = 213000
once ordersize = 1
td = opendayofweek >= 1 and opendayofweek <= 6
tt = time = 133000
c = close > exponentialaverage [6] (close)
if td and tt and c then
buy ordersize contracts at market
endif
set target %profit 1.5
pls can anyone help?
see attached the itf-file
What is the starting Capital you want to use for 1 lot?
Well, hi, Roberto.
Currently, unfortunately, I do not have so much time for PRT. I am sorry that I can only answer today. So here let´s go.
Starting Capital = 10.000
One addition/change perhaps still.
Since the TakeProfit is not reached every time because of the TimeStop, this would have to be taken into account.
Means therefore
If a trade is won with 50 points after time stop ,
New Startcapital= 10.050 = 100.5%
This NewCapital is then set to 100% for the further calculations
NewStartcapital = 10,050 = 100%
(Starting Capital = 10.000 = 100%
Gain after TimeStop = +50 pointsize
New Startcapital = 10.050 = 100%)
If a trade is lost, the next trade should reach the target of 1.5% calculated from the all-time high of the starting capital.
Therefore, the correct stake size must be calculated in order to achieve the take profit of the StartingCapital of 1.5% + all-time high from Starting Capital when the take profit of the trade is reached.
Example
oldStartCapital = 10.000
Profit trade = +50 points
newStartCapital = 10.050
next Trade = Losstrade =-100 points
newStartCapital= 9.950
Calculate the postionsize if reach the TakeProfit of the trade = 1.5% of the price = reach the TakeProfit of the all time high of the starting capital (= 10,050 ) +1% of the starting capital.
the target new starting capital would be 10.050 + 10.050*0,01 = 10.150,5
It is complicated. Do you understand what I mean?
If it’s unclear, please write back, we can do it piece by piece
There you go:
//-------------------------------------------------------
// late noon trade
// instrument dax40
// timezone europe, berlin
// timeframe 30m
// created and coded by JohnScher
//-------------------------------------------------------
defparam cumulateorders = false
//defparam flatafter = 213000
once Capital = 10000
once Equity = Capital
once SizeRatio = 1
once MinSize = 1 //minimum lot size allowed (it can be lower, if the broker allows decimals)
once PipGain = 50 * PipSize
once CapitalInc = Capital / 200 //0.5% increase
once ordersize = Equity * SizeRatio / Capital
once TradeLost = 0
IF TradeLost = 0 THEN
IF Time >= 213000 THEN
SELL AT Market
ENDIF
ENDIF
td = opendayofweek >= 1 and opendayofweek <= 6
tt = time = 133000
c = close > exponentialaverage[6](close)
myProfit = (StrategyProfit - StrategyProfit[1]) / PipValue
IF myProfit > 0 THEN
TradeLost = 0
ENDIF
IF myProfit >= PipGain THEN
Equity = Equity + CapitalInc
ordersize = Equity * SizeRatio / Capital
ELSIF myProfit < 0 THEN
TradeLost = 1
Equity = Equity + (myProfit * PipValue)
ENDIF
MaxEquity = max(MaxEquity,Equity) //not sure about the ALL-time highest Equity and 1.5%
if td and tt and c then
LotSize = max(MinSize,floor(ordersize,2))
buy LotSize contracts at market
endif
set target %profit 1.5
//graph TradeLost
//graph myProfit >= PipGain coloured("Red")
//graph OrderSize
I couldn’t fully understand the 1.5% and the all-time highest capital requirements, so I did not add them. Can you explain better with some examples?
Hello Roberto.
Thank you very much for your work.
I would also like to take this opportunity to say a big thank you for standing by me and helping me so many times. Thank you!
Once again for understanding. I try to express myself better.
It should apply in general to all strategies and be examined on the example of the late-noon-trade.
We have a time-based stop. This means we do not always reach the specified StopLoss and TargetProfit.
Nevertheless, we have SL and TP.
Let’s program the FinanceMangement, piece by piece.
We start from the initial capital of 10,000 euros.
Step 1
We win a trade.
Now the (new) starting capital should be = 10.000 Euro + the profit from the last trade.
Simple?
Send it back as a code.
oki?
I am attaching the new version according to yourlast request.
Thank you very much for your work.
I didn't get around to looking at it sooner, I was on the way on other battlefields. I'm sorry, I should appreciate your work even more.
If you want to answer that, please take your time. The strategy is important for all my systems to check. There is no rush, it does not depend on one day or the other.
Better let's talk so we don't talk past each other.
What I saw above doesn't quite match what I want. I probably didn't express myself correctly (the sender is responsible for the receiver understanding the signals)
So, I want to try again, using the late noon trade as an example.
Starting capital = 10.000 = 100%
We start a 1st trade.
The goal is a 1% profit from the starting capital - if the TakeProfits of the trade (!) (=1.5% of the index level) is reached.
Because of the TimeStop, the trade will not always end in the SL or TP, of course.
Therefore we act as follows.
If the new starting capital is greater than the old (first) starting capital after the first trade, the (new) starting capital becomes the old starting capital.
If after the 2nd trade the new starting capital is greater than the previous starting capital, the new starting capital becomes the old starting capital and so one .... so far, so clear.
And now the problem, it's going a bit in the direction of Martingale.
If the new starting capital is smaller than the old starting capital after the 1st trade, we want to calculate how large our positons (possibiliy in fractions) is so that we receive this 1% profit from the (old) starting capital
As long as the following trades are lost, I would like to keep recalculating how many positions (possibly in fractions) I have to trade in order to reach this 1% of the (first - later from the old) starting capital.
We do this everry until the new starting capital has finally reached 101% of the old starting capital after (many) lost trades.
Difficult Birth. I hope you understand... im sorry, ask me
I put your algo live. One trade so far, one winner but unfortunately no further trades although one appears every day in the backtest ??? It makes me doubt that there are live problems ??
I could not yet deal with Roberto’s changes, so many things are also to do. A big thanks to Roberto who works tirelessly like a machine.
The original trade approach runs live with me. ordersize halfpoint for control purposes. No problems. The same almost like in demo.
Hello Roberto
or maybe someone else can help.
I have simplified the code and changed onetime. Because it is not about maximization. He looks like this now.
//-------------------------------------------------------
// late noon trade
// instrument dax40
// timezone europe, berlin
// timeframe 30m
// created and coded by JohnScher
//-------------------------------------------------------
defparam cumulateorders = false
defparam flatafter = 213000
once Capital = 10000
once Equity = Capital
once CapitalInc = Equitiy / 200 //0.5% increase
once ordersize = 1
once TradeLost = 0
td = opendayofweek >= 1 and opendayofweek <= 6
tt = time = 133000
c = close > exponentialaverage[6](close)
myProfit = (StrategyProfit - StrategyProfit[1]) / PipValue
IF myProfit > 0 THEN
TradeLost = 0
Equity = Equity + myProfit
ELSIF myProfit < 0 THEN
TradeLost = 1
ENDIF
if td and tt and c then
If tradelost = 0 then
lotsize = ordersize
Elsif tradelost = 1 then
Lotsize = ??????????????? // here is the problem
buy LotSize contracts at market
Endif
Endif
set target %profit 1.5
The intended calculation of the order size seems clearer now.
If the last trade was won, the order size = 1.
If the last trade was lost, the order size should be calculated in such a way,
that the TakeProfit of the trade = 1.5% and when this TakeProfit is reached, the new Eqitity should be Equitiy[1] + Capitalincr*pipsize.
Can the code be created for this?
hello Roberto
do you already have a plan for John’s problem, would also be very interested to find out how it works????
Actually I don’t know what to do, I can’t find any calculation method when a trade is lost. How can 1.5% TP be reached if the trade was lost?
How can 1.5% TP be reached if the trade was lost?
For the next trade to come.
My problem was that there was only one trade and nothing happened for weeks (several trades were displayed in the backtest for the period), I closed it yesterday at PRT and immediately restarted it and today there was another trade that was still there is running, I’m curious what happens and if it starts trading again ??