Hi all. I’ve had a serious problem this morning with the previous version of the code. It sold at 08:05 as it should have and I got stopped out (again as it should have). The problem seems to be when I was stopped out the order was partially executed. I’ve had this problem with other systems I have been working on. When there is a partial executed order, the amount that is partially executed is either bought or sold again. I hope I’m making sense. See the screen shot attached. You can see the order tickets:
08:05:02: executed -5 Dax (@ 11,679.0)
08:05:16: SL : partially executed +4 Dax (@ 11,683.50)
08:05:16: SL : fully executed +1 Dax (@11,684.00)
08:05:18: executed +4 Dax (@11,684.00)
Result is that I have a naked long 4 position (shame as I would have made good money).
Can anyone help with this problem? Has anyone seen it before? The version of the code I’m using is below. Thanks everyone
// Definition of parameters
DEFPARAM CumulateOrders = false // No accumulation of orders
// Position is closed at 4:30 p.m., local market time (London).
DEFPARAM FlatAfter =162900
Once ordersize=1
// Start time (calculation at end of 080000 bar)
StartTime = 080500
// Only 1 position per day
EndTime = 080600
// Max orders & risk multiplier
//Margin = 60
//Lottfree = 0
//orderSize = max(1,1+ROUND((strategyprofit-lottfree)/Margin))
//ordersize=min(18,ordersize)
If Ordersize > 11 THEN
Ordersize = 11
Endif
n=1
// Conditions for analysis
If Time >= StartTime and time <= EndTime THEN
If not onmarket then
c1 = open < close-2*pointsize
c2= open > close-1*pointsize
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize/2
ELSIF PositionPerf(1)> 0 THEN
OrderSize =OrderSize+2
Endif
Ordersize=max(Ordersize,1)
// Conditions to enter positions
IF c1 THEN
buy Ordersize*n contract AT close+2 stop
endif
IF c2 THEN
sellshort Ordersize*n contract AT close-1 stop
Endif
Endif
Endif
//Stops & target
SET STOP ploss 4 //5 3
SET TARGET pPROFIT 10 //10 12
Hello,
On the dax, the minimum stop loss is 6
The stop loss trailing is 5
@ Raul. I ran the code you posted yesterday at 3:55pm. Same problem with using ptrailing with the data in July 2014. I attach the two results.
(I’m aware that thinking / code has moved on since then).
Hello jonjon, in your code the problem I see is that the minimum stop loss is 5, at least in my broker. By the way, the error that you say in the backtest the same day of June can be due to that as maximum can do 500 checks tick by tick by backtest. Try to put the backtest from May 1, 2014 until you get to see if t leaves the problem on the same day.
@Raul and @arcane. Thanks for the replies. I’m not signed up to IG. I realise that I will have minimum SLs to work with (these do seem to change by country). As / when I trade through IG then I will have to change the code accordingly. I may be wrong however at the moment my SL level being 4 instead of 5 (or 6) should not explain the error??
I’ve logged it with PRT as well and I’ll let you know what they say.
Hi,
Today in the first bar has happened again the other day, live has opened later due to the first time pull, in the backtest has opened when due and the first bar has been winning, live has opened later and has lost. It is necessary to prove it well, to see if this is common entry because the price changes very fast.
@Roul
Today all trade in loss..total day -25….I’m out for business travel and what is the difference between real and backtest today ? Thanks
with risk manager, Every 1000 euro of profits, adds a contract.
// Definición de los parámetros del código
DEFPARAM CumulateOrders = false // Acumulación de posiciones desactivada
DEFPARAM FlatAfter =173000
HoraEntradaLimite = 093000
HoraInicio = 090000
capital=10000+strategyprofit
n=capital/1000
if n>100 then
n=100
endif
if n<10 then
n=10
endif
if dayofweek=1 then //Monday
daytrading=1
endif
if dayofweek=2 then // Tuesday
daytrading=1
endif
if dayofweek=3 then // Wednesday
daytrading=1
endif
if dayofweek=4 then //Thursday
daytrading=1
endif
if dayofweek=5 then // Friday
daytrading=0
endif
if Time >= HoraInicio and time <= HoraEntradaLimite and daytrading= 1 then
c1 = open < close-2
if not onmarket then
IF c1 THEN
buy n contract AT close + 2 stop
endif
c2= open > close-1
IF c2 THEN
sellshort n contract AT close - 1 stop
endif
endif
endif
SET STOP ptrailing 5
For the strategy, I advise another martingale.
When the program is losing, you increase the position.
This famous martingale is the work of Alembert, French mathematician of the eighteenth century.
In case of loss, the position is increased by one unit, and in case of gain, it is reduced by one unit.
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize+2
The gain is better.
In my race towards madness I decided to re-edit the code.
// Definición de los parámetros del código
DEFPARAM CumulateOrders = false // Acumulación de posiciones desactivada
DEFPARAM FlatAfter =173000
capital=strategyprofit+10000
n=capital/1000
if n>100 then
n=100
endif
if n<10 then
n=10
endif
HoraEntradaLimite = 090600
HoraInicio = 090500
HoraEntradaLimite1 = 091600
HoraInicio1 = 091500
HoraEntradaLimite2 = 093100
HoraInicio2 = 093000
if dayofweek=1 then //Monday
daytrading=1
endif
if dayofweek=2 then // Tuesday
daytrading=1
endif
if dayofweek=3 then // Wednesday
daytrading=1
endif
if dayofweek=4 then //Thursday
daytrading=1
endif
if dayofweek=5 then // Frifay
daytrading=1
endif
if Time >= HoraInicio and time <= HoraEntradaLimite and daytrading= 1 or Time >= HoraInicio1 and time <= HoraEntradaLimite1 and daytrading= 1 or Time >= HoraInicio2 and time <= HoraEntradaLimite2 and daytrading= 1 then
c1 = open < close-2
if not onmarket then
IF c1 THEN
buy n contract AT close+2 stop
endif
c2= open > close-1
IF c2 THEN
sellshort n contract AT close-1 stop
endif
endif
endif
SET STOP ptrailing 5
Hi, just a thought.. If you want a smaller SL that the broker allows- you can try and play around with this code
//========LONG EXIT=======
SL=2
if longonmarket and close-tradeprice(1)<=-pipsize*SL then
sell AT MARKET
endif
//=========SHORT EXIT====
if shortonmarket and close-tradeprice(1)>=pipsize*SL then
exitshort AT MARKET
endif
Hi!
I tried to run it in live in my demo ig acount and it says that minimum 10 stop is allowed for automated strategies and today it made a loss trade with trailing sl at 5. Same strategy with tick backtest says it won that trade……
Regards
Henrik
https://www.prorealcode.com/topic/5-min-mini1e-dax-spread-1/page/13/#post-22445
EricParticipant
Master
off topic i know but worth reading http://www.trade2win.com/boards/spread-betting-cfds/220766-interview-highbury-fx.html
this is a smaller firm than IG and i think and i hope IG have a different way of handling the trades and hedging
but IG is still a market maker and as long they can pass on your wins to someone else (losing) its no problem but if you try to get IG to pay your profits it can be a problem?
dont answer to this here and ruin the thread, start a new topic in general trading in case of any thoughts on this
i dont want to sound negative just try to help
@Raul,
what about putting a fixed profit (eg 5 points) on half of the position and let go the other half of the position with the trailing stop? I suspect that some profits will be locked this way.