Strategy Volume Price Level
Forums › ProRealTime English forum › ProOrder support › Strategy Volume Price Level
- This topic has 1 reply, 2 voices, and was last updated 6 years ago by
Vonasi.
-
-
03/14/2019 at 2:01 AM #93576
Hi Coders,
I am opening a thread to test a strategy based on this indicator I made.
https://www.prorealcode.com/prorealtime-indicators/volume-by-price-levels-v2-extended/
Its goal is to identify strength and weakness in the distribution of volume per price :
- Max (strong level of volume per price => resistance or support depending on the position of the price)
- MinSup (week segment of price above the Max)
- MinInf (week segment of price under the Max)
There are 2 strategy ideas behind this indicator:
1. if the price crosses over (respectively under) the strong volume level (“Max”), the price will tend to test a week point in the distribution of volume per price, respectively either superior (“MinSup”) or inferior (“MinInf”).
2. A second idea would be to use a section of StartHighest/EndLowest (respectively StartLowest/EndHighest) to set entry point if the price crosses over MinInf (respectively MinSup) and use Fibonacci to have a trailing stop.
I wrote this code but it nos doing what I want; apparently it is not sequencing the highesthigh and lowestlow ;
Has anybody a clue to what should be modified or done?
Thanks for your help,
Chris
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500DEFPARAM PRELOADBARS = 10000defparam cumulateorders = falseequity = 1000 + strategyprofitz= round(equity/close)//MaxDrawDownPercentage = 10//MaxDrawdown = Equity * (MaxDrawDownPercentage/100)//////IF OnMarket and ((PositionPrice - low)*CountOfPosition) > MaxDrawDown THEN//Quit//ENDIFonce positionSize = z//---------------------//StartHighest=0//StartLowest=1//EndHighest=1//EndLowest=0NbOfDiv=12ScaleFactor=1//---------------------LastLowestbot = 100000LastHighestTop = 0LastLowestBotIndex = 0LastHighestTopIndex = 0NewLowestBotIndex = 0NewHighestTopIndex = 0//// Identification des pivots Top et Bot(tom)PivotBot = close[2]>close[1] and close[1]<closePivotTop = close[2]<close[1] and close[1]>close//// Identification pivot botif PivotBot and close[1] < LastLowestBot thenNewLowestBot = close[1]NewLowestBotIndex = barindex[1]LastHighestTop = NewHighestTopLastHighestTopIndex = NewHighestTopIndex//// calcul des différents segments et définition de MinInf Max MinSupEndBar = NewLowestBotIndexStartBar = LastHighestTopIndexStartBar = max(1,StartBar)Endbar = max(1,Endbar)volsum = summation [StartBar](volume)-summation [EndBar](volume)hh=LastHighestTopll=NewLowestBotdiv = (hh-ll)/NbOfDiv // thickness of the horizontal bari=0///Fibofullrange = abs(hh-ll)fibo100 = hhfibo0 = llfibo236 = ll+(fullrange*0.236)fibo382 = ll+(fullrange*0.382)fibo500 = ll+fullrange/2fibo618 = ll+(fullrange*0.618)fibo764 = ll+(fullrange*0.764)//StartbarIndex = LastHighestTopIndex//EndbarIndex = NewLowestBotIndex////// creation of the variables identifying MinInf, MinSup and MaxlrangeminInf = 0hrangeminInf = 0lrangeminSup = 0hrangeminSup = 0lrangemax = 0hrangemax = 0MaxVol = 0NumBarVol = 0//NumBarMaxVol = 0NumBarMinVolSup = 0NumBarMinVolInf = 0while i<NbOfDiv dolrange=ll+div*ihrange=lrange+divvolbull=0volbear=0NumBarVol = i+1for q = Endbar to StartBar doif close[q]>=lrange and close[q]<=hrange thenif close[q]>open[q] thenvolbull=volbull+volume[q]elsevolbear=volbear+volume[q]endifendifnext//bullbar = round((volbull*StartBar)/volsum)*scalefactor//bearbar = round((volbear*StartBar)/volsum)*scalefactorvolbar = round(((volbear+volbull)*StartBar)/volsum)*scalefactorif i=0 thenlrangemax = lrangehrangemax = hrangeMaxVol = volbar//NumBarMaxVol = NumBarVoLlrangeminSup = lrangehrangeminSup = hrangeMinVolSup = VolBarNumBarMinVolSup = NumBarVollrangeminInf = lrangehrangeminInf = hrangeMinVolInf = VolBarNumBarMinVolInf = NumBarVolendifif volbar > MaxVol thenlrangemax = lrangehrangemax = hrangeMaxVol = volbar//NumBarMaxVol = NumBarVolif MinVolSup < MinVolInf thenlrangeminInf = lrangeminSuphrangeminInf = hrangeminSupMinVolInf = MinVolSupNumBarMinVolInf = NumBarMinVolSupendiflrangeminSup = lrangehrangeminSup = hrangeMinVolSup = VolBarNumBarMinVolSup = NumBarVolelsif volbar < MaxVol thenif volbar < MinVolSup thenlrangeminSup = lrangehrangeminSup = hrangeMinVolSup = VolBarNumBarMinVolSup = NumBarVolendifelselrangeminInf = lrangeminInfhrangeminInf = hrangeminInfMinVolInf = MinVolInfNumBarMinVolInf = NumBarMinVolInfendifi=i+1wendendif//la strégie s'applique = franchissement de MinInf en direction de MAX avec TLS Fibo//tant qu'on a pas trouvé une nouveau plus haut la stratégie fonctionne avec les MinSup/Max/MinInf on reste sur cette stratégie// identification d'un nouveau point pivot haut est trouvéif PivotTop and close[1] > LastHighestTop thenNewHighestTop = close[1]NewHighestTopIndex = barindex[1]LastLowestBot = NewLowestBotLastLowestBotIndex = NewLowestBotIndex//// calcul des différents segments et définition de MinInf Max MinSupEndBar = NewHighestTopIndexStartBar = LastLowestBotIndexStartBar = max(1,StartBar)Endbar = max(1,Endbar)volsum = summation [StartBar](volume)-summation [EndBar](volume)hh=NewHighestTopll=LastLowestBotdiv = (hh-ll)/NbOfDiv // thickness of the horizontal bari=0////// Fibofullrange = abs(hh-ll)fibo100 = llfibo0 = hhfibo236 = hh-(fullrange*0.236)fibo382 = hh-(fullrange*0.382)fibo500 = hh-fullrange/2fibo618 = hh-(fullrange*0.618)fibo764 = hh-(fullrange*0.764)//StartbarIndex = LastLowestBotIndex//EndbarIndex = NewHighestTopIndex////// creation of the variables identifying MinInf, MinSup and Max//lrangeminInf = 0hrangeminInf = 0lrangeminSup = 0hrangeminSup = 0lrangemax = 0hrangemax = 0MaxVol = 0NumBarVol = 0//NumBarMaxVol = 0NumBarMinVolSup = 0NumBarMinVolInf = 0while i<NbOfDiv dolrange=ll+div*ihrange=lrange+divvolbull=0volbear=0NumBarVol = i+1for q = Endbar to StartBar doif close[q]>=lrange and close[q]<=hrange thenif close[q]>open[q] thenvolbull=volbull+volume[q]elsevolbear=volbear+volume[q]endifendifnext////bullbar = round((volbull*StartBar)/volsum)*scalefactor////bearbar = round((volbear*StartBar)/volsum)*scalefactorvolbar = round(((volbear+volbull)*StartBar)/volsum)*scalefactorif i=0 thenlrangemax = lrangehrangemax = hrangeMaxVol = volbar//NumBarMaxVol = NumBarVoLlrangeminSup = lrangehrangeminSup = hrangeMinVolSup = VolBarNumBarMinVolSup = NumBarVollrangeminInf = lrangehrangeminInf = hrangeMinVolInf = VolBarNumBarMinVolInf = NumBarVolendifif volbar > MaxVol thenlrangemax = lrangehrangemax = hrangeMaxVol = volbar//NumBarMaxVol = NumBarVolif MinVolSup < MinVolInf thenlrangeminInf = lrangeminSuphrangeminInf = hrangeminSupMinVolInf = MinVolSupNumBarMinVolInf = NumBarMinVolSupendiflrangeminSup = lrangehrangeminSup = hrangeMinVolSup = VolBarNumBarMinVolSup = NumBarVolelsif volbar < MaxVol thenif volbar < MinVolSup thenlrangeminSup = lrangehrangeminSup = hrangeMinVolSup = VolBarNumBarMinVolSup = NumBarVolendifelselrangeminInf = lrangeminInfhrangeminInf = hrangeminInfMinVolInf = MinVolInfNumBarMinVolInf = NumBarMinVolInfendifi=i+1wendendif//la strégie s'applique = franchissement de MinInf en direction de MAX avec TLS Fibo////// Fibo////StartFibo = max(1,StartbarIndex)//EndFibo = max(1,EndbarIndex)////isSwingDown = StartFibo < EndFibo////if isSwingDown then//fullrange = abs(hh-ll)//fibo100 = hh//fibo0 = ll//fibo236 = ll+(fullrange*0.236)//fibo382 = ll+(fullrange*0.382)//fibo500 = ll+fullrange/2//fibo618 = ll+(fullrange*0.618)//fibo764 = ll+(fullrange*0.764)//////else//fullrange = abs(hh-ll)//fibo100 = ll//fibo0 = hh//fibo236 = hh-(fullrange*0.236)//fibo382 = hh-(fullrange*0.382)//fibo500 = hh-fullrange/2//fibo618 = hh-(fullrange*0.618)//fibo764 = hh-(fullrange*0.764)//////endif////////////////////////////////////////////////////// Strategie#1// Start : lowest// End : highest//Signal long / short : croisement support majeur// Signal buy / sell : MinSup et MinInf//////////////////////////////////////////////////////If StartLowest and EndHighest then//endifif not ONMARKET and close crosses over hrangeminInf or close crosses over lrangeminInf thenBuy positionSize CONTRACTS AT MarketTrailStop = fibo0 - divendifif LONGONMARKET thenif high > fibo0 and high < fibo236 thenTrailStop = fibo0endifif high > fibo236 and high < fibo382 thenTrailStop = fibo236endifif high > fibo382 and high < fibo500 thenTrailStop = fibo382endifif high > fibo500 and high < fibo618 thenTrailStop = fibo500endifif high >= lrangeMax and high <=hrangeMax thenTrailStop = fibo500endifif high > fibo618 and high < fibo764 thenTrailStop = fibo618endifif high > fibo764 and high < fibo100 thenTrailStop = fibo618endifif high > fibo100 thenSELL AT MARKETendifSELL at TrailStop stopendifif not ONMARKET and close crosses under hrangeminSup thenSELLSHORT PositionSize CONTRACTS AT MarketTrailStop = fibo100 + divendifif SHORTONMARKET thenif low > fibo0 and high < fibo236 thenTrailStop = fibo0endifif low > fibo236 and high < fibo382 thenTrailStop = fibo236endifif low > fibo382 and high < fibo500 thenTrailStop = fibo382endifif low > fibo500 and high < fibo618 thenTrailStop = fibo500endifif low >= lrangeMax and high <=hrangeMax thenTrailStop = fibo500endifif low > fibo618 and high < fibo764 thenTrailStop = fibo618endifif low > fibo764 and high < fibo100 thenTrailStop = fibo618endifif low > fibo100 thenEXITSHORT AT MARKETendifEXITSHORT at TrailStop stopendif//endif// debug -----------//graph hH as "fibHigh"//graph lL//graph t236//graph Close//graph ma20graph hrangeMaxgraph hrangeminSupgraph hrangeminInfgraph TrailStopgraph NewHighestTopgraph hhgraph llgraph fibo100 + divgraph fibo236graph fibo382graph (low < fibo236)*10graph NewLowestBotgraph StartBargraph Endbargraph barindexgraph NewLowestBotIndex//graph StartDateStrat//graph positionperf// ------------------03/14/2019 at 9:53 AM #93592At a glance it appears that you zero everything in lines 29 to 34 on every run through the code so you have no last values to compare to. Maybe you need to use ONCE?
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on