Market Bias Indicator
Forums › ProRealTime English forum › ProBuilder support › Market Bias Indicator
- This topic has 6 replies, 3 voices, and was last updated 1 year ago by Nicolas.
-
-
06/10/2023 at 11:32 PM #215956Hello, is it possible to code this indicator in PRT? I find it very interesting. Thank’s in advanceAlessio// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Professeur_X//@version=5indicator(title=’HA Market Bias’, shorttitle=’HA Market Bias’, overlay=true)tf(_res, _exp, gaps_on) =>gaps_on == 0 ? request.security(syminfo.tickerid, _res, _exp) : gaps_on == true ? request.security(syminfo.tickerid, _res, _exp, barmerge.gaps_on, barmerge.lookahead_off) : request.security(syminfo.tickerid, _res, _exp, barmerge.gaps_off, barmerge.lookahead_off)ha_htf = ”show_ha = input.bool(true, “Show HA Plot/ Market Bias”, group=”HA Market Bias”)ha_len = input(100, ‘Period’, group=”HA Market Bias”)ha_len2 = input(100, ‘Smoothing’, group=”HA Market Bias”)// Calculations {o = ta.ema(open, ha_len)c = ta.ema(close, ha_len)h = ta.ema(high, ha_len)l = ta.ema(low, ha_len)haclose = tf(ha_htf, (o + h + l + c) / 4, 0)xhaopen = tf(ha_htf, (o + c) / 2, 0)haopen = na(xhaopen[1]) ? (o + c) / 2 : (xhaopen[1] + haclose[1]) / 2hahigh = math.max(h, math.max(haopen, haclose))halow = math.min(l, math.min(haopen, haclose))o2 = tf(ha_htf, ta.ema(haopen, ha_len2), 0)c2 = tf(ha_htf, ta.ema(haclose, ha_len2), 0)h2 = tf(ha_htf, ta.ema(hahigh, ha_len2), 0)l2 = tf(ha_htf, ta.ema(halow, ha_len2), 0)ha_avg = (h2 + l2) / 2// }// Oscillator {osc_len = input.int(7, “Oscillator Period”, group=”HA Market Bias”)osc_bias = 100 *(c2 – o2)osc_smooth = ta.ema(osc_bias, osc_len)sigcolor=(osc_bias>0)and(osc_bias>=osc_smooth)?color.new(color.lime,35):(osc_bias>0)and(osc_bias<osc_smooth)?color.new(color.lime,75):(osc_bias<0)and(osc_bias<=osc_smooth)?color.new(color.red,35):(osc_bias < 0) and (osc_bias > osc_smooth) ? color.new(color.red, 75) :na// }// Plots {p_h = plot(h2, “Bias High”, color=color(na), display=display.none, editable=false)p_l = plot(l2, “Bias Low”, color=color(na), display=display.none, editable=false)p_avg = plot(ha_avg, “Bias Avergae”, color=color(na), display=display.none, editable=false)fill(p_l, p_h, show_ha ? sigcolor : na)col = o2 > c2 ? color.red : color.limeplotcandle(show_ha ? o2 : na, h2, l2, c2, title=’heikin smoothed’, color=col)// }06/11/2023 at 11:08 AM #215962
Hi Alessio,
I had to split the indicator so that “HA Market Bias” indicator can be added in the price chart and the “Oscillator Market Bias” below the price chart…
First, the “HA Market BIAS”…
HA Market Bias1234567891011121314151617181920212223HAlen=100 //HA periodHAlen2=100 //HA smoothing period//CalculationsxO=ExponentialAverage[HAlen](Open)xC=ExponentialAverage[HAlen](Close)xH=ExponentialAverage[HAlen](High)xL=ExponentialAverage[HAlen](Low)HAClose=(xO+xH+xL+xC)/4xHAOpen=(xO+xC)/2HAOpen=(xHAOpen[1]+HAClose[1])/2HAHigh=Max(xH,Max(HAOpen,HAClose))HALow=Min(xL,Min(HAOpen,HAClose))O2=ExponentialAverage[HAlen2](HAOpen)C2=ExponentialAverage[HAlen2](HAClose)H2=ExponentialAverage[HAlen2](HAHigh)L2=ExponentialAverage[HAlen2](HALow)HAAvg=(H2+L2)/2Return H2 as "BIAS High", L2 as "BIAS Low", HAAvg as "BIAS Average"06/11/2023 at 6:11 PM #21597406/12/2023 at 8:04 PM #216026Hi Alessio / @Aragorna
Here is the bias indicator with the colors of the oscillator…
Hope it helps you…
Market BIAS Indicator coloured123456789101112131415161718192021222324252627282930313233343536373839404142434445464748HAlen=100 //HA periodHAlen2=100 //HA smoothing period//CalculationsxO=ExponentialAverage[HAlen](Open)xC=ExponentialAverage[HAlen](Close)xH=ExponentialAverage[HAlen](High)xL=ExponentialAverage[HAlen](Low)HAClose=(xO+xH+xL+xC)/4xHAOpen=(xO+xC)/2HAOpen=(xHAOpen[1]+HAClose[1])/2HAHigh=Max(xH,Max(HAOpen,HAClose))HALow=Min(xL,Min(HAOpen,HAClose))O2=ExponentialAverage[HAlen2](HAOpen)C2=ExponentialAverage[HAlen2](HAClose)H2=ExponentialAverage[HAlen2](HAHigh)L2=ExponentialAverage[HAlen2](HALow)HAAvg=(H2+L2)/2OSCLen=7 //Oscillator periodOSCBias=100*(C2-O2)OSCSmooth=ExponentialAverage[OSCLen](OSCBias)If OscBias>0 and OscBias>=OscSmooth thenR=0G=255B=0ElsIf OscBias>0 and OscBias<OscSmooth thenR=0G=150B=0ElsIf OscBias<0 and OscBias<=OscSmooth thenR=255G=0B=0ElsIf OscBias<0 and OscBias>OscSmooth thenR=150G=0B=0EndIfDrawcandle(O2,H2,L2,C2) Coloured(R,G,B)Return H2 as "BIAS High", L2 as "BIAS Low", HAAvg as "BIAS Average"06/13/2023 at 1:44 AM #216041thank you JS. I was thinking about a strategy that uses this market Bias and stifness indicator. I don’t know if it’s something good enough, this strategy is both long and short on Nasdaq, 1Hour TF. consider I use IB, not IG. so things could be a little different.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192defparam cumulateorders= false// BIAS market+stifness indicatorHAlen=MM //HAlen2=NN ////CalculationsxO=ExponentialAverage[HAlen](Open)xC=ExponentialAverage[HAlen](Close)xH=ExponentialAverage[HAlen](High)xL=ExponentialAverage[HAlen](Low)HAClose=(xO+xH+xL+xC)/4xHAOpen=(xO+xC)/2HAOpen=(xHAOpen[1]+HAClose[1])/2HAHigh=Max(xH,Max(HAOpen,HAClose))HALow=Min(xL,Min(HAOpen,HAClose))O2=ExponentialAverage[HAlen2](HAOpen)C2=ExponentialAverage[HAlen2](HAClose)H2=ExponentialAverage[HAlen2](HAHigh)L2=ExponentialAverage[HAlen2](HALow)HAAvg=(H2+L2)/2//Return H2 as "BIAS High", L2 as "BIAS Low", HAAvg as "BIAS Average"P = 100LB = PP //LookBack periods- 60LB = max(1,min(999,LB)) //range allowed: 1-999HAAvgL = HAAvg + (0.2 * STD[P](close)) //add a buffer for LONG trendsHAAvgS = HAAvg - (0.2 * STD[P](close)) //subtract a buffer for SHORTContoL = summation[LB](close > HAAvgL) //tally how many times CLOSE was above SMA in the LB periodContoS = summation[LB](close < HAAvgS) //tally how many times CLOSE was below SMA in the LB period//StiffL = 100 * (ContoL / LB) //UPtrend %StiffS = 100 * (ContoS / LB) //DOWNtrend %//RETURN StiffL AS "UPtrend %",StiffS AS "DOWNtrend %",90 AS "90",10 AS "10",50 as "50"If not longonmarket and Close Crosses Over HAAvgS and Summation[QQ](StiffL<10) and (StiffL > 10) then //50Buy 1 contract at MarketEndIfIf not SHORTONMARKET and Close Crosses under HAAvgS and Summation[QQ](StiffL>90) and (StiffL < 90) then //50SELLSHORT 1 contract at MarketEndIf// Stops und TargetsSET STOP pLOSS TT//200SET TARGET PPROFIT UU//400//trailing stop functiontrailingstart = RR// 20trailing will start @trailinstart points profit-50trailingstep = 10// 5trailing step to move the "stoploss"//reset the stoploss valueIF NOT LONGONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFthis strategy instead is only long. I did Forwars test for this last one, that seems good. Consider I can see 100K bars.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990defparam cumulateorders= false// BIAS market+stifness indicatorHAlen=MM //HAlen2=NN ////CalculationsxO=ExponentialAverage[HAlen](Open)xC=ExponentialAverage[HAlen](Close)xH=ExponentialAverage[HAlen](High)xL=ExponentialAverage[HAlen](Low)HAClose=(xO+xH+xL+xC)/4xHAOpen=(xO+xC)/2HAOpen=(xHAOpen[1]+HAClose[1])/2HAHigh=Max(xH,Max(HAOpen,HAClose))HALow=Min(xL,Min(HAOpen,HAClose))O2=ExponentialAverage[HAlen2](HAOpen)C2=ExponentialAverage[HAlen2](HAClose)H2=ExponentialAverage[HAlen2](HAHigh)L2=ExponentialAverage[HAlen2](HALow)HAAvg=(H2+L2)/2//Return H2 as "BIAS High", L2 as "BIAS Low", HAAvg as "BIAS Average"P = 100LB = PP //LookBack periods- 60LB = max(1,min(999,LB)) //range allowed: 1-999HAAvgL = HAAvg + (0.2 * STD[P](close)) //add a buffer for LONG trendsHAAvgS = HAAvg - (0.2 * STD[P](close)) //subtract a buffer for SHORTContoL = summation[LB](close > HAAvgL) //tally how many times CLOSE was above SMA in the LB periodContoS = summation[LB](close < HAAvgS) //tally how many times CLOSE was below SMA in the LB period//StiffL = 100 * (ContoL / LB) //UPtrend %StiffS = 100 * (ContoS / LB) //DOWNtrend %//RETURN StiffL AS "UPtrend %",StiffS AS "DOWNtrend %",90 AS "90",10 AS "10",50 as "50"If not longonmarket and Close Crosses Over HAAvgS and Summation[QQ](StiffL<10) and (StiffL > 10) then //50Buy 1 contract at MarketEndIf// Stops und TargetsSET STOP pLOSS TT//200SET TARGET PPROFIT UU//400//trailing stop functiontrailingstart = RR// 20trailing will start @trailinstart points profit-50trailingstep = 10// 5trailing step to move the "stoploss"//reset the stoploss valueIF NOT LONGONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF1 user thanked author for this post.
06/13/2023 at 1:51 AM #21604206/13/2023 at 8:42 AM #216101I just add this Market Bias indicator in the Library, thank you @JS for providing the translation!
Market Bias indicator coloured
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on