ProRealCode - Trading & Coding with ProRealTime™
Hi.
This looks intressting
How do I use the optimizer to backtest and find the best entry with this indicator.
Hi!
You could create a new variable called “type” (for example) and introduce in conditions to take a long position:
Here you have an example with 4 variations. Your code has a lot of types…
//---Doji: type1
DojiSize = 0.05
data=(abs(open - close) <= (high - low) * DojiSize)
if type=1 and data then
buy 1 contract at market
endif
//---MorningStar: type 2
MorningStar=(body[2]<0 and body>0 and longcandle[2] and open[1]<close[2] and open>close[1] and ratio[1]<0.3 and abody[1]<abody[2] and abody[1]<abody and low[1]<low and low[1]<low[2] and high[1]<open[2] and high[1]<close)
if type=2 and TrendDown[3] AND MorningStar then
buy 1 contract at market
endif
//---PiercingLine: type 3
PiercingLine=(body[1]<0 and body>0 and longcandle[1] and longcandle and open<low[1] and close>Pmiddle[1] and close<open[1])
if type=3 and TrendDown[2] AND PiercingLine then
buy 1 contract at market
endif
//---AbandonedBabyBottom: type 4
AbandonedBabyBottom=(body[2]<0 and body>0 and longcandle[2] and ratio[1]<0.3 and high[1]<low[2] and high[1]<low)
if type=4 and TrendDown[3] AND AbandonedBabyBottom then
buy 1 contract at market
endif
Thank you Ivan. That helped alot!
I added the variable Signal to tell which pattern is returned and the variable Opt to be used with the optimizer.
The optimizer will pliot the best performing patterns for LONG trades.
Then you will have to uncomment line 487 and comment out line 486 to repeat the optimization for the best performing patterns for SHORT trades.
Here is the code:
// Trend direction identification
//(choose 0=No Trend check, 1=MACD, 2=SAR, 3=Directional Movement, 4=Moving Averages crossing [default], 5=Stochastic)
TDS=4
//text color
// white = 255,255,255 ; black = 0,0,0
r = 0
g = 0
b = 0
atr = averagetruerange[10](close)*0.5
body=close-open
abody=abs(body)
if range>0 then
ratio=abody/range
else
ratio=0
endif
myMiddle=(open+close)/2
if body>0 then
bodytop=close
bodybottom=open
else
bodytop=open
bodybottom=close
endif
//bodytop=max(open, close)
//bodybottom=min(open, close)
shadowtop=high-bodytop
shadowbottom=bodybottom-low
longcandle= (ratio>0.6)
DojiSize = 0.05
data=(abs(open - close) <= (high - low) * DojiSize)
if data then
//DrawText("Doji", barindex, high+atr*0.75, Dialog, Standard, 12) COLOURED(R,G,B)
endif
//Trend Detection
if TDS=0 then
TrendUp=1
TrendDown=1
else
if TDS=1 then
TrendUp=(MACDline[12,26,9](close)>0 AND MACD[12,26,9](close)>0)
TrendDown=(MACDline[12,26,9](close)<0 AND MACD[12,26,9](close)<0)
else
if TDS=2 then
TrendUp=(SAR[0.02,0.02,0.2]<low)
TrendDown=(SAR[0.02,0.02,0.2]>high)
else
if TDS=3 then
TrendUp=(ADX[14]>23 AND DI[14](close)>0)
TrendDown=(ADX[14]>23 AND DI[14](close)<0)
else
if TDS=4 then
TrendUp=(ExponentialAverage[2](close)>ExponentialAverage[4](close))
TrendDown=(ExponentialAverage[2](close)<ExponentialAverage[4](close))
else
if TDS=5 then
TrendUp=(Stochastic[14,3](close)>Average[5](Stochastic[14,3](close)))
TrendDown=(Stochastic[14,3](close)<Average[5](Stochastic[14,3](close)))
endif
endif
endif
endif
endif
endif
Signal = 0
//Bullish Signal
MorningStar=(body[2]<0 and body>0 and longcandle[2] and open[1]<close[2] and open>close[1] and ratio[1]<0.3 and abody[1]<abody[2] and abody[1]<abody and low[1]<low and low[1]<low[2] and high[1]<open[2] and high[1]<close)
if TrendDown[3] AND MorningStar then
Signal = 1
//DrawText("Morning Star", barindex, low[1]-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex-1,low[1]) COLOURED(0,155,10)
endif
PiercingLine=(body[1]<0 and body>0 and longcandle[1] and longcandle and open<low[1] and close>myMiddle[1] and close<open[1])
if TrendDown[2] AND PiercingLine then
Signal = 2
//DrawText("Piercing Line", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
AbandonedBabyBottom=(body[2]<0 and body>0 and longcandle[2] and ratio[1]<0.3 and high[1]<low[2] and high[1]<low)
if TrendDown[3] AND AbandonedBabyBottom then
Signal = 2
//DrawText("Abandoned Baby Bottom", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
ThreeInsideUp=(body[2]<0 and body[1]>0 and body>0 and BullishHarami[1] and close>close[1])
if TrendDown[3] AND ThreeInsideUp then
Signal = 3
//DrawText("Three Inside Up", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
ThreeOutsideUp=(body[2]<0 and body[1]>0 and body>0 and BullishEngulfing[1] and close>close[1])
if TrendDown[3] AND ThreeOutsideUp then
Signal = 4
//DrawText("Three Outside Up", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
ThreeWhiteSoldiers=(body[2]>0 and body[1]>0 and body>0 and high[1]>high[2] and high>high[1] and close[1]>close[2] and close>close[1] and open[1]>open[2] and open[1]<close[2] and open>open[1] and open<close[1])
if TrendDown[3] AND ThreeWhiteSoldiers then
Signal = 5
//DrawText("Three White Soldiers", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
ConcealingBabySwallow=(body[3]<0 and body[2]<0 and body[1]<0 and body<0 and ratio[3]>0.8 and ratio[2]>0.8 and ratio>0.8 and open[1]<close[2] and high[1]>close[2] and shadowtop[1]>0.6*(abody[1]+shadowbottom[1]) and bodybottom<bodybottom[1] and bodytop>high[1])
if TrendDown[4] AND ConcealingBabySwallow then
Signal = 6
//DrawText("Concealing Baby Swallow", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BullishHarami=(body[1]<0 and body>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
if TrendDown[2] AND BullishHarami then
Signal = 7
//DrawText("Bullish Harami", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
HomingPigeon=(body[1]<0 and body<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
if TrendDown[2] AND HomingPigeon then
Signal = 8
//DrawText("Homing Pigeon", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BullishEngulfing=(body[1]<0 and body>0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
if TrendDown[2] AND BullishEngulfing then
Signal = 9
//DrawText("Bullish Engulfing", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
LastEngulfingBottom=(body[1]>0 and body<0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
if TrendDown[2] AND LastEngulfingBottom then
Signal = 10
//DrawText("Last Engulfing Bottom", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
DragonflyDojiBottom=(body[1]<0 and longcandle[1] and low<low[1] and shadowbottom>3*abody and shadowtop<shadowbottom/3)
if TrendDown[2] AND DragonflyDojiBottom then
Signal = 11
//DrawText("Dragonfly Doji", barindex, low-atr, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
GravestoneDojiBottom=(body[1]<0 and longcandle[1] and low<low[1] and shadowtop>3*abody and shadowbottom<shadowtop/3)
if TrendDown[2] AND GravestoneDojiBottom then
Signal = 12
//DrawText("Gravestone Doji", barindex, low-atr, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
DojiStarBottom=(body[1]<0 AND longcandle[1] AND low<low[1] AND open<close[1] AND ratio<0.3 AND range<0.3*range[1])
if TrendDown[2] AND DojiStarBottom then
Signal = 13
//DrawText("Doji", barindex, low-atr*0.75, Dialog, Standard, 12) COLOURED(R,G,B)
endif
BullishHaramiCross=(body[1]<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1] and ratio<0.3 and range<0.3*range[1])
if TrendDown[2] AND BullishHaramiCross then
Signal = 14
//DrawText("Bullish Harami Cross", barindex, low-atr*1.20, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
ThreeStarsInTheSouth=(body[2]<0 and body[1]<0 and body<0 and shadowtop[2]<range[2]/4 and shadowbottom[2]>abody[2]/2 and low[1]>low[2] and high[1]<high[2] and abody[1]<abody[2] and shadowtop[1]<range[1]/4 and shadowbottom[1]>abody[1]/2 and low>low[1] and high<high[1] and abody<abody[1] and shadowtop<range/4 and shadowbottom<range/4)
if TrendDown[3] AND ThreeStarsInTheSouth then
Signal = 15
//DrawText("Three Stars In The South", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BullishBreakaway=(body[4]<0 and body[3]<0 and body>0 and open[3]<close[4] and close[2]<close[3] and close[1]<close[2] and longcandle and close<close[4] and close>open[3])
if TrendDown[5] AND BullishBreakaway then
Signal = 16
//DrawText("Bullish Breakaway", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
Hammer=(body[1]<0 and longcandle[1] and low<low[1] and shadowbottom>2*abody and shadowtop<0.3*abody)
if TrendDown[2] AND Hammer then
Signal = 17
//DrawText("Hammer", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
InvertedHammer=(body[1]<0 and longcandle[1] and low<low[1] and shadowtop>2*abody and shadowbottom<0.3*abody)
if TrendDown[2] AND InvertedHammer then
Signal = 18
//DrawText("Inverted Hammer", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
RisingThreeMethods=(body[4]>0 and body[3]<0 and body[1]<0 and body>0 and longcandle[4] and longcandle and close[2]<close[3] and close[1]<close[2] and high[2]<high[3] and high[1]<high[2] and low[1]>low[4] and open>close[1] and close>high[4] and close>high[3] and close>high[2] and close>high[1])
if TrendUp[5] AND RisingThreeMethods then
Signal = 19
//DrawText("Rising Three Methods", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BullishThreeLineStrike=(body[3]>0 and body[2]>0 and body[1]>0 and body<0 and longcandle[3] and longcandle[2] and longcandle[1] and close[2]>close[3] and close[1]>close[2] and open>close[1] and close<open[3])
if TrendUp[4] AND BullishThreeLineStrike then
Signal = 20
//DrawText("Bullish Three Line Strike", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BullishMatHold=(body[4]>0 and body[3]<0 and body[1]<0 and body>0 and longcandle[4] and close[3]>close[4] and close[2]<close[3] and close[1]<close[2] and high[2]<high[3] and high[1]<high[2] and low[1]>low[4] and open>close[1] and close>high[4] and close>high[3] and close>high[2] and close>high[1])
if TrendUp[5] AND BullishMatHold then
Signal = 21
//DrawText("Bullish Mat Hold", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
//Bearish Signal
EveningStar=(body[2]>0 AND body<0 and longcandle[2] and open[1]>close[2] and open<close[1] and ratio[1]<0.3 and abody[1]<abody[2] and abody[1]<abody and high[1]>high and high[1]>high[2] and low[1]>open[2] and low[1]>close)
if TrendUp[3] AND EveningStar then
Signal = 22
//DrawText("Evening Star", barindex, high[1]+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex-1,high[1]) COLOURED(255,0,10)
endif
DarkCloudCover=(body[1]>0 and body<0 and longcandle[1] and longcandle and open>high[1] and close<myMiddle[1] and close>open[1])
if TrendUp[2] AND DarkCloudCover then
Signal = 23
//DrawText("Dark Cloud Cover", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
AbandonedBabyTop=(body[2]>0 and body<0 and longcandle[2] and ratio[1]<0.3 and low[1]>high[2] and low[1]>high)
if TrendUp[3] AND AbandonedBabyTop then
Signal = 24
//DrawText("Abandoned Baby Top", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
ThreeInsideDown=(body[2]>0 and body[1]<0 and body<0 and bearishharami[1] and close<close[1])
if TrendUp[3] AND ThreeInsideDown then
Signal = 25
//DrawText("Three Inside Down", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
ThreeOutsideDown=(body[2]>0 and body[1]<0 and body<0 and bearishengulfing[1] and close<close[1])
if TrendUp[3] AND ThreeOutsideDown then
Signal = 26
//DrawText("Three Outside Down", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
ThreeBlackCrows=(body[2]<0 and body[1]<0 and body<0 and longcandle[2] and longcandle[1] and longcandle and low[1]<low[2] and low<low[1] and close[1]<close[2] and close<close[1] and open[1]<open[2] and open[1]>close[2] and open<open[1] and open>close[1])
if TrendUp[3] AND ThreeBlackCrows then
Signal = 27
//DrawText("Three Black Crows", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
UpsideGapTwoCrows=(body[2]>0 and body[1]<0 and body<0 and longcandle[2] and open[1]>close[2] and bodytop>bodytop[1] and bodybottom<bodybottom[1] and close>close[2])
if TrendUp[3] AND UpsideGapTwoCrows then
Signal = 28
//DrawText("Upside Gap Two Crows", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
BearishHarami=(body[1]>0 and body<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
if TrendUp[2] AND BearishHarami then
Signal = 29
//DrawText("Bearish Harami", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
DescendingHawk=(body[1]>0 and body>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
if TrendUp[2] AND DescendingHawk then
Signal = 30
//DrawText("Descending Hawk", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
BearishEngulfing=(body[1]>0 and body<0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
if TrendUp[2] AND BearishEngulfing then
Signal = 31
//DrawText("Bearish Engulfing", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,20)
endif
LastEngulfingTop=(body[1]<0 and body>0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
if TrendUp[2] AND LastEngulfingTop then
Signal = 32
//DrawText("Last Engulfing Top", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,20)
endif
DragonflyDojiTop=(body[1]>0 and longcandle[1] and high>high[1] and shadowbottom>3*abody and shadowtop<shadowbottom/3)
if TrendUp[2] AND DragonflyDojiTop then
Signal = 33
//DrawText("Dragonfly Doji", barindex, high+atr, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
GravestoneDojiTop=(body[1]>0 and longcandle[1] and high>high[1] and shadowtop>3*abody and shadowbottom<shadowtop/3)
if TrendUp[2] AND GravestoneDojiTop then
Signal = 34
//DrawText("Gravestone Doji", barindex, high+atr, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
DojiStarTop=(body[1]>0 AND longcandle[1] AND high>high[1] AND open>close[1] AND ratio<0.3 AND range<0.3*range[1])
if TrendUp[2] AND DojiStarTop then
Signal = 35
//DrawText("Doji", barindex, high+atr*0.75, Dialog, Standard, 12) COLOURED(R,G,B)
endif
BearishHaramiCross=(body[1]>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1] and ratio<0.3 and range<0.3*range[1])
if TrendUp[2] AND BearishHaramiCross then
Signal = 36
//DrawText("Bearish Harami Cross", barindex, high+atr*1.20, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
AdvanceBlock=(body[2]>0 and body[1]>0 and body>0 and high[2]<high[1] and high[1]<high and open[1]>bodybottom[2] and open[1]<bodytop[2] and open>bodybottom[1] and open<bodytop[1] and abody[1]<abody[2] and abody<abody[1])
if TrendUp[3] AND AdvanceBlock then
Signal = 37
//DrawText("Advance Block", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
TwoCrows=(body[2]>0 and body[1]<0 and body<0 and longcandle[2] and open[1]>close[2] and close[1]>close[2] and open<bodytop[1] and open>bodybottom[1] and close<bodytop[2] and close>bodybottom[2])
if TrendUp[3] AND TwoCrows then
Signal = 38
//DrawText("Two Crows", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
BearishBreakaway=(body[4]>0 and body[3]>0 and body<0 and open[3]>close[4] and close[2]>close[3] and close[1]>close[2] and longcandle and close>close[4] and close<open[3])
if TrendUp[5] AND BearishBreakaway then
Signal = 39
//DrawText("Bearish Breakaway", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
ShootingStar=(body[1]>0 and longcandle[1] and high>high[1] and shadowtop>2*abody and shadowbottom<0.3*abody)
if TrendUp[2] AND ShootingStar then
Signal = 40
//DrawText("Shooting Star", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
HangingMan=(body[1]>0 and longcandle[1] and high>high[1] and shadowbottom>2*abody and shadowtop<0.3*abody)
if TrendUp[2] AND HangingMan then
Signal = 41
//DrawText("Hanging Man", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
FallingThreeMethods=(body[4]<0 and body[3]>0 and body[1]>0 and body<0 and longcandle[4] and longcandle and close[2]>close[3] and close[1]>close[2] and low[2]>low[3] and low[1]>low[2] and high[1]<high[4] and open<close[1] and close<low[4] and close<low[3] and close<low[2] and close<low[1])
if TrendDown[5] AND FallingThreeMethods then
Signal = 42
//DrawText("Falling Three Methods", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
BearishThreeLineStrike=(body[3]<0 and body[2]<0 and body[1]<0 and body>0 and longcandle[3] and longcandle[2] and longcandle[1] and close[2]<close[3] and close[1]<close[2] and open<close[1] and close>open[3])
if TrendDown[4] AND BearishThreeLineStrike then
Signal = 43
//DrawText("Bearish Three Line Strike", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
BearishMatHold=(body[4]<0 and body[3]>0 and body[1]>0 and body<0 and longcandle[4] and close[3]<close[4] and close[2]>close[3] and close[1]>close[2] and low[2]>low[3] and low[1]>low[2] and high[1]<high[4] and open<close[1] and close<low[4] and close<low[3] and close<low[2] and close<low[1])
if TrendDown[5] AND BearishMatHold then
Signal = 44
//DrawText("Bearish Mat Hold", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
//Gaps
GapUp=(low>high[1])
GapDown=(high<low[1])
if GapUp then
Signal = 45
//DrawText("w", barindex, (high[1]+low)/2, Dialog, Bold, 12) COLOURED(0,0,255)
else
if GapDown then
Signal = 46
//DrawText("w", barindex, (high+low[1])/2, Dialog, Bold, 12) COLOURED(255,0,255)
endif
endif
//Steve Nison Candles
BullSash=(body[1]<0 AND longcandle[1] AND body>0 AND longcandle AND open>close[1] AND open<open[1] AND close>open[1] AND shadowtop<0.1*abody)
if BullSash then
Signal = 47
//DrawText("Bull Sash", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BullSeparatingLine=(body[1]<0 AND longcandle[1] AND body>0 AND longcandle AND open>=open[1] AND shadowtop<0.1*abody)
if BullSeparatingLine then
Signal = 48
//DrawText("Bull Separating Line", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BullishCounterAttack=(body[1]<0 AND longcandle[1] AND body>0 AND longcandle AND close<=close[1])
if TrendDown[2] AND BullishCounterAttack then
Signal = 49
//DrawText("Bullish Counter Attack", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BearSash=(body[1]>0 AND longcandle[1] AND body<0 AND longcandle AND open>open[1] AND open<close[1] AND close<open[1] AND shadowbottom<0.1*abody)
if BearSash then
Signal = 50
//DrawText("Bear Sash", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
BearSeparatingLine=(body[1]>0 AND longcandle[1] AND body<0 AND longcandle AND open<=open[1] AND shadowbottom<0.1*abody)
if BearSeparatingLine then
Signal = 51
//DrawText("Bear Separating Line", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
BearishCounterAttack=(body[1]>0 AND longcandle[1] AND body<0 AND longcandle AND close>=close[1])
if TrendUp[2] AND BearishCounterAttack then
Signal = 52
//DrawText("Bearish Counter Attack", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
//Tweezers Top and Bottom
TweezersTop=(body[1]>0 AND longcandle[1] AND body<=0 AND high=high[1])
if TrendUp[2] AND TweezersTop then
Signal = 53
//DrawText("Tweezers Top", barindex, high+atr*1.20, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
TweezersBottom=(body[1]<0 AND longcandle[1] AND body>=0 AND low=low[1])
if TrendDown[2] AND TweezersBottom then
Signal = 54
//DrawText("Tweezers Bottom", barindex, low-atr*1.20, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
//kicker candlestick patterns
BullishKicking=(body[1]<0 AND longcandle[1] AND body>0 AND longcandle AND open>=open[1] AND shadowtop=0 AND shadowbottom=0)
if BullishKicking then
Signal = 55
//DrawText("Bullish Kicking", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
//DrawArrOWUP(barindex,low-atr) COLOURED(0,155,10)
endif
BearishKicking=(body[1]>0 AND longcandle[1] AND body<0 AND longcandle AND open<=open[1] AND shadowtop=0 AND shadowbottom=0)
if BearishKicking then
Signal = 56
//DrawText("Bearish Kicking", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
//DrawArrOWDOWN(barindex,high+atr) COLOURED(255,0,10)
endif
IF Signal = Opt THEN
BUY 1 CONTRACT AT MARKET
//SELLSHORT 1 CONTRACT AT MARKET
SET STOP %LOSS 1
SET TARGET %PROFIT 2
ENDIF
I din’t read Ivan’s reply 🙂
The ITF file is working like a charm.
Several of the ‘Signals’ show body < 0 (example below).
How can a body be less than 0?
Or is it that PRT uses one calc only for body – Close – Open (instead of abs(Close-Open) – and so with a red candle, Close – Open gives a negative number and so this is interpreted by PRT as < 0?
Or do I need more coffee!? 😉
BearSash=(body[1]>0 AND longcandle[1] AND body<0 AND longcandle AND open>open[1] AND open<close[1] AND close<open[1] AND shadowbottom<0.1*abody)
if BearSash then Signal = 50
EDIT / PS
Signal 50 does get selected by the optimser so PRT does interpret body < 0 somehow?
Only had a quick glance at code…
On line 13, if body is bear, close-open will result in a negative value, as you noted, Therefore, is body<0, just a way of knowing its a bear candle by the fact, bear will be negative and bull will be positive.
The BearSash statement is a logic equation, if body<0 was negative, this part results to true ‘1’. If it was positive it results in false ‘0’.
All part of the statement need to be true for Bearish to be true, if body was bull, the statement would fail false.
In this case the value of body appears not needed here just if its + or -.
Maybe the variable names may be a bit misleading, body = candleDirection, abody = candleSize,
additionally line 15, abody = abs(body) is just the size of the body if that info is required in a condition.
I think there is a little bug: the AbandonedBabyBottom signal should be 3 , not 2. From there you have to add 1 to all the signal values. Otherwise, superjob from @lighthouse and @roberto !
Well spotted!
Easier to renumber the first 4 as 0,1,2,3 and enter 0 – 56 -1 in the optimiser?
Well spotted! Easier to renumber the first 4 as 0,1,2,3 and enter 0 – 56 -1 in the optimiser?
even easier, just renumber AbandonedBabyBottom signal from 2 to 57
Indicator to Optimizer
This topic contains 12 replies,
has 7 voices, and was last updated by pableitor
1 year, 4 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 09/21/2024 |
| Status: | Active |
| Attachments: | 2 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.