Moving average colour change
Forums › ProRealTime English forum › ProBuilder support › Moving average colour change
- This topic has 5 replies, 3 voices, and was last updated 4 years ago by
robertogozzi.
-
-
11/22/2021 at 11:06 AM #182055
Hi there,
I would like to code a moving average(10 SMA) but change the colour when it points up or down. is there a way to do it in the code so I do not have to do it manually?I did search for it but didn’t find anything.
thanks in advance, 🙂
11/22/2021 at 2:41 PM #182066A colour change is when the current candle is:
- ascending and the previous one was descending;
- descending and the previous one was ascending.
Here is the code:
123MySma = average[20,0](close)Rising = MySma > MySma[1] AND MySma[1] < MySma[2]Falling = MySma < MySma[1] AND MySma[1] > MySma[2]1 user thanked author for this post.
11/25/2021 at 7:13 AM #182239Okay, just struggling to make it work in the code. What do I have to return in the code to make the average appear on chart and still have two separate colours? I know it might be a dumb question, just not too great at coding. Usually to make the average a standard colour we return the average and also the colour, but more than that I’m struggling with.
11/25/2021 at 9:14 AM #182245Just a way to do it (many other options to color based on conditions)
12345678910111213MySma = average[20,0](close)Rising = MySma > MySma[1] AND MySma[1] < MySma[2]Falling = MySma < MySma[1] AND MySma[1] > MySma[2]if rising thenr = 0g = 255elsif falling thenr = 255g = 0endifreturn mysma coloured(r,g,0)2 users thanked author for this post.
11/25/2021 at 12:33 PM #18225811/26/2021 at 5:55 PM #182348You can use the indicator’s properties (settings) to add colour zones.
This is the code that mimicks the properties, but is not as good:
123456789101112131415161718192021222324MySma = average[20,0](close)Rising = MySma > MySma[1] AND MySma[1] < MySma[2]Falling = MySma < MySma[1] AND MySma[1] > MySma[2]if rising thenr = 0g = 255elsif falling thenr = 255g = 0endifIF close > MySma THENOO = closeHH = closeLL = MySmaCC = MySmaDrawCandle(OO,HH,LL,CC) coloured(0,128,0,16)ELSIF close < MySma THENOO = MySmaHH = MySmaLL = closeCC = closeDrawCandle(OO,HH,LL,CC) coloured(255,0,0,16)ENDIFreturn mysma coloured(r,g,0)1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on