Change Scan to Study and add color to candle


Category:
0
0

Hey Pete, 

Below are the conditions I’m looking for. I have it set up ( I think) on a scan and want to see if I can put it into a study and add another condition. 

If the volume is up 10% (or whatever % we choose) and if MktFacilitationIdx (study: MktFacilIdx) is less than the prior bar. 

If these conditions are met, can we change the bar to yellow on the chart and receive an alert?

 

Below are the screen shots I have set up from the scan and a chart example. 

Thanks

Attachments:
Marked as spam
Posted by (Questions: 21, Answers: 47)
Asked on August 11, 2019 8:44 pm
126 views
0
First attempt: input price = volume; input percent = 10; input Choice = {default greater, less}; input length = 1; def x = 100*(price / price[length]-1); def condition = x and mktFacilitationIdx() is less than 0 and mktFacilitationIdx() is less than mktFacilitationIdx() from 1 bars ago; plot scan = condition; AssignPriceColor(if condition then Color.YELLOW else Color.CURRENT);
( at August 11, 2019 9:31 pm)
0
In your "first attempt". The inputs for percent and Choice are never used in your condition. I have no clue what you are attempting do with x, but you are trying to use x as a true/false condition. However it is NOT a true/false condition, x is a numerical value.
( at August 12, 2019 9:06 am)
0
Not sure what to do with the volume study that I pulled from the scan wizard and how to add it to the mktFacilitation study as well. Looking for the volume is up 10% (or whatever % we choose and why I want an input) and if MktFacilitationIdx (study: MktFacilIdx) is less than its the prior bar. If these conditions are met, can we change the bar to yellow on the chart and receive an alert?
( at August 12, 2019 10:07 am)
0
I've also adjust this line: mktFacilitationIdx() is less than mktFacilitationIdx() from 1 bars ago. There is no zero line and took the first part out
( at August 12, 2019 11:33 am)
0
Updated*** (Need the percent increase 10%) I think 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);
( at August 12, 2019 11:42 am)
0
Private answer

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.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on August 12, 2019 1:51 pm
0
Thank you very much and it's great trying to get this on my own. The videos online are very helpful too. Again, I really appreciate the assistance on this.
( at August 12, 2019 2:20 pm)