Posts: 50 since Oct 2010
Thanks Given: 36
Thanks Received: 10
|
Hello,
I wrote a simple program that draws arrows whenever the Stochastic crosses above 20 or below 80. But sometimes the Stoch. completes the cycles before crossing 20 or 80. Unfortunately I'm not smart enough to write smth more complicated and need help with this if possible please. I do not know if this is too much to ask. Please let me know if this is the issue.
The idea is simple - to get a single arrow per cycle. Currently the program draws the arrows whenever the Stoch crosses 20 then 30, 40 etc... But what I want is to check for all crosses, e.g. CrossAbv 20, 30, 40... and if either one is true then draw the arrow and disregard the rest of the crosses. Below is the simple test code I wrote, which works lk OR, e.g. drawing arrows if cross abv 20 or 30, or 40... It would work if the Stoch. completes the cycle before crossing below 20% line then reverses somewhere around 25% and keep rising. But again, it would draw the arrows at 30, 40... But I want only one arrow per cycle, e.g. if it reverses at 25 then check for crosses above 25 and if cross abv 30 = true draw arrow and disregard the rest of the checks.
private int crsAbvCheck = 0;
bool crsAbv20 = false;
bool crsAbv30 = false;
bool crsAbv40 = false;
bool crsAbv50 = false;
OnBarUpdate....
if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 20, 1))
{
crsAbv20 = true; crsAbvCheck = 20;
}
else if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 30, 1))
{
crsAbv30 = true; crsAbvCheck = 30;
}
else if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 40, 1))
{
crsAbv40 = true; crsAbvCheck = 40;
}
else if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 30, 1))
{
crsAbv50 = true; crsAbvCheck = 50;
}
else
{
crsAbv20 = false; crsAbv30 = false; crsAbv40 = false; crsAbv50 = false; crsAbvCheck = 0;
}
if (crsAbv20 || crsAbv30 || crsAbv40 || crsAbv50) { Print("Cross abv = " +crsAbvCheck+ "---Time:......"+Time[0]); }
I do not know how to write a code that would draw arrow for the first cross and would disregard the rest.
Another thing that comes to mind but I do not have enough skills to implement this is how to check the MACD cross if Stoch. cross returns false, which sounds simple....
Thank you very much.
|