Topic: Using Indicator as stop loss

(moved from Tracing Techniques)

Re: Using Indicator as stop loss

Thanks Krog for all this work again smile

I will have to play with this to fully understand it
when i look at coding, i tend to follow the logic but the structure or the grammar of it is just eluding me (for now)
i will try not to ask for too much of your time, as it seems like you are helping everyone... i like the Gann project you are working on, it looks promising. smile
one question,  is it possible to set the a stop loss to an indicator value?  what i have in mind is to use Ross Hook value as a sl and add extra few pips for protection

Re: Using Indicator as stop loss

dr.B wrote:

Thanks Krog for all this work again smile

I will have to play with this to fully understand it
when i look at coding, i tend to follow the logic but the structure or the grammar of it is just eluding me (for now)
i will try not to ask for too much of your time, as it seems like you are helping everyone... i like the Gann project you are working on, it looks promising. smile
one question,  is it possible to set the a stop loss to an indicator value?  what i have in mind is to use Ross Hook value as a sl and add extra few pips for protection

Hi dr.B,
Please feel free to ask, I'm happy to help people to be able to code.

It is not possible to make an indicator as a stop for a specific position; indicators do not have information about positions. It has to be coded into FSB, then has to be coded into FST. If the indicator is used a stop, the value changes with the indicator, so then becomes a closing indicator.

Re: Using Indicator as stop loss

krog wrote:

It is not possible to make an indicator as a stop for a specific position; indicators do not have information about positions. It has to be coded into FSB, then has to be coded into FST. If the indicator is used a stop, the value changes with the indicator, so then becomes a closing indicator.

Hi Krog smile
I see... hmm  i guess one can always shift the indicator up or down to get the same effect and then use it as a closing ind.
Q.
I was trying to set a tracer as u described  for the Ross Hook Ind, and got this error from  FSB
Line 76 Column 29: 'Forex_Strategy_Builder.Bar' is a 'type' but is used like a 'variable'.
I assume that i have to define the tracer somewhere as a variable how and where do i do that?
Thanks

Re: Using Indicator as stop loss

dr.B wrote:

Hi Krog smile
I see... hmm  i guess one can always shift the indicator up or down to get the same effect and then use it as a closing ind.
Q.
I was trying to set a tracer as u described  for the Ross Hook Ind, and got this error from  FSB
Line 76 Column 29: 'Forex_Strategy_Builder.Bar' is a 'type' but is used like a 'variable'.
I assume that i have to define the tracer somewhere as a variable how and where do i do that?
Thanks

My first guess, you have 'Bar' with a capital B. It looks like you are trying to get the bar number -- try 'iBar' instead. It should match what's in the for loop, for Ross Hook:

for (int iBar = 5; iBar < Bars - 1; iBar++)

Also, be sure you are in the for loop -- from the curly brace ({) just after to the closing curly brace (}) at the same indentation. If you are outside, you will get an error message like " 'iBar' is not defined in this scope", or something about not defined.

Let me know if that works, if not paste the for-loop code you have and I'll take a look.

thanks
krog

Re: Using Indicator as stop loss

krog wrote:

My first guess, you have 'Bar' with a capital B. It looks like you are trying to get the bar number -- try 'iBar' instead. It should match what's in the for loop, for Ross Hook:

for (int iBar = 5; iBar < Bars - 1; iBar++)

Also, be sure you are in the for loop -- from the curly brace ({) just after to the closing curly brace (}) at the same indentation. If you are outside, you will get an error message like " 'iBar' is not defined in this scope", or something about not defined.

Let me know if that works, if not paste the for-loop code you have and I'll take a look.

thanks
krog


yup that did it
Thanks

Re: Using Indicator as stop loss

Hi Krog
All your help has been great, I just spend my weekend tinkering with C#, as the result I just wrote my first program smile ( borrowing heavily from other examples )
it's not much of a filter, just an exercise to see if  I  have grasp the logic and the basics. the FST seems to run fine  however when i try to test it on FST it loads ok but  it fails to open a position .  The  behavior shows "repainting "of Short allowed or Long allowed , I can't figure it out... any thoughts?
Thanks

Re: Using Indicator as stop loss

Does it open trades in backtesting in FSB?

Is the indicator used as an Open Slot (indicator on first slot in strategy), or as an OpenFilter (Bar Opening or Bar Closing in first slot, then indicator comes after)?

Here are a few ideas to search:

Ambiguous Bars (most likely) -- sometimes the indicator gives a long and short signal at the same time in the bar. Then, FSB / FST does not open a position, it cannot decide which one. To see if you have a lot: FSB -- click the exclamation mark button (with "!") in the price chart view. If you see a lot of exclamation marks over the price data, it supports this. When you mouse over, the dynamic info on the right will show:
Is long entry allowed    Yes
Is short entry allowed   Yes
Check your code separates them, or add another indicator to strategy to decide.

Repainting (somewhat likely) -- do you mean, ex, 3 previous bars say "short", then when the next bar comes, the previous 3 bars change to "long"?
I have done this when I compare current bar with previous bars, then set previous bars in the indicator array to the current indicator value.
Ex (don't do this):

if (High[iBar] > High[iBar-2] && High[iBar] > High[iBar-1]) {
   highCurrentValue = High[iBar];
}
adHighestValues[iBar] = highCurrentValue;
adHighestValues[iBar-1] = highCurrentValue;
adHighestValues[iBar-2] = highCurrentValue;

Here, I wanted to draw a continuous line of the highest value, but it will repaint because I am setting [iBar-2] and [iBar-1] in adHighestValues (indicator array) from new info in the current bar. Be sure only setting the current bar [iBar].

Typos (somewhat likely)
- check do not have "Enter Time", "Day of Week" or "Enter Once" slots in strategy

- Component section -- for the component with "Is long entry allowed", verify DataType is AllowOpenLong, should look like:
Component[4].DataType = IndComponentType.AllowOpenLong;
same for Short

- Indicator Logic section -- verify ref Components are correct, should look like:
OscillatorLogic(iFirstBar, iPrvs, adHighLowOsc, 0, 0, ref Component[4], ref Component[5], IndicatorLogic.The_indicator_rises);
check that the numbers in brackets (4 and 5 for my example) are the same component numbers as your AllowOpenLong and AllowOpenShort components

Let me know how that goes, hope that helps

Re: Using Indicator as stop loss

Also, for more info to figure out what the Component functions do to decide out allowing long or short, here is the source:
https://github.com/PopovMP/Forex-Strate … tor%20base

Click on Indicator.cs, then towards the bottom it has the functions.

For built-in indicators' source:
https://github.com/PopovMP/Forex-Strate … Indicators

Re: Using Indicator as stop loss

Thanks Krog!!!! smile smile
this is a lot to digest at once. I am sure that this will help smile
I will let you know how i am progressing. if i am realy stuck i will post the code... but i like to figure it out by my self, I learn better when i do smile