Trade Once per Data2 Bar  [SOLVED]

Questions about MultiCharts and user contributed studies.
crescendo
Posts: 1
Joined: 23 Sep 2016

Trade Once per Data2 Bar

Postby crescendo » 23 Sep 2016

Hello,

Attempting to create a signal that uses two data streams of the same symbol. Data1 is time. Data2 is renko.

The idea requires that there be one entry per data2 bar created, directly proceeding the closure of the data2 bar, I believe this means the actual trade would occur at the closure of the very next data1 bar, correct? All calculations should be based upon data2, except for the actual entry/exit trade which requires use of data1.

I think I am missing a basic concept somewhere in here. I've tried counting bars based upon barstatus change, however, my commentary is clearly showing that's not coded correctly (so did not add it as an entry signal requirement). I am both way off in counting data1 bars after a completed data2 bar, just counting data2 bars in general, and how to accomplish the original idea of just one entry directly after a formed data2 bar and not allowing a trade to occur until that data2 bar forms after an exit of a trade.

Requesting assistance from the community to please advise of an easier, and successful way to accomplish this goal.

I would think that just a simple:

Code: Select all

if barstatus(2) = 2 then begin barcount = barcount + 1 ; end ;
would successfully count data2 bars each time a a data2 bar closes, yet commentary on chart shows this does not work.


Sample code, that does not work successfully, to trade only after a data2 bar is as below:

Code: Select all

inputs: Quantity ( 1 ) , __PRICECHANNEL__ ( "PriceChannel" ), PC_ENTRY_ONOFF ( 1 ) , PCEntrylength ( 10 ),
ProfitTargetAmt ( 100), StopLossAmt ( 50 ) ;

variables:
{PRICE CHANNEL} HIGHESTHIGHSIGNAL ( 0 ), LOWESTLOWSIGNAL ( 0 ), PcUpperBand ( 0, data2 ), PcLowerBand( 0, data2 ), Price ( 0, data2 ) ,
{barcount} barcount ( 0 ) ;
Price = Close data2;

PcUpperBand = Highest( High data2, PCEntrylength )[1] data2; PcLowerBand = Lowest( Low data2, PCEntrylength )[1] data2;

IF PC_ENTRY_ONOFF = 0 then begin HIGHESTHIGHSIGNAL = 1; LOWESTLOWSIGNAL = 1; end
else if PC_ENTRY_ONOFF = 1 then BEGIN
if Price > PcUpperBand then begin HIGHESTHIGHSIGNAL = 1 ; end else HIGHESTHIGHSIGNAL = 0;
IF Price < PcLowerBand then begin LOWESTLOWSIGNAL = 1 ; end else LOWESTLOWSIGNAL = 0; end ;

if HIGHESTHIGHSIGNAL = 1 then begin Buy ( "LONG" ) Quantity shares THIS bar CLOSE; end ;
if LOWESTLOWSIGNAL = 1 then begin SellShort ( "SHORT" ) Quantity shares THIS bar CLOSE ; end ;

if ProfitTargetAmt > 0 then SetProfitTarget( ProfitTargetAmt ) ;
SetStopPosition ; if StopLossAmt > 0 then SetStopLoss( StopLossAmt ) ;




if barstatus(2) = 2 then begin barcount = 0 ; end ;
if barcount = 0 then begin barcount = barcount + 1 ; end ;

if AtCommentaryBar then begin CommentaryCl( "PcUpperBand : ", PcUpperBand ) ;
CommentaryCl( "PcLowerBand: ", PcLowerBand) ; CommentaryCl( "Price : ", Price ) ; CommentaryCl( "barstatus(1): ", barstatus(1)) ;
CommentaryCl( "barstatus(2): ", barstatus(2)) ; CommentaryCl( "barcount : ", barcount ) ; end ;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trade Once per Data2 Bar  [SOLVED]

Postby TJ » 23 Sep 2016

Hello,
::
I would think that just a simple:

Code: Select all

if barstatus(2) = 2 then begin barcount = barcount + 1 ; end ;
would successfully count data2 bars each time a a data2 bar closes, yet commentary on chart shows this does not work.
::
This will never work.

Go back to read and understand the construct of renko.

By definition, renko is a hindsight. There is no barstatus=2.



PS. Renko is never good on matching backtest result with real life trading. That's just the nature of the beast. I would not spend too much time going into the rabbit hole. YMMV.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Trade Once per Data2 Bar

Postby tony » 23 Sep 2016

I love using multiple data series, but MC has limitations with backtesting such strategies. If you reference prior bars on Data2, etc then it's less of an issue and if you do not use IOG then it's almost a non-issue. But if you have an intraday scalping strategy that relies on tick data, then just be on notice that your backtest results will somewhat differ from production.


Return to “MultiCharts”