How to code condition block for change % of an indicator
-
I am having trouble with figuring how to use the adjust section of the condition block correctly. Let's say I am using the 5 minute time frame and I want to place a buy now if the MACD indicator value 5 minutes ago was at -10 and then it increased in value to -8 or higher over the next 5 minutes.
-
It is a lot easier to use a fixed number -10 to -8 is +2, do you need a %?
-
Yes preferably I was looking for a relative notable percentage change in a Macd value from a previous point in time to a present or closer to present point in time as a condition to pass or not. I could do fixed numbers it may just take me more time to code.
-
You will need to get the value at a given place, by doing this:
// Define two numbers
num1 = 50;
num2 = 70;// Calculate the absolute difference
double absoluteDifference = MathAbs(num1 - num2);// Calculate the percentage difference relative to num1 (or you could use num2 or average)
percentageDifference = (absoluteDifference / num1) * 100;Num1 and num2 are the 2 indicator values, you will need to create the variable to save the result.
-
I am sorry, I think I miscommunicated. I am not looking to find a certain percent. I am looking for the bot to place a buy trade if condition the Macd value is greater than -15 and if yes to place a buy trade if the Macd value increased by 20% or more from the previous candle bar. When I plugged in 120% after backtesting the bot placed a trade at 17:40 when the Macd value was decreasing. When I plugged in 20% after backtesting the bot did not place a trade at 16:40 or 16:45 when the Macd value was greater than -15 value and it increased more than 20%.
