Im about to blow my head off with frustration on a coding issue i cannot figure out. I have a strat i am running on daily renkos. The entry is not relevant but i am having an issue with my trailing stops in the strategy. The logic i am trying to code is relatively simple.
A trailing stop off the last pivot low that moves up after a new higher pivot low is formed. The initial stop is the higher of the last pivot low or 95% of the entry price. see code excerpt below:
if marketposition = 0 then
if condition7 then buy 100 shares next bar at market;
//Long Stop Language
Condition20 = PivotLowVSBar( 1, low,Leftstrength, rightstrength, rightstrength+1) <> -1 ; // if new pivot low forms this is true
if marketposition = 0 and condition20 then longpivotstop = Low[rightStrength]; // when flat and a new pivot low forms, the intrabarpersist variable longpivotstop is set
//equal to the Low of the bar at the new pivot
if marketposition = 1 and condition20 and Low[rightstrength]>Longpivotstop then LongPivotStop = Low[rightStrength]; // when long and a new pivot forms that is higher than the last
//pivot low, longpivotstop is reset to the new higher low.
if marketposition = 1 then begin
currentlongstop = Entryprice*.95; //sets initial stop to 5% from entryprice
If Longpivotstop > currentlongstop and longpivotstop<last then currentlongstop = longpivotstop;
Sell ( "Pivot LX" ) next bar at currentlongstop stop;
The above code seems to generally work ok but there is something i am missing. See attached screen shot i marked up.
Any ideas with what i am screwing up in my logic? its making me crazy.....
Please remember Renko's and backtesting don't go well together. Renko's have false opens, and all backtest results will be false.
Best way to troubleshoot your issue in my opinion would be to print the trailing stop price to a debug window, along with a time stamp, so you can see what is happening.
I assume if you change the dataseries to something less exotic, like a 1-range bar, that it works correctly? If so, likely the issue is the Renko bar itself and the false prices.
You could make the first dataseries a 1-range, and the second dataseries your Renko. MultiCharts only allows execution on the first dataseries. Signals could be generated from the secondary series.
Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.
Need help? 1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first. 2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses. 3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make. 4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance. 5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers. 6) Help using the forum? Watch this video to learn general tips on using the site.
If you want to support our community, become an Elite Member.
The following 3 users say Thank You to Big Mike for this post:
hey mike - i did what you said and figured out my logic issue. if anyone wants the code for trailing pivots i came up with i can post. many thanks
one quick follow up question - I am struggling with coding renkos as data2 for triggering entries and exits. my issue comes with data1 (regular minute bars) having many more bars than data2 (renkos). when there are no renkos in data2 - i get entries and exits on data1.
Im sure there is some boneheaded function i am missing. I tried using "barstatus <> = -1" but that only fixed some of my incorrect entries on data1.