How to create an indicator that references the number of bars in a trade?
Author: mikesblack
Creation Date: 2/16/2016 3:08 PM
profile picture

mikesblack

#1
I wish to plot the results of each trade using a sharp indicator which I created. As the number of bars vary based on each trade I created the indicator and PlotSeries for the sharp ratio indicator in the scope of the trading loop sell conditions as follows:

CODE:
Please log in to see this code.
I'm aware that I shouldn't do this in the trading block of code as I have shown above. Where would I write this code and how?

Thank you
profile picture

Eugene

#2
CODE:
Please log in to see this code.
profile picture

mikesblack

#3
Thank you Eugene.
profile picture

Eugene

#4
Got interrupted.

Using .Series would lead to invalid results due to caching: the DataSeries would be only created once. So when populating such dynamic indicators, the idea is to call the .Value method (if available; most Community indicators do not implement it).
profile picture

mikesblack

#5
Eugene,
I used what you wrote and am getting satisfactory results. Is there anything glaringly wrong? Code below:
CODE:
Please log in to see this code.
profile picture

Eugene

#6
Other than I don't see the connection of this incomplete code to the orignal task - perhaps no, nothing's wrong.

P.S. Keep in mind my comment in post #4.
profile picture

mikesblack

#7
I see that I pasted the wrong code. I'll send my example shortly.
profile picture

mikesblack

#8
Eugene,

I applied the above code to the following system. I've included a PDF of the resulting charts from your code and from my code. My example shows missing lines during some of the trades while your example has all bars during the trade showing the indicator. The good thing is that the sharp indicator is being displayed on the trades page. Can you tell why this is happening with the charts?
BTW The example that I mentioned in post #5 is on my home PC. I'm away from home and using my laptop. I just created the following system a moment ago.

CODE:
Please log in to see this code.
profile picture

Eugene

#9
Mike, you can (and should) troubleshoot your code yourself. The QuickRef has an example on how to use PrintDebug, the simplest troubleshooting tool available. When you learn to insert it into your code (or an alternative like AnnotateBar), you're going to notice the value at a given bar. In short, what you'll probably find is that the indicator value at such bars is invalid and therefore is assigned a zero.
profile picture

mikesblack

#10
Eugene,
I haven't used the Print Debug tool. Even using the example give in quick ref, I'm not sure how to apply it or how to interpret it. As for this example, where would I write PrintDebug? I have an example code and debug log pdf attached
profile picture

Eugene

#11
I would insert PrintDebug right after the code finishes assigning the indicator value.
profile picture

mikesblack

#12
In addition, please explain
CODE:
Please log in to see this code.

I don't know what this means exactly.

Also, why in certain cases the indicator is assigned a 0 in my example case, while in your example no such case occurs?
profile picture

Cone

#13
Mikes.. these are browser search questions. Google double.IsInfinity, for example. Repeat for double.IsNaN.
profile picture

Eugene

#14
QUOTE:
Also, why in certain cases the indicator is assigned a 0 in my example case, while in your example no such case occurs?

Since this is your indicator, understanding and troubleshooting it is yours.
profile picture

mikesblack

#15
Thanks Robert and Eugene. I will search Google accordingly. Eugene, I am trying to get a handle on it. I wouldn't have arrived at it if it wasn't for your generous offering of the code. Now I'm playing catch up to understand how it work and why it doesn't under different circumstances. Perhaps after I have a good grip on .IsInfinity and .IsNaN ,I might be able to answer my own question. I hope.

You guys, have a great rest of your weekend.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).