how to extract nearest support price from arraylist? - futures io
futures io



how to extract nearest support price from arraylist?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one zacharydw00 with 5 posts (3 thanks)
    2. looks_two Trader.Jon with 3 posts (0 thanks)
    3. looks_3 Laserdan with 2 posts (2 thanks)
    4. looks_4 Big Mike with 2 posts (2 thanks)
    1. trending_up 4,268 views
    2. thumb_up 7 thanks given
    3. group 6 followers
    1. forum 15 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

how to extract nearest support price from arraylist?

(login for full post details)
  #1 (permalink)
 zacharydw00 
Idaho
 
Experience: Intermediate
Platform: NinjaTrader,ToS
Broker: Amp Futures, ToS
Trading: ES, E7, CL, GC
 
zacharydw00's Avatar
 
Posts: 145 since Aug 2009
Thanks: 87 given, 172 received

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.

Attached Thumbnails
Click image for larger version

Name:	How To Find nearest SR price in array.jpg
Views:	131
Size:	61.5 KB
ID:	20966  
Started this thread Reply With Quote

Journal Challenge April 2021 results:
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(620 thanks from 61 posts)
looks_twoSalao's Journalby Salao
(163 thanks from 29 posts)
looks_3Learning to Profit - A journey in algorithms and optionsby Syntax
(115 thanks from 27 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(94 thanks from 30 posts)
looks_5Maybe a little bit different journalby Malykubo
(53 thanks from 32 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
I finally blew up an account
122 thanks
The Crude Dude Oil Trading System
85 thanks
Spoo-nalysis ES e-mini futures S&P 500
66 thanks
The tiyfTradePlanFactory indicator
32 thanks
Building a Crypto Mining Rig
19 thanks
 
(login for full post details)
  #3 (permalink)
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
 
Trader.Jon's Avatar
 
Posts: 500 since Jul 2009
Thanks: 401 given, 184 received



zacharydw00 View Post
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 that is currently below the Close price, and the opposite when price is moving down.
See attached image for illustration.
Thanks guys.

Not exactly what you asked, and it _might_ do if you dont have a resolution : Swing Gap Links and Downloads Manager - NinjaTrader Support Forum

use the MostRecentOccurance ... I might have other thoughts after a nites sleep

TJ

Reply With Quote
 
(login for full post details)
  #4 (permalink)
 zacharydw00 
Idaho
 
Experience: Intermediate
Platform: NinjaTrader,ToS
Broker: Amp Futures, ToS
Trading: ES, E7, CL, GC
 
zacharydw00's Avatar
 
Posts: 145 since Aug 2009
Thanks: 87 given, 172 received


Trader.Jon View Post
Not exactly what you asked, and it _might_ do if you dont have a resolution : Swing Gap Links and Downloads Manager - NinjaTrader Support Forum
use the MostRecentOccurance ... I might have other thoughts after a nites sleep TJ

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.

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
 cory 
the coin hunter
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
 
cory's Avatar
 
Posts: 6,044 since Jun 2009
Thanks: 857 given, 7,916 received

loop thru your array, for support look for smallest negative price - s/r value, for resis look for smallest positive price - s/r value.

Reply With Quote
 
(login for full post details)
  #6 (permalink)
 zacharydw00 
Idaho
 
Experience: Intermediate
Platform: NinjaTrader,ToS
Broker: Amp Futures, ToS
Trading: ES, E7, CL, GC
 
zacharydw00's Avatar
 
Posts: 145 since Aug 2009
Thanks: 87 given, 172 received

Thanks cory. I get the concept. The details are another thing.

Any code givers... any one... any one... Bueller.... any body

Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
 
Trader.Jon's Avatar
 
Posts: 500 since Jul 2009
Thanks: 401 given, 184 received


zacharydw00 View Post
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.

MostRecentOccurence (MRO(SwingGap)[0]) ...MRO(SwingGap)[15] gets those values, me thinks

Reply With Quote
 
(login for full post details)
  #8 (permalink)
 Laserdan 
North Carolina
 
Experience: Beginner
Platform: Ninja Trader
Broker: Ninja Trader Broker / Continuum
Trading: ES
 
Posts: 57 since Jun 2009
Thanks: 4 given, 57 received

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.

List<double>listSR = new List<double>();
privatedouble SRNextHigh = 0;
privatedouble SRNextLow = 0;


 
Code
protected void FindNextSR()
{
 
listSR.Sort();
for (int x = 0; x < listSR.Count; x++)
{
if (listSR[x] > Close[0])
{
SRNextHigh = listSR[x];
if (x != 0) SRNextLow = listSR[x - 1];
Print(SRNextHigh + " High   Close=" + Close[0] + "   Low " + SRNextLow);
break;
}
if (listSR[x] > Close[0]) SRNextLow = 0;
if (listSR[x] < Close[0]) SRNextHigh = 0;
}
}
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
Follow me on Twitter Reply With Quote
The following user says Thank You to Laserdan for this post:
 
(login for full post details)
  #9 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
 
Posts: 278 since Jun 2009
Thanks: 161 given, 269 received

most recent occurrence. wouldnt that be the last value of the List.

like

 
Code
 List<double>listSR = new List<double>();



 
Code
double SR = listSR[listSR.Count - 1];


Reply With Quote
 
(login for full post details)
  #10 (permalink)
 Laserdan 
North Carolina
 
Experience: Beginner
Platform: Ninja Trader
Broker: Ninja Trader Broker / Continuum
Trading: ES
 
Posts: 57 since Jun 2009
Thanks: 4 given, 57 received


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 View Post
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.

List<double>listSR = new List<double>();
privatedouble SRNextHigh = 0;
privatedouble SRNextLow = 0;


 
Code
protected void FindNextSR()
{
 
listSR.Sort();
for (int x = 0; x < listSR.Count; x++)
{
if (listSR[x] > Close[0])
{
SRNextHigh = listSR[x];
if (x != 0) SRNextLow = listSR[x - 1];
Print(SRNextHigh + " High   Close=" + Close[0] + "   Low " + SRNextLow);
break;
}
if (listSR[x] > Close[0]) SRNextLow = 0;
if (listSR[x] < Close[0]) SRNextHigh = 0;
}
}
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
Follow me on Twitter Reply With Quote
The following user says Thank You to Laserdan for this post:
 
(login for full post details)
  #11 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,068 since Jun 2009
Thanks: 32,534 given, 98,494 received


zacharydw00 View Post
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.

Here is the thread:


Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #12 (permalink)
 zacharydw00 
Idaho
 
Experience: Intermediate
Platform: NinjaTrader,ToS
Broker: Amp Futures, ToS
Trading: ES, E7, CL, GC
 
zacharydw00's Avatar
 
Posts: 145 since Aug 2009
Thanks: 87 given, 172 received

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.
 
Code
        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?
Started this thread Reply With Quote
The following 2 users say Thank You to zacharydw00 for this post:
 
(login for full post details)
  #13 (permalink)
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
 
Trader.Jon's Avatar
 
Posts: 500 since Jul 2009
Thanks: 401 given, 184 received

Would you please expand a little on srlist, how you formulate that?

I am curious on how you determine trend for this.

Thanks for this code, it definitely will be studied for use!

Jon

Reply With Quote
 
(login for full post details)
  #14 (permalink)
 zacharydw00 
Idaho
 
Experience: Intermediate
Platform: NinjaTrader,ToS
Broker: Amp Futures, ToS
Trading: ES, E7, CL, GC
 
zacharydw00's Avatar
 
Posts: 145 since Aug 2009
Thanks: 87 given, 172 received


Trader.Jon View 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?
Started this thread Reply With Quote
The following user says Thank You to zacharydw00 for this post:
 
(login for full post details)
  #15 (permalink)
dar17
Maharashtra,INDIA
 
 
Posts: 3 since Aug 2010
Thanks: 8 given, 1 received


Laserdan View 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

Reply With Quote
 
(login for full post details)
  #16 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,068 since Jun 2009
Thanks: 32,534 given, 98,494 received


dar17 View Post
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

You need to ask in the Amibroker section of the forum:
AmiBroker - Big Mike's Trading Forum

Unfortunately, not many participants there. Please ask your Amibroker friends to come join us and start sharing. You should also share what you have.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > how to extract nearest support price from arraylist?


Last Updated on January 1, 2012


Upcoming Webinars and Events

NinjaTrader Indicator Challenge!

Ongoing

Journal Challenge w/$1,800 in prizes!

May 7

The Cold Hard Truth: Maybe I Am Not Good Enough w/Chris Gray @ Earn2Trade

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts