Does anyone have code that can do this, or something similar?
I have the prices of support/resistance (S/R) lines stored in an ArrayList. When price is moving up, I want to find the nearest S/R line, in said ArrayList, that is currently below the Close price, once price gets 1 point above the nearest S/R line. And, the opposite when price is moving down.
See attached image for illustration.
Thanks guys.
Can you help answer these questions from other members on futures io?
That's funny... sending me a link to my own modified code. LOL
The Swing ind. only stores the most recent occurance. I have an ArrayList, which may have up to 15 stored prices, that I need to look through.
In variables section declare a list object...they are more efficient than arrays and do not need to be initialized with a size. Or just use arrays, no matter. Methods are the same.
This routine will go thru the list object and put the next supprt (SRNextLow) below the Close of the current bar, and the next resistance (SRNextHigh) above the current close
if there are no support values above, it sets SRNextHigh to 0
if there are no support values below, it sets SRNextLow to 0
items may be added to the List object using .add method
Hope this helps
PS. dont forget to add a ref to
using System.Collections.Generic;
Laserdan
The following user says Thank You to Laserdan for this post:
This way you don't need to worry about which way price is moving. The current bar close is always sandwiched between the two SR lines (one above and one below).
Laserdan
The following user says Thank You to Laserdan for this post:
Site Administrator Swing Trader Data Scientist & DevOps
Manta, Ecuador
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
Posts: 49,785 since Jun 2009
Thanks: 32,314 given,
97,575
received
zacharydw00
Does anyone have code that can do this, or something similar?
I have the prices of support/resistance (S/R) lines stored in an ArrayList. When price is moving up, I want to find the nearest S/R line, in said ArrayList, that is currently below the Close price, once price gets 1 point above the nearest S/R line. And, the opposite when price is moving down.
See attached image for illustration.
Thanks guys.
A very long time ago I wrote a strategy to trade Murrey Math lines, and I wrote some functions to get all the levels. I'm willing to share the strategy, but only for elite members (which this thread is not). Can be easily adapted to Pivots.
I wrote this strategy over a year ago for NT. I haven't looked at it in a year, but I've received dozens of requests from people who read about the strategy for me to sell it or give it to them, etc. I've always declined, but the fact is, …
Here's the code I ended up with. (including all the debugging Print statements & a Plot statement) price is typically going to be Close[0] srOffset is how far price need to be away from any S/R lines. IE. if there is an S/R at 90 & 100, the trend is up, and you want price to confirm above 110 before using S/R @ 100 then set srOffset = 10, when price gets to 100, 90 will be returned. Trend = true for up trend, false for down trend. srList hold the list of S/R line values.
private double FindSRline(double price, double srOffset, bool Trend, ArrayList srList)
{
srNearest = 0;
if (Trend) // UP Trend
{ //Print (Time[0].ToString()+" \tCurrentBar = "+CurrentBar+"\tTrend = UP \tsrListCnt = "+(srList.Count));
for (i=0; i < srList.Count; i++) // Search from Lowest price in srList
{ //Print ("srList["+i+"]+1 = "+Math.Round((double)srList[i]+srOffset,2).ToString("0000.00")+" \tprice = "+price.ToString("0000.00"));
if (price >= (double)srList[i]+srOffset) // Find Close above SRline+offset
{ srNearest = (double)srList[i]; }
else
{ //Print ("break; srNearest = srList["+(i)+"] = "+srNearest.ToString("0000.00"));
break; // Stop if price is below SRline+offset
}
}
// if (srNearest > 0) Values[srListMax].Set(srNearest); // Plot srNearest for TESTING
}
else // DOWN Trend
{ //Print (Time[0].ToString()+" \tCurrentBar = "+CurrentBar+"\tTrend = DOWN \tsrListCnt = "+(srList.Count));
for (i=srList.Count-1; i >= 0; i--) // Search from Highest price in srList
{ //Print ("srList["+i+"]+1 = "+Math.Round((double)srList[i]+srOffset,2).ToString("0000.00")+" \tprice = "+price.ToString("0000.00"));
if (price <= (double)srList[i]-srOffset) // Find Close below SRline-offset
{ srNearest = (double)srList[i]; }
else
{ //Print ("break; srNearest = srList["+(i)+"] = "+srNearest.ToString("0000.00"));
break; // Stop if price is above SRline-offset
}
}
// if (srNearest > 0) Values[srPlot].Set(srNearest); // Plot srNearest for TESTING
}
//Print ("srNearest = srList["+i+"] = "+srNearest.ToString("0000.00"));
return srNearest ;
}
Thanks for the suggestions guys.
Milk-a-What?
The following 2 users say Thank You to zacharydw00 for this post:
1) Would you please expand a little on srlist, how you formulate that?
2) I am curious on how you determine trend for this.
Thanks for this code, it definitely will be studied for use!
Jon
1) srList is an "array" (specifically an ArrayList, Google it) that stores all the s/r (Support/Resistance) price values. It's up to you to determine these values and store them in an ArrayList. As a side note. Static values would be horizontal s/r lines. If you want to use dynamic s/r lines, such as a 200, 100, & 50 SMA for s/r, then you would have to update the srList array on every bar.
2} Trend could be determined by the slope of an MA, LinRegSlope ind., DM ind., or whatever your favorite sloping indicator is. If the slope is up then Trend would equal true.
Good Luck.
Milk-a-What?
The following user says Thank You to zacharydw00 for this post:
This way you don't need to worry about which way price is moving. The current bar close is always sandwiched between the two SR lines (one above and one below).
Hello senior members,
can we code the above function into amibroker ?.
i.e=
my value=300;
h1=310,h2=320,h3=325,h4=312,h5=318......
out of h1,h2,h3 i want to find out which value is nearest to my value i.e 300
Thank you
Site Administrator Swing Trader Data Scientist & DevOps
Manta, Ecuador
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
Posts: 49,785 since Jun 2009
Thanks: 32,314 given,
97,575
received
dar17
Hello senior members,
can we code the above function into amibroker ?.
i.e=
my value=300;
h1=310,h2=320,h3=325,h4=312,h5=318......
out of h1,h2,h3 i want to find out which value is nearest to my value i.e 300
Thank you