Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Indciators and conditions Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jackmanjls
Posted : Thursday, March 10, 2011 8:18:21 PM
Registered User
Joined: 9/28/2009
Posts: 135

RE: SF, RCode, BScanner
Refer to this post by BruceL dated: Thurs, Sept. 17, 2009 10:20:54 AM as the "initial post".

Bruce I know that "you are not a programmer" but I need to at least try to get headed in the right direction.

I'm desperately searching for additional help on this. It seems like it's either impossible or extremely difficult to get any info on this within the Worden empire...but here goes. None of the documentation I've read addresses any of the questions that I have, it lacks the detail required for serious RC developement.

I'm want to use BScan for backtesting. In general, I want to create 2-conditions: Buy Rule(BR) and a Sell Rule(SR). These 2 rules will be embedded within the BuySellIndicator(BSI). I have autoloop=false which means I will sequentially evaluate each bar starting at index 0 up until index 1999 (2000 bars).

To implement this, if I use the response (refer to "initial post")  that Bruce posted, Thurs,Sept 17, 2009 2:04:41 PM as a template. It looks like I would put both the BR and SR rules in the BSI and use flags to control program flow.

The BR and SR are 2 separate rules that are created in RCode, with autoloop=false. (Q1.) Would these RC rules be created separately and then drag/dropped to BSI or are they a class within the BSI shell? 

From the manual, when the BScan condition rules are evaluated there output is either true or false. If true then none of the follwing rules will be evaluated, that is when BScan evaluates the rules and a true is found none of the follwing rules get evaluated. (Q2.) How does the evualtion of the RC take place when the conditions are in the BSI shell and autoloop=false, ie, each bar is evaluated?


To better understand what I'm trying to do a  simple example might be in order. Assume the we have the BSI indicator, within this indicator there are 2 condtional rules, BR and SR. The requirements for the BR are that when bar index is 1925(index goes from 0 to 1999) then set the BR condition to true, meaning a buy will occur. Using the BScan (TradeSignal) this would put the Buy arrow pointing to the bar that has the index of 1925. The requirements for the SR are that when the BR=true then 3 bars later generate a sell, so at bar 1925+3=1928 a sell will occur. It's the implementation of this simple example that I'm trying to decode.

Can you help?

Thanks.

Bruce_L
Posted : Friday, March 11, 2011 12:10:18 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (jackmanjls)
To implement this, if I use the response (refer to "initial post")  that Bruce posted, Thurs,Sept 17, 2009 2:04:41 PM as a template. It looks like I would put both the BR and SR rules in the BSI and use flags to control program flow.

I would probably move further down in the post as a place to start. I'd recommend my Friday, September 18, 2009 2:12:12 PM ET post as the basic template. You can look at my Monday, September 21, 2009 3:16:47 PM post for the RealCode along with an explanation.

QUOTE (jackmanjls)
The BR and SR are 2 separate rules that are created in RCode, with autoloop=false.

If I'm understanding correctly, I would not recommend this approach for what you are trying to do. You really want the Indicator to spoon feed the Conditions their results. Why?

I am not aware of a way to synchronize the evaluation of multiple Conditions. You would not be stepping through the data one Bar at a time with each Condition waiting for the other Conditions and Indicators to finish calculating the same Bar before all of the Conditions and Indicators increment to the next Bar. One Condition might be calculated completely before the second Condition starts calculating at all.

You can't feed the results of a Condition or Indicator into another Indicator until it is done calculating. For what you are trying to do, I suspect this would create dependency loops. You don't want your Buy Condition to return True if you are in the Trade, but you have no idea if you are in the Trade unless you know if your Sell Condition has returned True. You don't want your Sell Condition to return True if you aren't in a Trade, but you have no idea if you are in a Trade unless you know if your Buy Condition returns True.

QUOTE (jackmanjls)
(Q1.) Would these RC rules be created separately and then drag/dropped to BSI or are they a class within the BSI shell?

If I'm understanding this question correctly, you wouldn't want to Drag and Drop the Conditions into the Indicator. You want the Conditions to be part of the BSI Indicator.

QUOTE (jackmanjls)
From the manual, when the BScan condition rules are evaluated there output is either true or false. If true then none of the follwing rules will be evaluated, that is when BScan evaluates the rules and a true is found none of the follwing rules get evaluated. (Q2.) How does the evualtion of the RC take place when the conditions are in the BSI shell and autoloop=false, ie, each bar is evaluated?

This depends entirely on how you write and structure the BSI Indicator. I know that doesn't sound helpful, but we'll look at your simple example and maybe that will help.

QUOTE (jackmanjls)
To better understand what I'm trying to do a  simple example might be in order. Assume the we have the BSI indicator, within this indicator there are 2 condtional rules, BR and SR. The requirements for the BR are that when bar index is 1925(index goes from 0 to 1999) then set the BR condition to true, meaning a buy will occur. Using the BScan (TradeSignal) this would put the Buy arrow pointing to the bar that has the index of 1925. The requirements for the SR are that when the BR=true then 3 bars later generate a sell, so at bar 1925+3=1928 a sell will occur. It's the implementation of this simple example that I'm trying to decode.

