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 |

Help convert TQI Amibroker formula to PCF Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
ez2000
Posted : Wednesday, April 2, 2014 8:21:15 PM
Registered User
Joined: 3/29/2014
Posts: 1

Hi I am doing a platinum trial of TQ2000 and so far I find it a very good charting platform but there is one stumbling block that is preventing me from migrating away from AMIBROKER and that is this formula.

Can somebody help me convert this amibroker formula to pcf?

 

_SECTION_BEGIN("");
// Piecewise EMA is an EMA that restarts calculations each time
// the 'sincebar' argument is true
function PiecewiseEMA( array, range, sincebar )
{
  factor = IIf( sincebar, 1, 2/(range+1) );
  return AMA2( array, factor, 1-factor );
}
// parameters
m=4;
n=250;
// generate reversal signals based on EMA crossover rule
Lpf1 = EMA( C, 7  );
Lpf2 = EMA( C, 15 );
CrossPoint = Cross( Lpf1, Lpf2 ) OR Cross( Lpf2, Lpf1 );
Periods = BarsSince( CrossPoint );
// variable bar sum
DC = Close - Ref( Close, -1 );
CPC = Sum( DC, Periods );
// smooth CPC by piecewise 4 bar EMA
Trend = PiecewiseEMA( CPC, 4, CrossPoint );
// noise
DT = CPC - Trend;
Noise = 2 * sqrt( MA( DT^2, n ) );
// alternative 'linear' noise calculation
// Noise = 2 * MA( abs( DT ), n ) );
QIndicator = Trend/Noise;
Plot( Qindicator, "Qindicator", ParamColor( "Color", colorCycle ), styleHistogram, ParamStyle("Style") );
 
PlotGrid( 0, colorBlack );
 
_SECTION_END();
 

 

Bruce_L
Posted : Thursday, April 3, 2014 9:31:15 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

It is possible to get as far as calculating DT, but any formula for Noise and QIndicator ends up being way too long and slow to be practical or post in the forums.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
cpolaritz
Posted : Thursday, April 10, 2014 3:13:46 PM
Registered User
Joined: 12/30/2004
Posts: 123

Having never used AMIBroker, Is the noise cancel a big improvement to the base calculation? Could we take a look at DT?

rivels
Posted : Monday, March 6, 2017 3:05:23 PM
Registered User
Joined: 11/4/2010
Posts: 1

Hi I using TC2000 .

Can somebody help me convert this amibroker formula to pcf?

 

_SECTION_BEGIN("Magic Trend Indicator Update");

SetBarsRequired(sbrAll,sbrAll);

SetFormulaName( "Magic Trend Indicator Update" );

SetOption( "Initialequity", 100000 );

SetOption( "AccountMargin", 0.25 );

SetOption( "MinShares", 1 );

MaxOpenPos = Param( "MaxOpenPos", 20, 1, 200, 1 );

SetOption( "MaxOpenPositions", MaxOpenPos );

SetOption( "PriceBoundChecking", 1 );

SetOption( "CommissionMode", 1 );

SetOption( "CommissionAmount", 0.01 );

PositionSize = -400 / ( MaxOpenPos );

P = Param("Period",20,2,25,1);

m = Param("Multiplier",3,0.1,5,0.1);

A = ATR(P);

for(i=0;i<P;i++)

{

 S[i] = C[i]-m*(A[i]);

 T[i] = 1;

}

for(i=P;i<BarCount;i++)

{

 if(C[i] > S[i-1])

 {

 if(T[i-1]==1)

 {

 S[i] = Max(C[i] - m*A[i],S[i-1]);

 T[i] = 1;

 }

 else

 {

 S[i] = C[i] - m*A[i];

 T[i] = 1;

 }

 

 }

 else

 {

 if(T[i-1]==-1)

 {

 S[i] = Min(C[i] + m*A[i],S[i-1]);

 T[i] = -1;

 }

 else

 {

 S[i] = C[i] + m*A[i];

 T[i] = -1;

 }

 }

}

Buy = Cover = C>S;

Short = Sell = C<S;

Buy = ExRem(Buy,Sell OR Short);

