Starting Point
Ok so after a couple of attempts this is what you have created:
input price = volume;
input percent = 10;
input length = 1;
def condition = price is greater than price from 1 bars ago and mktFacilitationIdx() is less than mktFacilitationIdx() from 1 bars ago;
plot scan = condition;
AssignPriceColor(if condition then Color.YELLOW else Color.CURRENT);
Since you are trying to learn how to do this on your own (and making very good progress), I will give you some tips and show you how I would build it myself. I take a very simplistic approach to everything. And I build from the foundation up. I don't try to put the paint on while I'm framing the walls, get it?
Foundation
So let's see what that foundation looks like. Which is the very minimum amount of code to get the job done. We'll add paint and landscaping after we get something functional.
First we have the volume filter. I have copied this directly from the Study Filter on the scan, based on the screenshot you provided.
The only thing I have changed is:
plot scan;
That now becomes one of our two conditions. So we change it to this:
def conditionVolume;
And having done this, we need to be very careful to ensure we also update the rest of the code to replace the variable named scan
, with the new variable named conditionVolume
.
Here is the complete code for the volume filter with those modifications completed.
input price = volume;
input percent = 2;
input Choice = {default greater, less};
input length = 10;
def x = 100*(price / price[length]-1);
def conditionVolume;
switch (Choice){
case greater:
conditionVolume = x >= percent;
case less:
conditionVolume = x <= -percent;
}
Having completed our volume filter, let's move on to the second condition. Which is taken from the Condition Wizard as you have included in your screenshot:
MktFacilitationIdx() is less than MktFacilitationIdx() from 1 bars ago
That is straight from the Condition Wizard, in its purest form. But we need to take that code and use it to assign a new variable for our second condition. Which I will name conditionMFI
:
def conditionMFI = MktFacilitationIdx() is less than MktFacilitationIdx() from 1 bars ago;
Putting it All Together
That's all we need to do. I did mention something about painting and landscaping. However the volume filter we copied from the scan already had those element applied (HINT: the user adjustable inputs). Now let's put them all together into a single section of code and add the final line of code that colors the candle based on these two conditions.
input price = volume;
input percent = 2;
input Choice = {default greater, less};
input length = 10;
def x = 100*(price / price[length]-1);
def conditionVolume;
switch (Choice){
case greater:
conditionVolume = x >= percent;
case less:
conditionVolume = x <= -percent;
}
def conditionMFI = MktFacilitationIdx() is less than MktFacilitationIdx() from 1 bars ago;
AssignPriceColor(if conditionVolume and conditionMFI then Color.YELLOW else Color.CURRENT);
Screenshot below shows the result.