Hi, Please can somebody point me in the right direction, I would like code to pause the system till next open when a loss is booked after a stoploss is hit, Thanks.
There you go:
Once TradeON = 1
If TradeON = 0 then
TradeON = 1
Endif
If StrategyProfit < StrategyProfit[1] then
TradeON = 0
Endif
.
.
If MyLongConditions and TradeON Then
Buy 1 Contract at Market
Endif
.
.
If MyShortConditions and TradeON Then
Buy 1 Contract at Market
Endif
.
.
Hi Robert,
I made an attempt at inserting the code but it is not performing as expected still multiple losses on same day. D2 is the original equity curve before code was inserted please take a look at the code thanks.
// M5
// SPREAD 1.5
// by BALMORA 74 – FEBRUARY 2019
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
//VARIABLES
CtimeA = time >= 080000 and time <= 180000
CtimeB = time >= 080000 and time <= 180000
// TAILLE DES POSITIONS
ONCE PositionSizeLong = 1
ONCE PositionSizeShort = 1
//STRATEGIE
//VECTEUR = CALCUL DE L’ANGLE
ONCE PeriodeA = 10
ONCE nbChandelierA= 15
MMA = Exponentialaverage[PeriodeA](close)
ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierA
ANGLE = (ATAN(ADJASUROPPO)) //FONCTION ARC TANGENTE
CondBuy1 = ANGLE >= 45
CondSell1 = ANGLE <= – 37
//VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILE
ONCE PeriodeB = 20
ONCE nbChandelierB = 35
lag = 5
MMB = Exponentialaverage[PeriodeB](close)
pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB
trigger = Exponentialaverage[PeriodeB+lag](pente)
CondBuy2 = (pente > trigger) AND (pente < 0)
CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)
Once TradeON = 1
If TradeON = 0 then
TradeON = 1
Endif
If StrategyProfit < StrategyProfit[1] then
TradeON = 0
Endif
If condbuy and TradeON Then
Buy 1 Contract at Market
Endif
If condsell and TradeON Then
Buy 1 Contract at Market
Endif
//ENTREES EN POSITION
CONDBUY = CondBuy1 and CondBuy2 and CTimeA
CONDSELL = CondSell1 and CondSell2 and CtimeB
//POSITION LONGUE
IF CONDBUY THEN
buy PositionSizeLong contract at market
SET STOP %LOSS 1.3
SET STOP pLOSS 80
ENDIF
//POSITION COURTE
IF CONDSELL THEN
Sellshort PositionSizeShort contract at market
SET STOP %LOSS 1.3
SET STOP pLOSS 80
ENDIF
//VARIABLES STOP SUIVEUR
ONCE trailingStopType = 1 // Trailing Stop – 0 OFF, 1 ON
ONCE trailingstoplong = 4 // Trailing Stop Atr Relative Distance
ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance
ONCE atrtrailingperiod = 14 // Atr parameter Value
ONCE minstop = 0 // Minimum Trailing Stop Distance
// TRAILINGSTOP
//———————————————-
atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000
trailingstartl = round(atrtrail*trailingstoplong)
trailingstartS = round(atrtrail*trailingstopshort)
if trailingStopType = 1 THEN
TGL =trailingstartl
TGS=trailingstarts
if not onmarket then
MAXPRICE = 0
MINPRICE = close
PREZZOUSCITA = 0
ENDIF
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close)
if MAXPRICE-tradeprice(1)>=TGL*pointsize then
if MAXPRICE-tradeprice(1)>=MINSTOP then
PREZZOUSCITA = MAXPRICE-TGL*pointsize
ELSE
PREZZOUSCITA = MAXPRICE – MINSTOP*pointsize
ENDIF
ENDIF
ENDIF
if shortonmarket then
MINPRICE = MIN(MINPRICE,close)
if tradeprice(1)-MINPRICE>=TGS*pointsize then
if tradeprice(1)-MINPRICE>=MINSTOP then
PREZZOUSCITA = MINPRICE+TGS*pointsize
ELSE
PREZZOUSCITA = MINPRICE + MINSTOP*pointsize
ENDIF
IF ONMARKET AND DAYOFWEEK=5 AND TIME>=210000 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
ENDIF
ENDIF
if onmarket and PREZZOUSCITA>0 then
EXITSHORT AT PREZZOUSCITA STOP
SELL AT PREZZOUSCITA STOP
ENDIF
ENDIF
You asked to wait 1 bar, that’s what it’s doing.
If you want to pause the whole day then replace line 2 of my code with
If IntraDayBarIndex = 0 then
Please, always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
// ROBOT VECTORIAL DAX
// M5
// SPREAD 1.5
// by BALMORA 74 - FEBRUARY 2019
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
//VARIABLES
CtimeA = time >= 080000 and time <= 180000
CtimeB = time >= 080000 and time <= 180000
// TAILLE DES POSITIONS
ONCE PositionSizeLong = 1
ONCE PositionSizeShort = 1
//STRATEGIE
//VECTEUR = CALCUL DE L'ANGLE
ONCE PeriodeA = 10
ONCE nbChandelierA= 15
MMA = Exponentialaverage[PeriodeA](close)
ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierA
ANGLE = (ATAN(ADJASUROPPO)) //FONCTION ARC TANGENTE
CondBuy1 = ANGLE >= 45
CondSell1 = ANGLE <= - 37
//VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILE
ONCE PeriodeB = 20
ONCE nbChandelierB = 35
lag = 5
MMB = Exponentialaverage[PeriodeB](close)
pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB
trigger = Exponentialaverage[PeriodeB+lag](pente)
CondBuy2 = (pente > trigger) AND (pente < 0)
CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)
Once TradeON = 1
IF IntraDayBarIndex = 0 THEN
TradeON = 1
Endif
If StrategyProfit < StrategyProfit[1] then
TradeON = 0
Endif
If CONDBUY and TradeON Then
Buy 1 Contract at Market
Endif
If CONDSELL and TradeON Then
Buy 1 Contract at Market
Endif
//ENTREES EN POSITION
CONDBUY = CondBuy1 and CondBuy2 and CTimeA and TradeON
CONDSELL = CondSell1 and CondSell2 and CtimeB and TradeON
//POSITION LONGUE
IF CONDBUY THEN
buy PositionSizeLong contract at market
SET STOP %LOSS 1.3
SET STOP pLOSS 80
ENDIF
//POSITION COURTE
IF CONDSELL THEN
Sellshort PositionSizeShort contract at market
SET STOP %LOSS 1.3
SET STOP pLOSS 80
ENDIF
//VARIABLES STOP SUIVEUR
ONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ON
ONCE trailingstoplong = 4 // Trailing Stop Atr Relative Distance
ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance
ONCE atrtrailingperiod = 14 // Atr parameter Value
ONCE minstop = 0 // Minimum Trailing Stop Distance
// TRAILINGSTOP
//----------------------------------------------
atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000
trailingstartl = round(atrtrail*trailingstoplong)
trailingstartS = round(atrtrail*trailingstopshort)
if trailingStopType = 1 THEN
TGL =trailingstartl
TGS=trailingstarts
if not onmarket then
MAXPRICE = 0
MINPRICE = close
PREZZOUSCITA = 0
ENDIF
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close)
if MAXPRICE-tradeprice(1)>=TGL*pointsize then
if MAXPRICE-tradeprice(1)>=MINSTOP then
PREZZOUSCITA = MAXPRICE-TGL*pointsize
ELSE
PREZZOUSCITA = MAXPRICE - MINSTOP*pointsize
ENDIF
ENDIF
ENDIF
if shortonmarket then
MINPRICE = MIN(MINPRICE,close)
if tradeprice(1)-MINPRICE>=TGS*pointsize then
if tradeprice(1)-MINPRICE>=MINSTOP then
PREZZOUSCITA = MINPRICE+TGS*pointsize
ELSE
PREZZOUSCITA = MINPRICE + MINSTOP*pointsize
ENDIF
IF ONMARKET AND DAYOFWEEK=5 AND TIME>=210000 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
ENDIF
ENDIF
if onmarket and PREZZOUSCITA>0 then
EXITSHORT AT PREZZOUSCITA STOP
SELL AT PREZZOUSCITA STOP
ENDIF
ENDIF
Hi Robert, Thanks I made the suggested replacement and I am still getting subsequent trades opening that day, thanks for your help.
You did not add TradeON to your conditions (line 10 and 15 in my code).
Add it to your lines 67 and 75.
My first code was made to wait ONE bar, while my next suggestions was to wait ONE day (till new day opens).
The code still dont work.
It’s beacause STRATEGYPROFIT (like ONMARKET, etc…) take a bar to be able to update its status, so when you do Stop & Reverse ProOrder can’t know whether there was a gain or a loss.
To achieve the correct result you should add
and Not OnMarket
to your conditions to enter a trade.
In case you want to do Stop & Reverse you need to take note of that and accept that you will probably suffer TWO losses before there’s a temporary stop.
At line 52 and 57 you always use BUY both for long and short conditions, is that intentional?
Ok Roberto, el código es bueno, thanks.
But, other problem.
If cumulateórders = true, the Code no function.
If you use and Not OnMarket it will not work!