Strategy with 4 triggers to be followed in sequence doesn't generate trades
Author: bcdxxx
Creation Date: 6/11/2019 2:51 PM
profile picture

bcdxxx

#1
Hi all,
I was trying to create an RSI-based momentum oscillator strategy, but for some reason can't get it to generate trades...
I feel like I must be missing something very basic here.
I am using IQFeed for data, in case that makes any difference.

Thanks for any help anyone can provide!

-bd

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

Eugene

#2
Hi Bryan,

You must have converted it from another platform as the entire code is clearly far from being "Wealth-Lab style". In particular, putting the cart (IsLastPositionActive) before the horse (main trading loop):
CODE:
Please log in to see this code.

Anyway there are other errors which prevent the not so readable code from running. If you wish to get anywhere with it you might want to express your trading rules in plain English. Looks like helping you code it from scratch may get it done faster.
profile picture

bcdxxx

#3
Hi Eugene,
Thanks for your help!
Actually, I am trying to teach myself how to code, so some of it is modified from "Rules-generated" code, and the rest is hand-coded by me. Somewhat analogous to trying to write a short story using a dictionary. :)
That last bit that you quoted was a last-second addition that I thought I could skate by and throw in there to decrease computing cycles by eliminating extraneous cycles. I should have structured it more appropriately with curly braces before posting, my apologies.

The idea is this:
Exit Criteria (3 of them):
Stop loss of x% (let's just say 3% in the example)
Profit of y% (3% in this example also)
Sell at end of day

Entry Criteria (1 entry criteria with 5 steps):
I'll describe below is a series of 4 triggers to be followed in sequence:
1) If RSI is falling (RSI[t]<RSI[t-1]), and RSI < Trigger 1 variable (Trigger 1 default 30)
2) Next trigger is RSI > Trigger 2 variable (Trigger 2 default 50)
3) 3rd trigger is RSI < Trigger 3 variable (Trigger 3 default 40)
4) 4th Trigger is waiting time delay (default 5 minutes/bars) to be sure no further dropping of price beyond the daily low (thus far)
After hitting all 4 triggers in order, time for action (buy). If RSI < Trigger 1, need to start back at Trigger 1.
5) Buy price set at the Daily Low (thus far) * (a fudge factor) . (default fudge factor 0.5%)

thanks again.
-bd
profile picture

Eugene

#4
Thanks, it starts to make sense now.
QUOTE:
I'll describe below is a series of 4 triggers to be followed in sequence:

Could you clarify what does "in sequence" mean? They all have to trigger in the exact order, right? (e.g. RSI falls below 30, then jumps above 50, then again drops below 40 etc.
profile picture

bcdxxx

#5
Yes, they have to trigger in order 1->2->3->4, then set buy price
profile picture

Eugene

#6
OK I'm on it. Will get back to you with code soon.
profile picture

bcdxxx

#7
Thanks so much Eugene! You're the best!
profile picture

Eugene

#8
Here you have it. When it comes to sequenced conditions (1->2->3->4), the natural solution is to apply this design pattern: Tutorial: Setups, Triggers, Delays, and Timeouts. Your conditions are nested which makes the resulting code a bit less readable. Hope this helps.

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

bcdxxx

#9
Eugene,
you are amazing!
Thanks so much. I have so much to learn.
Have a great night.
-bd
profile picture

Eugene

#10
Bryan,

Thanks for the kind words. Was glad to help. If you encounter any issues don't hesitate to ask (and exemplify it with symbol, bar scale and data range).
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).