Swing levels  [SOLVED]

Questions about MultiCharts and user contributed studies.
Samuel187
Posts: 3
Joined: 09 Jul 2019
Location: Italy
Has thanked: 2 times

Swing levels

Postby Samuel187 » 09 Jul 2019

Hi,
I'm trying to code a strategy and now I would need to insert a filter based on support/swing levels.
Basically, I'll buy only if the swing level has been crossed by this bar or the previous one.

In order to find the swing levels I was thinking about giving these rules :
I'll take as a swing level the low of a bar, only if this low is lower than the previous 6 bars lows and lower then the next 6 bars lows
So, I'm taking lows of the market as my "swing levels", and a trade can occur only if one level has just been crossed.

Although until now I could find solutions to code my system by myself, I now have no clue on how to insert this swing level filter...
So, even though I'm not asking anyone to do the hard work of coding this for me :D I'd really appreciate any suggestion on how to move on...

I was thinking that maybe, instead of coding how to find these levels in the code of the signal, I could create an indicator that can do this (if it does not already exist) but then, I don't know how to reference to the indicator when I'm writing the signal code, so, if the indicator finds a level at 100.0 , how can I write in my code that I have to look at this 100.0 level ?

Hope I was clear enough :)
Any suggestion will be very much appreciated
Thank you
Samuel

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Swing levels

Postby TJ » 09 Jul 2019

See post #6
Developing Your Strategy
viewtopic.php?t=11713

Samuel187
Posts: 3
Joined: 09 Jul 2019
Location: Italy
Has thanked: 2 times

Re: Swing levels

Postby Samuel187 » 10 Jul 2019

Those are examples of the levels I'm looking for, I'd need the system to trade only on the bars that just crossed those levels, (or if the previous bar crossed the level it's ok)
Any suggestion on how to do this?

Should I write an indicator to draw these levels? If so, how can I refer to the indicator when writing the signal code?

Thank you!

Image

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Swing levels

Postby ABC » 10 Jul 2019

Samuel187,

an indicator might make sense to visualize the levels and see if your code detects the levels you have in mind, but to keep the strategy simple I would put the logic inside the strategy code, too.

Regards,

ABC

Samuel187
Posts: 3
Joined: 09 Jul 2019
Location: Italy
Has thanked: 2 times

Re: Swing levels

Postby Samuel187 » 10 Jul 2019

Samuel187,

an indicator might make sense to visualize the levels and see if your code detects the levels you have in mind, but to keep the strategy simple I would put the logic inside the strategy code, too.

Regards,

ABC
Hi ABC thank you for your answer,

I'll try to write it into the strategy code, but I'm not sure on how to refer to these levels.

I have an idea on the rules to find these swing levels, which are pretty simple: if the low is lower than the previous 6 bars and lower than the next 6 bars, then this low is a swing point, which should be used 1 time only, so when crossed once, it should not be used anymore in the future...

But I'm not sure on how to insert this in a code that is compiled every time a new bar closes...
The first thing that I thought was to write to go back (every time) to the last (example 100 bars) and check any single one of them to see if it made a swing point,,, so check if the last bar made a swing, check the bar before, the bar before and so on 100 times :o
But I don't think this is the best way :?

Can you suggest an easier way?
Thank you!

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Swing levels  [SOLVED]

Postby ABC » 11 Jul 2019

Samuel187,

the built-in Pivot function does pretty much what you describe and you can take a look at the code for ideas. However it might be more efficient to go bar by bar as the chart progresses and check if your conditions are fulfilled (i.e. count bars with lower lows etc. in variables). You might need an array or a list to store the swing points that you detected and remove them once they are crossed.

Regards,

ABC


Return to “MultiCharts”