Sell = ExRem(Sell,Buy);

Short = ExRem(Short,Cover OR Buy);

Cover = ExRem(Cover,Short);

BuyPrice = ValueWhen(Buy,C,1);

SellPrice = ValueWhen(Sell,C,1);

ShortPrice = ValueWhen(Short,C,1);

CoverPrice = ValueWhen(Cover,C,1);

Offset = -12;

PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,Min(S,L),Offset);

PlotShapes(Short*shapeDownArrow,colorRed,0,Max(S,H),Offset);

PlotShapes(Cover*shapeHollowUpArrow,colorBrightGreen,0,Min(S,L),Offset);

PlotShapes(Sell*shapeHollowDownArrow,colorRed,0,Max(S,H),Offset);

SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Plot(S,"STOP",IIf(C>S,colorBrightGreen,colorRed),styleDots|styleStaircase|styleThick|styleNoTitle );

PlotOHLC(O,H,L,C,"Close",colorDefault,styleCandle|styleNoTitle);

GfxSetOverlayMode(1);

GfxSelectFont("Verdana", 12, 800, True );

GfxSetBkMode(0);

GfxSetTextColor(ColorRGB(18,18,18));

GfxTextOut("Created By: Rakesh Solanki", 800 , 430 );

GfxSelectFont("Verdana", 14, 800, True );

GfxSetBkMode(1);

GfxTextOut("www.nascenttraders.com" , 800 ,400 );

Open_Long = Flip( Buy, Sell );

Open_Short = Flip( Sell, Buy );

Buy_Price = ValueWhen( Buy, BuyPrice, 1 );

Short_Price = ValueWhen( Short, ShortPrice, 1 );

Sell_Price = IIf( Sell, ValueWhen( Sell, SellPrice, 1 ), Short_Price );

Cover_Price = IIf( Cover, ValueWhen( Cover, CoverPrice, 1 ), Buy_Price );

Profit = IIf( Open_Long, ( Close - Buy_Price ), IIf( Open_Short, ( Short_Price - Close ), 0 ) );

Last_Profit = IIf( Ref( Open_Long, -1 ) == 1 AND Open_Long != 1, ( Sell_Price - Buy_Price ), IIf( Ref( Open_Short, -1 ) == 1 AND Open_Short != 1, ( Short_Price - Cover_Price ), 0 ) );

Cum_Profit[0] = Last_Profit[0];

PreviousProfit = ValueWhen(Last_Profit!=0,Last_Profit,1);

for ( i = 1;i < BarCount;i++ )

{

 Cum_Profit[i] = Cum_Profit[i-1] + Last_Profit[i];

}

Trade[0] = 0;

for ( i = 1;i < BarCount;i++ )

{

 if ( Buy[i] == 1 OR Short[i] == 1 )

 {

 Trade[i] = Trade[i-1] + 1;

 }

 else

 {

 Trade[i] = Trade[i-1];

 }

}

// Trade Report //

TR = ParamToggle( "Trade Report", "Show|Hide", 1 );

 

if ( TR == 1 )

{

 GfxSelectFont( "Verdana", 10, 100 );

 GfxSetBkMode( 1 );

 GfxSetTextColor( ColorRGB(50,50,50) );

 y = Status( "pxchartheight" );

 

 GfxTextOut( ( "Total Trades : " + WriteVal( Trade, 3.0 ) ), 13, y - 125 );

 GfxTextOut( ( "Total Profit : " + WriteVal( Cum_Profit, 4.2 ) ), 13, y - 100 );

 GfxTextOut( ( "Previous Profit : " + WriteVal( PreviousProfit, 2.2 ) ), 13, y - 50 );

 GfxTextOut( ( "Price : " + WriteVal( Close, 2.2 ) ), 13, y - 75 );

 GfxTextOut( ( "Current Profit : " + WriteVal( Profit, 2.2 ) ), 13, y - 25 );

}

_SECTION_END();

Bruce_L
Posted : Monday, March 6, 2017 4:13:38 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I am pretty sure I don't completely understand the code, but I also can't think of a way to convert the code I can understand into a PCF.



-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.