One interpretation of this example might be to replace everything below the Inherits line in the Class tab of the RealCode Editor for a RealCode Indicator with the following (again, I am not a programmer and there are probably much better ways to do this):

    Enum Status As Integer
        NotInTrade = 0
        LongTrade = 1
        ShortTrade = 2
    End Enum
    Enum Action As Integer
        DoNothing = 0
        BuyLong = 1
        SellShort = 2
        ExitAll = 3
    End Enum
    Dim TradeAction As Integer = Action.DoNothing
    Dim TradeStatus As Integer = Status.NotInTrade
    Dim i As Integer
    Sub New
        AutoLoop = False
    End Sub
    Public Overrides Function Plot() As System.Single
        If Price.Bar.Count >= 2000 Then
            TradeStatus = Status.NotInTrade
            For i = 0 To 1999
                TradeAction = Action.DoNothing
                If TradeStatus = Status.NotInTrade Then
                    Call BuyRule
                Else If TradeStatus = Status.LongTrade Then
                    Call SellRule
                End If
                AddToOutput(Price.Bar.DateValue(i), TradeAction)
            Next
        End If
    End Function
    Private Function BuyRule As Boolean
        If i = 1925 Then
            TradeAction = Action.BuyLong
            TradeStatus = Status.LongTrade
            Return True
        Else
            Return False
        End If
    End Function
    Private Function SellRule As Boolean
        If i = 1928 Then
            TradeAction = Action.ExitAll
            TradeStatus = Status.NotInTrade
            Return True
        Else
            Return False
        End If
    End Function
End Class

You could then replace everything below the Inherits line in the Class tab of the RealCode Editor for a RealCode Condition with the following to create Buy Long Condition (the '# BSI = chart.BuySellIndicator line was created by Dragging and Dropping the Indicator from the Chart, but you could use Import Indicator instead if it was already saved):

    Enum Action As Integer
        DoNothing = 0
        BuyLong = 1
        SellShort = 2
        ExitAll = 3
    End Enum
    Sub New
        '# BSI = chart.BuySellIndicator
        AutoLoop = False
    End Sub
    Public Overrides Sub CallUserCode()
        For i As Integer = 0 To BSI.Line.Count - 1
            If BSI.Line.Value(i) = Action.BuyLong Then
                AddToOutput(BSI.Line.DateValue(i), True)
            Else
                AddToOutput(BSI.Line.DateValue(i), False)
            End If
        Next
    End Sub
End Class

You would then need to create an Exit All Condition. You would just need to change:

            If BSI.Line.Value(i) = Action.BuyLong Then

To:

            If BSI.Line.Value(i) = Action.ExitAll Then

I bet you can guess at how to get a Sell Short Condition as well.

The interpretation provided takes your example literally. It just loops through the first 2000 Bars, Buys Long on Index 1925 and Exits All on Index 1928.

I'm guessing if you were actually creating something useful, you would probably be using requirements other than the index and that when the Buy Long requirement was met you would enter. I'm also guessing you would have a variable tracking the length or Entry Index of the Trade and Exit All when you were actually in the trade for 3 Bars instead of just plugging in an index of 1928.

It should probably be noted that I declared the Conditions/Rules as Boolean so you could do something like the following and not have to test all of the Rules at each Bar:

If TradeStatus = Status.NotInTrade Then
    If Buy OrElse _
        SellShort Then
    End If
Else If TradeStatus = Status.LongTrade Then
    If RemainLong OrElse _
        RemainInTrade OrElse _
        SellShort OrElse _
        Sell OrElse _
        ExitAll Then
    End If
Else If TradeStatus = Status.ShortTrade Then
    If RemainShort OrElse _
        RemainInTrade OrElse _
        Buy OrElse _
        BuyCover OrElse _
        ExitAll Then
    End If
End If

You can rather obviously make this structure as simple or complex as you want. You could have certain Conditions/Rules only evaluated if you made a particular Entry or change the results if certain combinations of Conditions/Rules happened by actually having the If Then Else structure do something besides a call of the Conditions/Rules.

Theoretically you could have an even more complex structure allowing Entries and Exits on the same Bar, but if you did so, you would probably need to bypass BackScanner as it can only Trigger or Execute a single BackScanner Rule at each Bar. Bypassing BackScanner could also be used to allow Entries and Exits at something besides the Open, High, Low, Close or Midpoint of a Bar.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jackmanjls
Posted : Friday, March 11, 2011 8:00:29 PM
Registered User
Joined: 9/28/2009
Posts: 135
Bruce,
Thanks for the reply. I see the approach and will work on over the weekend. I'll keep you posted so that this can be used as a reference for others that might do something similiar.
Bruce_L
Posted : Monday, March 14, 2011 8:16:05 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.