ProRealCode - Trading & Coding with ProRealTimeâą
//-------------------------------------------------------------------------
// Code principal : PP4H V1
//-------------------------------------------------------------------------
// Définition des paramÚtres du code
// Cumul des positions désactivé
DEFPARAM CumulateOrders = False
DEFPARAM PRELOADBARS = 100000000
//************************************************************************
//Horaires de trading
// Annule tous les ordres en attente et ferme toutes les positions Ă 0:00, puis empĂȘche toute crĂ©ation d'ordre avant l'heure "FLATBEFORE".
DEFPARAM FLATBEFORE = 090000
// Annule tous les ordres en attente et ferme toutes les positions Ă l'heure "FLATAFTER"
DEFPARAM FLATAFTER = 173000
// EmpĂȘche le systĂšme de placer des ordres pour entrer sur le marchĂ© ou augmenter la taille d'une position avant l'heure spĂ©cifiĂ©e
noEntryBeforeTime = 090500
timeEnterBefore = time >= noEntryBeforeTime
// EmpĂȘche le systĂšme de placer des ordres pour entrer sur le marchĂ© ou augmenter la taille d'une position aprĂšs l'heure spĂ©cifiĂ©e
noEntryAfterTime = 125000
timeEnterAfter = time < noEntryAfterTime
// EmpĂȘche le systĂšme de placer de nouveaux ordres sur les jours de la semaine spĂ©cifiĂ©s
daysForbiddenEntry = OpenDayOfWeek = 5 OR OpenDayOfWeek = 0
//************************************************************************
// Calcul Points Pivots 4h
Int = (OpenTime[1] < 010000 AND OpenTime > 010000) OR (OpenTime[1] < 050000 AND OpenTime > 050000) OR (OpenTime[1] < 090000 AND OpenTime > 090000) OR (OpenTime[1] < 130000 AND OpenTime > 130000) OR (OpenTime[1] < 170000 AND OpenTime > 170000) OR (OpenTime[1] < 210000 AND OpenTime > 210000) OR (Openday <> Openday[1] AND DayOfWeek < DayOfWeek[1])
IF (OpenTime Mod 40000 = 10000) OR Int THEN
myLastHigh = myHigh
myLastLow = myLow
myLastClose = Close[1]
myHigh = High
myLow = Low
Premierpassage=0
DebutOpen = Barindex
ELSE
myHigh = Max(myHigh, High)
myLow = Min(myLow, Low)
ENDIF
PP = (myLastHigh + myLastLow + myLastClose) / 3
hh = highest[85](high)
ll = lowest[85](low)
if (hh-ll)<20 then
Rang = 0
else
Rang = 1
Endif
BarresDepuisOpen = Barindex - DebutOpen
HighSinceOpen = highest[BarresDepuisOpen](high)
LowSinceOpen = lowest[BarresDepuisOpen](low)
DiffHighSinceOpen = HighSinceOpen - pp
DiffLowSinceOpen = pp - LowSinceOpen
If DiffHighSinceOpen>25 or DiffLowSinceOpen>25 then
Rang2 = 1
else
Rang2 = 0
Endif
// Conditions pour ouvrir une position acheteuse
c1 = (close[1] CROSSES UNDER pp)
IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang and Rang2 THEN
BUY 1 CONTRACT AT MARKET
Premierpassage=1
SET STOP pLOSS 60
ENDIF
// Conditions pour ouvrir une position en vente à découvert
c2 = (close[1] CROSSES OVER pp)
IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang and Rang2 THEN
SELLSHORT 1 CONTRACT AT MARKET
Premierpassage=1
SET STOP pLOSS 50
ENDIF
If time>=090500 and time<=125000 then
If Premierpassage=0 and c1 or c2 then
Premierpassage=1
endif
Endif
//************************************************************************
//trailing stop function
trailingstartL = 21 //LONG trailing will start @trailinstart points profit
trailingstartS = 21 //SHORT trailing will start @trailinstart points profit
trailingstep = 11 //trailing step to move the "stoploss"
breakeven = 0 //Activate or not the Brakeven
breakevenlevel = 15 //Level of activation of the breakeven
PointsToKeepBreakeven = 1
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
BreakevenStop=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
If Breakeven and BreakevenStop=0 then
IF close-tradeprice(1)>=breakevenlevel*pipsize THEN
BreakevenStop = tradeprice(1) + PointsToKeepBreakeven
Endif
Endif
//first move trailing stop
IF newSL=0 AND close-tradeprice(1)>=trailingstartL*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
If Breakeven and BreakevenStop=0 then
IF tradeprice(1)-close>=breakevenlevel*pipsize THEN
BreakevenStop = tradeprice(1) - PointsToKeepBreakeven
Endif
Endif
//first move trailing stop
IF newSL=0 AND tradeprice(1)-close>=trailingstartS*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions with trailing stop
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//stop order to exit the positions with breakeven
IF BreakevenStop>0 THEN
SELL AT BreakevenStop STOP
EXITSHORT AT BreakevenStop STOP
ENDIF
//************************************************************************
HighSinceOpen = highest[max(1,BarresDepuisOpen)](high)
LowSinceOpen = lowest[max(1,BarresDepuisOpen)](low)
because the first time BarresDepuisOpen retains 0.
//-------------------------------------------------------------------------
// Code principal : PP4H V1
//-------------------------------------------------------------------------
// Définition des paramÚtres du code
// Cumul des positions désactivé
DEFPARAM CumulateOrders = False
DEFPARAM PRELOADBARS = 100000000
//************************************************************************
//Horaires de trading
// Annule tous les ordres en attente et ferme toutes les positions Ă 0:00, puis empĂȘche toute crĂ©ation d'ordre avant l'heure "FLATBEFORE".
DEFPARAM FLATBEFORE = 090000
// Annule tous les ordres en attente et ferme toutes les positions Ă l'heure "FLATAFTER"
DEFPARAM FLATAFTER = 173000
// EmpĂȘche le systĂšme de placer des ordres pour entrer sur le marchĂ© ou augmenter la taille d'une position avant l'heure spĂ©cifiĂ©e
noEntryBeforeTime = 090500
timeEnterBefore = time >= noEntryBeforeTime
// EmpĂȘche le systĂšme de placer des ordres pour entrer sur le marchĂ© ou augmenter la taille d'une position aprĂšs l'heure spĂ©cifiĂ©e
noEntryAfterTime = 125000
timeEnterAfter = time < noEntryAfterTime
// EmpĂȘche le systĂšme de placer de nouveaux ordres sur les jours de la semaine spĂ©cifiĂ©s
daysForbiddenEntry = OpenDayOfWeek = 5 OR OpenDayOfWeek = 0
//************************************************************************
// Calcul Points Pivots 4h
Int = (OpenTime[1] < 010000 AND OpenTime > 010000) OR (OpenTime[1] < 050000 AND OpenTime > 050000) OR (OpenTime[1] < 090000 AND OpenTime > 090000) OR (OpenTime[1] < 130000 AND OpenTime > 130000) OR (OpenTime[1] < 170000 AND OpenTime > 170000) OR (OpenTime[1] < 210000 AND OpenTime > 210000) OR (Openday <> Openday[1] AND DayOfWeek < DayOfWeek[1])
IF (OpenTime Mod 40000 = 10000) OR Int THEN
myLastHigh = myHigh
myLastLow = myLow
myLastClose = Close[1]
myHigh = High
myLow = Low
Premierpassage=0
DebutOpen = Barindex
ELSE
myHigh = Max(myHigh, High)
myLow = Min(myLow, Low)
ENDIF
PP = (myLastHigh + myLastLow + myLastClose) / 3
hh = highest[85](high)
ll = lowest[85](low)
if (hh-ll)<20 then
Rang = 0
else
Rang = 1
Endif
BarresDepuisOpen = Barindex - DebutOpen
HighSinceOpen = highest[BarresDepuisOpen](high)
LowSinceOpen = lowest[BarresDepuisOpen](low)
DiffHighSinceOpen = HighSinceOpen - pp
DiffLowSinceOpen = pp - LowSinceOpen
If DiffHighSinceOpen>25 or DiffLowSinceOpen>25 then
Rang2 = 1
else
Rang2 = 0
Endif
// Conditions pour ouvrir une position acheteuse
c1 = (close[1] CROSSES UNDER pp)
IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang and Rang2 THEN
BUY 1 CONTRACT AT MARKET
Premierpassage=1
SET STOP pLOSS 60
ENDIF
// Conditions pour ouvrir une position en vente à découvert
c2 = (close[1] CROSSES OVER pp)
IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang and Rang2 THEN
SELLSHORT 1 CONTRACT AT MARKET
Premierpassage=1
SET STOP pLOSS 50
ENDIF
If time>=090500 and time<=125000 then
If Premierpassage=0 and c1 or c2 then
Premierpassage=1
endif
Endif
//************************************************************************
//trailing stop function
trailingstartL = 21 //LONG trailing will start @trailinstart points profit
trailingstartS = 21 //SHORT trailing will start @trailinstart points profit
trailingstep = 11 //trailing step to move the "stoploss"
mybreakeven = 0 //Activate or not the Brakeven
breakevenlevel = 15 //Level of activation of the breakeven
PointsToKeepBreakeven = 1
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
BreakevenStop=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
If mybreakeven and BreakevenStop=0 then
IF close-tradeprice(1)>=breakevenlevel*pipsize THEN
BreakevenStop = tradeprice(1) + PointsToKeepBreakeven
Endif
Endif
//first move trailing stop
IF newSL=0 AND close-tradeprice(1)>=trailingstartL*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
If mybreakeven and BreakevenStop=0 then
IF tradeprice(1)-close>=breakevenlevel*pipsize THEN
BreakevenStop = tradeprice(1) - PointsToKeepBreakeven
Endif
Endif
//first move trailing stop
IF newSL=0 AND tradeprice(1)-close>=trailingstartS*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions with trailing stop
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//stop order to exit the positions with breakeven
IF BreakevenStop>0 THEN
SELL AT BreakevenStop STOP
EXITSHORT AT BreakevenStop STOP
ENDIF
//************************************************************************
timeframe(4h, updateonclose)
Cbuy, Csell =Call "JM INDICATOR V0.1"
ONCE periodFirstMA = 6
ONCE periodSecondMA = 10
ONCE periodThirdMA = 4
// filter parameter
ONCE periodLongMA = 160
ONCE periodShortMA = 40
ONCE lastweekbarindex =0
once lastmonthbarindex = 0
// calculate daily high/low
dailyHigh = DHigh(1)
dailyLow = DLow(1)
// calculate weekly high/low
If DayOfWeek < DayOfWeek[1] and barindex > 0 then
weeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)
lastWeekBarIndex = BarIndex
ENDIF
// calculate monthly high/low
If Month <> Month[1] and barindex > 0 then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
lastMonthBarIndex = BarIndex
ENDIF
// calculate signalline with multiple smoothed averages
firstMA = WilderAverage[periodFirstMA](close)
secondMA = TimeSeriesAverage[periodSecondMA](firstMA)
signalline = TimeSeriesAverage[periodThirdMA](secondMA)
// filter criteria because not every breakout is profitable
c1 = close > Average[periodLongMA](close)
c2 = close < Average[periodLongMA](close) c3 = close > Average[periodShortMA](close)
c4 = close < Average[periodShortMA](close)
// long position conditions
l1 = signalline CROSSES OVER monthlyHigh
l2 = signalline CROSSES OVER weeklyHigh
l3 = signalline CROSSES OVER dailyHigh
l4 = signalline CROSSES OVER monthlyLow
// short position conditions
s1 = signalline CROSSES UNDER monthlyHigh
s2 = signalline CROSSES UNDER monthlyLow
s3 = signalline CROSSES UNDER dailyLow
CondAchat = ((l1) OR (l4) OR (l2)OR (l3 AND c2))
CondVente= ((s2 AND c4) OR (s3 AND c1))
RETURN CondAchat, CondVente
Hi,
I tried the indicator, and I don’t get an error message (also not on Monday) and the indicator gives buy and sell signals…?
Hi,
That’s right, I hadn’t read everything yet… đ
I personally think that error message is due to the “Crosses Over” and “Crosses Under”…
Perhaps it would be better to use “greater than (>) ” and “smaller than (<)” here…
(remark: there is no WeeklyLow in the code…?)Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTimeâą indicator, screener or system for you.
Error indicator negative entry or zero parameter
This topic contains 17 replies,
has 4 voices, and was last updated by
robertogozzi
3 years, 1 month ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 03/10/2021 |
| Status: | Active |
| Attachments: | 1 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.