Simple Coding Help - No Promise.

HI DEAR Happy_Singh
WILL YOU PLZ ADD TREND LINE TO CCI LIKE THAT RSI
HTML:
_SECTION_BEGIN("CCI");
periods = Param( "Periods", 14, 2, 200, 1 );
Plot( CCI( periods ), _DEFAULT_NAME(), ParamColor( "Color",  colorCycle ), ParamStyle("Style")  );
_SECTION_END();

Just replace all the RSI with CCI and you are done, :thumb:

you should try these things out on your own . . .

although they call it bugs but the code does not actually come out and bite you back :D


Code:
// CCI TRENDLINE formula ver 1.0

SetBarsRequired(sbrAll, sbrAll);                                                        
TP = Param("Trend Per", 300,2,1000);                                                                
per_RSI= Param("RSI Per", 14, 7, 35,1);
IND =  CCI(per_RSI);                                                                                                      
Center = 0 ;

Plot( CCI(per_RSI), "", 4, 4);     
Plot(0,"",1,1) ;

// CALCULATE  UPTREND

startvalue = LastValue( LLV( IND, TP ) );                                                                          
startbar =  LastValue( ValueWhen( IND == startvalue, BarIndex(), 1) );                      
BP = BarCount - Startbar;                                                                                            

secondvalue =  LastValue( LLV( IND, BP - 5  ) );                                                       
secondbar =  LastValue( ValueWhen( IND == secondvalue, BarIndex(), 1) );            
BP2 = BarCount - secondbar;  

thirdvalue =  LastValue( LLV( IND, BP2 - 5 ) );                                                    
thirdbar =  LastValue( ValueWhen( IND == thirdvalue, BarIndex(), 1) );             
BP3 = BarCount - thirdbar;  

fourthvalue =  LastValue( LLV( IND, BP3 - 5 ) );                                                       
fourthbar =  LastValue( ValueWhen( IND ==fourthvalue, BarIndex(), 1) );         
BP4 = BarCount - fourthbar;  

fifthvalue =  LastValue( LLV( IND, BP4 - 5 ) );                                                    
fifthbar =  LastValue( ValueWhen( IND ==fifthvalue, BarIndex(), 1) );       
BP5 = BarCount - fifthbar;  

sixthvalue =  LastValue( LLV( IND, BP5 - 5 ) );                                             
sixthbar =  LastValue( ValueWhen( IND ==sixthvalue, BarIndex(), 1) );         

Low_1= IIf( BarIndex() == startbar, 80, Null);
Low_2= IIf( BarIndex() == secondbar, 80, Null);
Low_3= IIf( BarIndex() == thirdbar, 80, Null);
Low_4= IIf( BarIndex() == fourthbar, 80, Null);
Low_5= IIf( BarIndex() == fifthbar, 80, Null);
Low_6= IIf( BarIndex() == sixthbar, 80, Null);

b = startvalue ;    
FirstSlope = (secondvalue - b) / (secondbar - startbar) ;
FirstTrendline = FirstSlope * ( BarIndex() - startbar ) + b;                                                             
// Plot(  IIf(  BarIndex() >= startbar  AND FirstTrendline <= 90 , FirstTrendline, Null ) , "FirstTrendline", colorGreen, styleThick +2048 );        

SecondSlope = (thirdvalue - b) / (thirdbar - startbar) ;
SecondTrendline = SecondSlope * ( BarIndex() - startbar ) + b;                                                              

ThirdSlope = (fourthvalue - b) / (fourthbar - startbar) ;
ThirdTrendline = ThirdSlope * ( BarIndex() - startbar ) + b;  

FourthSlope = (fifthvalue - b) / (fifthbar - startbar) ;
FourthTrendline = FourthSlope * ( BarIndex() - startbar ) + b;  

FifthSlope = (sixthvalue - b) / (sixthbar - startbar) ;
FifthTrendline = FifthSlope * ( BarIndex() - startbar ) + b;  

MainSlope = IIf( FirstSlope > SecondSlope,  IIf( SecondSlope > ThirdSlope,  IIf( ThirdSlope > FourthSlope, 
 IIf( FourthSlope >  FifthSlope,  FifthSlope, FourthSlope),ThirdSlope), SecondSlope), FirstSlope) ;

MainLine = MainSlope * ( BarIndex() - startbar ) + b;    
Plot(  IIf(  BarIndex() >= startbar, MainLine, Null ) , "MainLine", colorDarkGreen, styleThick ) ;   


IND_Diff = IIf(  BarIndex() >= startbar, abs( IND - MainLine), Null) ;
MainTrendLine_Diff = Param("Difference IND from MainTrendLine", 2.5, 0.5,5,  0.5);

Cond_Buy = IIf( BarIndex() >= Thirdbar AND  IND_Diff  <= MainTrendLine_Diff, IND, 0)  AND  MainLine < 55 ;

PlotShapes( IIf( Cond_Buy, shapeUpArrow , shapeNone ), colorGreen );



/////////////////////////////////////////////

// CALCULATE  DOWNTREND

starthigh = LastValue( HHV( IND, TP ) );                                                                         
starthighbar =  LastValue( ValueWhen( IND == starthigh, BarIndex(), 1) );                
HBP = BarCount - starthighbar;                                                                                   

secondhigh =  LastValue( HHV( IND, HBP - 5  ) );                                                    
secondhighbar =  LastValue( ValueWhen( IND == secondhigh, BarIndex(), 1) );      
HBP2 = BarCount - secondhighbar;  

thirdhigh =  LastValue( HHV( IND, HBP2 - 5 ) );                                                    
thirdhighbar =  LastValue( ValueWhen( IND == thirdhigh, BarIndex(), 1) );            
HBP3 = BarCount - thirdhighbar;  

fourthhigh =  LastValue( HHV( IND, HBP3 - 5 ) );                                                         
fourthhighbar =  LastValue( ValueWhen( IND ==fourthhigh, BarIndex(), 1) );           
HBP4 = BarCount - fourthhighbar;  

fifthhigh =  LastValue( HHV( IND, HBP4 - 5 ) );                                                   
fifthhighbar =  LastValue( ValueWhen( IND ==fifthhigh, BarIndex(), 1) );         
HBP5 = BarCount - fifthhighbar;  

sixthhigh =  LastValue( HHV( IND, HBP5 - 5 ) );                                                
sixthhighbar =  LastValue( ValueWhen( IND ==sixthhigh, BarIndex(), 1) );           

High_1= IIf( BarIndex() == starthighbar, 90, Null);
High_2= IIf( BarIndex() == secondhighbar, 90, Null);
High_3= IIf( BarIndex() == thirdhighbar, 90, Null);
High_4= IIf( BarIndex() == fourthhighbar, 90, Null);
High_5= IIf( BarIndex() == fifthhighbar, 90, Null);
High_6= IIf( BarIndex() == sixthhighbar, 90, Null);

MainTrendLine_Diff = Param("Difference IND from MainTrendLine", 2.5, 0.5,7,  0.5);

d = starthigh ;    
FirstDownSlope = (secondhigh - d) / (secondhighbar - starthighbar) ;
FirstDownTrendline = FirstDownSlope * ( BarIndex() - starthighbar ) + d;                                                               

SecondDownSlope = (thirdhigh - d) / (thirdhighbar - starthighbar) ;
SecondDownTrendline = SecondDownSlope * ( BarIndex() -  starthighbar ) + d;                                                          

ThirdDownSlope = (fourthhigh - d) / (fourthhighbar - starthighbar) ;
ThirdDownTrendline = ThirdDownSlope * ( BarIndex() - starthighbar ) + d;  

FourthDownSlope = (fifthhigh - d) / (fifthhighbar - starthighbar) ;
FourthDownTrendline = FourthDownSlope * ( BarIndex() - starthighbar ) + d;  

FifthDownSlope = (sixthhigh - d) / (sixthhighbar - starthighbar) ;
FifthDownTrendline = FifthDownSlope * ( BarIndex() - starthighbar ) + d;  

MainDownSlope = IIf( FirstDownSlope < SecondDownSlope,  IIf( SecondDownSlope < ThirdDownSlope,  
IIf( ThirdDownSlope < FourthDownSlope,  IIf( FourthDownSlope <  FifthDownSlope, FifthDownSlope, FourthDownSlope),ThirdDownSlope), SecondDownSlope), FirstDownSlope) ;

MainDownLine =  IIf( MainDownSlope == 0, Null, MainDownSlope * ( BarIndex() - starthighbar ) + d ) ;    
Plot(  IIf(  BarIndex() >=  starthighbar, MainDownLine, Null ) , "Main_DOWN_Line", colorViolet, styleThick ) ;    

IND_Diff = IIf(  BarIndex() >=  starthighbar, abs( IND - MainDownLine), Null) ;

Cond_Sell = IIf( BarIndex() >= Thirdbar AND  IND_Diff  <= MainTrendLine_Diff, IND, 0)  AND  MainDownLine > 45 ;

PlotShapes( IIf( Cond_Sell, shapeDownArrow , shapeNone ), colorRed );


Title =  Name() + "\\c17" +   "  " +"\\c12" + "RSI" +  " " + per_RSI   ;

Happy :)
 
SetBarsRequired( 800, 0 );

GraphXSpace = 7;
SetChartOptions( 0, chartShowArrows | chartShowDates );

// set criteria to scan for big stock only;
BigStock = MA( V, 10 ) * MA( C, 10 ) > 1000000;

//---------------Color------------------------
per1 = 6;
per2 = 2;
Om = MA( O, per1 );
hm = MA( H, per1 );
lm = MA( L, per1 );
Cm = MA( C, per1 );

// 1. Heiken Ashi
HACLOSE = ( Om + Hm + Lm + Cm ) / 4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );


Of = MA( Haopen, per2 );
Cf = MA( Haclose, per2 );
Lf = IIf( haOpen < haClose, MA( Halow, per2 ), MA( Hahigh, per2 ) );
Hf = IIf( haOpen < haClose, MA( Hahigh, per2 ), MA( Halow, per2 ) );
//Color = IIf( Cf > Of, colorGreen, colorRed );


//----------------------------------------------------

TrailStop = HHV( C - 2 * ATR( 10 ), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR( 10 );

/* **********************************
Code to automatically identify pivots
********************************** */

// -- what will be our lookback range for the hh and ll?
farback = 140; //How Far back to go
nBars = 12; //Number of bars

// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;

// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;

// -- looking back from the current bar, how many bars
// back were the hhv and llv values of the previous
// n bars, etc.?
aHHVBars = HHVBars( H, nBars );
aLLVBars = LLVBars( L, nBars );
aHHV = HHV( H, nBars );
aLLV = LLV( L, nBars );

// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of
// _Trace output will show a value of 0
aVisBars = Status( "barvisible" );
nLastVisBar = LastValue( Highest( IIf( aVisBars, BarIndex(), 0 ) ) );
_TRACE( "Last visible bar: " + nLastVisBar );

// -- Initialize value of curTrend
curBar = ( BarCount - 1 );
curTrend = "";

if ( aLLVBars[curBar] < aHHVBars[curBar] )
{
curTrend = "D";
}
else
{
curTrend = "U";
}

// -- Loop through bars. Search for
// entirely array-based approach
// in future version
for ( i = 0; i < BarCount; i++ )
{
curBar = ( BarCount - 1 ) - i;
// -- Have we identified a pivot? If trend is down...

if ( aLLVBars[curBar] < aHHVBars[curBar] )
{
// ... and had been up, this is a trend change
if ( curTrend == "U" )
{
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}

// -- or current trend is up
}
else
{
if ( curTrend == "D" )
{
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}

// -- If curTrend is up...else...
}

// -- loop through bars
}

// -- Basic attempt to add a pivot this logic may have missed
// -- OK, now I want to look at last two pivots. If the most
// recent low pivot is after the last high, I could
// still have a high pivot that I didn't catch
// -- Start at last bar
curBar = ( BarCount - 1 );

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if ( lastLPIdx > lastHPIdx )
{
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar];

if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar )
{
// -- OK, we'll add this as a pivot...
aHPivs[candIdx] = 1;
// ...and then rearrange elements in the
// pivot information arrays

for ( j = 0; j < nHPivs; j++ )
{
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs- ( j+1 )];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-( j+1 )];
}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;
nHPivs++;
}
}
else
{
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];

if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar )
{
// -- OK, we'll add this as a pivot...
aLPivs[candIdx] = 1;
// ...and then rearrange elements in the
// pivot information arrays

for ( j = 0; j < nLPivs; j++ )
{
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-( j+1 )];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-( j+1 )];
}

aLPivLows[0] = candPrc;

aLPivIdxs[0] = candIdx;
nLPivs++;
}
}

//============== EXPLORATION ==============
Buy = Cover = BigStock AND aLPivs == 1;

Sell = Short = BigStock AND aHPivs == 1;

SellPrice = ValueWhen( Sell, C, 1 );

BuyPrice = ValueWhen( Buy, C, 1 );

Long = Flip( Buy, Sell );

Shrt = Flip( Sell, Buy );

//============== Plot price ==============
n = 15;

a = C > ( MA( H, n ) + MA( L, n ) ) / 2;// then Buy next bar at market;

b = C < ( MA( H, n ) + MA( L, n ) ) / 2;// then Sell Short next bar at market;

state = IIf( BarsSince( a ) < BarsSince( b ), 1, 0 );

Longs = state == 1;

shorts = state == 0;

//Chart
Colorbar = IIf( Longs, colorGreen, IIf( Shorts, colorRed, colorGrey40 ) );

//Plot( C, "Close", colorbar, styleCandle = 64 | styleNoTitle );

//============== Plot Shape ==============
PlotShapes( IIf( aHPivs == 1, shapeDownArrow, shapeNone ), colorOrange, 0, High, Offset = -45 );

PlotShapes( IIf( aLPivs == 1, shapeUpArrow , shapeNone ), colorLime, 0, Low, Offset = -20 );
PlotShapes( IIf(Buy, shapeSmallCircle, shapeNone),colorDarkGreen, 0, BuyPrice, Offset = -15 );
PlotShapes( IIf(Sell, shapeSmallCircle, shapeNone),colorRed, 0 ,SellPrice, Offset = 45 );
FirstVisibleBar = Status( "FirstVisibleBar" );
Lastvisiblebar = Status("LastVisibleBar");
for( b = Firstvisiblebar; b <= Lastvisiblebar AND b < BarCount; b++)
{
if( Buy ) PlotText("\n\n\n\n Buy\n "+NumToStr(BuyPrice,1.2),b,BuyPrice,colorDarkGreen);
else if( Sell ) PlotText("Sell "+NumToStr(SellPrice, 1.2),b,SellPrice,colorRed);
}

//============== EMA(13) ==============
Plot( EMA( C, 13 ), "" , colorSkyblue + styleLine + styleNoRescale );

//============== TRENDING ==============
DTL = 150; // DTL = Define Trend Long

DTM = 70; // DTM = Define Trend Medium

DTS = 14; // DTS = Define Trend Short

TL = LinRegSlope( MA( C, DTL ), 2 ); // TL = Trend Long

TM = LinRegSlope( MA( C, DTM ), 2 ); // TM = Trend Medium

TS = LinRegSlope( MA( C, DTS ), 2 ); // TS = Trend Short

TLL = IIf( LinRegSlope( MA( C, DTL ), 2 ) > 0, True, False );

TMM = IIf( LinRegSlope( MA( C, DTM ), 2 ) > 0, True, False );

TSS = IIf( LinRegSlope( MA( C, DTS ), 2 ) > 0, True, False );

//============== VOLUME ==============
Vlp = 30; //Volume lookback period

Vrg = MA( V, Vlp );

St = StDev( Vrg, Vlp );

Vp3 = Vrg + 3 * st;

Vp2 = Vrg + 2 * st;

Vp1 = Vrg + 1 * st;

Vn1 = Vrg - 1 * st;

Vn2 = Vrg - 2 * st;

//============== WILLIAM'S %R ==============
WR = ( ( HHV( H, 14 ) - C ) / ( HHV ( H, 14 ) - LLV ( L, 14 ) ) ) * -100;

//============== A/D ==============
TRH = IIf( Ref( C, -1 ) > H, Ref( C, -1 ), H );

TRL = IIf( Ref( C, -1 ) < L, Ref( C, -1 ), L );

ad = IIf( C > Ref( C, -1 ), C - TRL, IIf( C < Ref( C, -1 ), C - TRH, 0 ) );

WAD = Cum( ad );

wu = wad > Ref( wad, -1 );

wd = wad < Ref( wad, -1 );

//============== MACD ==============
MB = Cross ( MACD(), Signal() );

MS = Cross( Signal(), MACD() );

MB = ExRem( MB, MS );

MS = ExRem( MS, MB );

MB1 = MACD() > Signal();

MS1 = MACD() < Signal();

//============== STOCH ==============
StochKval = StochK( 10, 5 );

StochDval = StochD( 10, 5, 5 );

StochBuy = Cross( StochK( 10, 5 ), StochD( 10, 5, 5 ) );

StochSell = Cross ( StochD( 10, 5, 5 ), StochK( 10, 5 ) );

StBuy = StochK( 10, 5 ) > StochD( 10, 5, 5 );

StSell = StochK( 10, 5 ) < StochD( 10, 5, 5 );

//============== ADX ==============
adxBuy = Cross( PDI( 14 ), MDI( 14 ) );

adxSell = Cross( MDI( 14 ), PDI( 14 ) );

adxBuy = ExRem( adxBuy, adxSell );

adxSell = ExRem( adxSell, adxBuy );

adxbuy1 = PDI( 14 ) > MDI( 14 );

adxsell1 = MDI( 14 ) > PDI( 14 );

//==============Zero Lag TMA ==============
function ZeroLagTEMA( array, period )
{
TMA1 = TEMA( array, period );
TMA2 = TEMA( TMA1, period );
Diff = TMA1 - TMA2;
return TMA1 + Diff ;
}

haClose = ( haClose + haOpen + haHigh + haLow ) / 4;

periodtm = 55;
ZLHa = ZeroLagTEMA( haClose, periodtm );
ZLTyp = ZeroLagTEMA( Avg, periodtm );
TMBuy = Cross( ZLTyp, ZLHa );
TMSell = Cross( ZLHa, ZLTyp );
TMBuy1 = ZLTyp > ZLHa ;
TMSell1 = ZLHa > ZLTyp ;

//============== ZLW ==============
R = ( ( HHV( H, 14 ) - C ) / ( HHV ( H, 14 ) - LLV ( L, 14 ) ) ) * -100;
MaxGraph = 10;
PeriodZ = 10;
EMA1 = EMA( R, PeriodZ );
EMA2 = EMA( EMA1, 5 );
Difference = EMA1 - EMA2;
ZeroLagEMA = EMA1 + Difference;
PR = 100 - abs( ZeroLagEMA );
MoveAvg = MA( PR, 5 );
ZBuy = Cross( PR, moveAvg ) AND PR < 30;
ZSell = Cross( moveAvg, PR ) AND PR > 70;
ZBuy1 = PR >= MoveAvg AND PR >= Ref( PR, -1 ) ;
ZSell1 = ( PR < MoveAvg ) OR PR >= MoveAvg AND PR < Ref( PR, -1 ) ;

//============== RS ==============
p = ( H + L + C ) / 3;
r1 = ( 2 * p ) - L;
s1 = ( 2 * p ) - H;
r2 = p + ( r1 - s1 );
s2 = p - ( r2 - s1 );
R3 = P + ( R2 - S2 );
S3 = P - ( R3 - S2 );

//============== IBUY ==============
Ibuy = Cross( RSI( 14 ), EMA( RSI( 14 ), 9 ) );
Isell = Cross( EMA( RSI( 14 ), 9 ), RSI( 14 ) );
Ibuy = ExRem( Ibuy, ISell );
Isell = ExRem( ISell, Ibuy );
BlRSI = RSI( 14 ) > EMA( RSI( 14 ), 9 );
BrRSI = RSI( 14 ) < EMA( RSI( 14 ), 9 );


//=================Trend & Signals & Market Index ===============================
/// Please replace "00DSEGEN" with your market index ticker and activate the codes

/// Market Bull Bear

Cg = Foreign("^GSPC", "C");
Cgo= Ref(Cg,-1);

//Longterm Bullish or Bearish
Bullg = Cg > WMA(Cg,200);
Bearg= Cg <WMA(Cg,200);

//Midterm Bullish or Bearish
mBullg = Cg >WMA(Cg,50);
mBearg= Cg <WMA(Cg,50);

//Shortterm Bullish or Bearish
sBullg = Cg >WMA(Cg,15);
sBearg= Cg <WMA(Cg,15);
////////////////////////////////



xChange1=Cg - Ref(Cg,-1);
Change1 = StrFormat("%1.2f% ",xChange1);
barche1= xChange1>=0;
Comche1= xChange1<0;
xperchange1 = xChange1/100;
perchange1 = StrFormat("%1.2f% ",xperchange1);
positivechange1 = xperchange1>0;
negativechange1 = xperchange1<0;

//=================Trend & Signals & Market Index END===============================



//============== TITLE ==============

_SECTION_BEGIN("Volatility 2");
// Just Re-share
// E.M.Pottasch, Jul 2010
// from Metastock formula, link: http://stocata.org/metastock/stop_trail_atr.html
// added separate parameters for upward and downward market environment

function vstop_func(trBull,trBear)
{
trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - trBull[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + trBear[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - trBull[ i ];
}
else
{
trailArray[ i ] = C[ i ] + trBear[ i ];
}
}
return trailArray;
}

per = Param("per",20, 1, 150, 1);
multBull = Param("multBull",2, 1, 4, 0.05);
multBear = Param("multBear",2, 1, 4, 0.05);

trBull = multBull * ATR(per);
trBear = multBear * ATR(per);

trailArray = vstop_func(trBull,trBear);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot(IIf(trailArray > C,trailArray,Null),"\ntrailShort",ParamColor("Colo rTrailShort",ColorRGB(255,0,0)),styleStaircase);
Plot(IIf(trailArray < C,trailArray,Null),"\ntrailLong",ParamColor("Color TrailLong",ColorRGB(0,255,0)),styleStaircase);
Plot( C, "\nCandle",colorWhite, styleCandle );
_SECTION_END();

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",15,30,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlue) );
Hor=Param("Horizontal Position",750,800,800,800);
Ver=Param("Vertical Position",27,27,27,27);
GfxTextOut("L.T.P="+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5.45, Ver+45 );
_SECTION_END();

_SECTION_BEGIN("KPL Swing with N&M Swing");
SetBarsRequired(200,0);

GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k = Optimize("K",Param("K",3,0.25,5,0.25),0.25,5,0.25) ;
Per= Optimize("atr",Param("atr",10,3,20,1),3,20,1);
HACLOSE=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorBlack, styleCandle | styleNoLabel );
j=Haclose;

//================================================== ================================================== ===================
//=========================Indicator================ ================================================== ============================
f=ATR(15);

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;
NW[0] = 0;
NW[BarCount-1] = Null;


for(i = 1; i < BarCount-1; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

//===============system================

Plot(NW, "", IIf(Trend == 1, 27, 4), 4);
Buy=NW<HACLOSE;
Sell=NW>HACLOSE;
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy );

Short=Sell;
Cover=Buy;


NMAB= NW<HACLOSE;
NMAS= NW>HACLOSE;
AlertIf( Buy , "SOUND C://Windows//Media//chimes.wav", "Audio alert", 2 );
AlertIf( Sell , "SOUND C://Windows//Media//alert.wav", "Audio alert", 2 );

NMA_status= WriteIf(NMAB, "BUY MODE", WriteIf(NMAS, "SELL MODE", "NEUTRAL"));
NMAS_Col=IIf(NMAB, colorGreen, IIf(NMAS, colorRed, colorLightGrey));
Filter=1;
AddColumn( NW[BarCount-1], "SAR", 1.2 );
AddColumn( HACLOSE, "HA Close", 1.2 );
AddColumn( C, "Close", 1.2 );
AddTextColumn(NMA_status, "MODE", 1, colorWhite, NMAS_Col);
AddColumn( DateTime(), "Date / Time", formatDateTime );
_SECTION_END();
//=================TITLE============================ ================================================== ==================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "SureShot trading 3 10" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"",""));
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"","") ;
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);



for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = H;
sig = "BUY";
sl = Ref(NW,-1);
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = L;
sl = Ref(NW,-1);
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == BUY, colorLime, colorRed) ;
ssl = IIf(bars == BarCount-1, NW[BarCount-1], Ref(NW, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);



messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "SureShot Trading System"),13,y-100);
GfxTextOut( (" "),27,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-60);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);

}

_SECTION_END();

_SECTION_END();
function ChandelierCl(AtrARRAY, AtrMult) {
// Skip empty values
i = 0;
do {
result = Null;
i++;
}
while( i < BarCount AND (IsNull(O) OR IsNull(H) OR IsNull(L) OR IsNull(C) ) );
First = i;

if (i < BarCount - 1) {
HHC[First] = C[First];
LLC[First] = C[First];

if (C[First + 1] > HHC[First]) {
HHC[First + 1] = C[First + 1];
LLC[First + 1] = LLC[First];
result[First] = C[First] - AtrMult * AtrARRAY[First];
iTrade = "LT";
}
else {
if (C[First + 1] < LLC[First]) {
HHC[First = 1] = HHC[First];
LLC[First + 1] = LLC[First + 1];
result[First] = C[First] + AtrMult * AtrARRAY[First];
iTrade = "ST";
}
else {
HHC[First + 1] = C[First + 1];
LLC[First + 1] = C[First + 1];
result[First] = C[First] - AtrMult * AtrARRAY[First];
iTrade = "LT";
}
}

for( i = First; i < BarCount; i++ ) {
if (iTrade == "LT") {
if (C >= result[i-1]) { // Long Trade is continuing
if (C > C[i-1]) {
HHC = C;
}
else {
HHC = HHC[i-1];
}
result = HHC - AtrMult * AtrARRAY;
if (result < result[i-1]) {
result = result[i-1];
}
}
else { // Long trade Exit triggered
iTrade = "ST";
LLC = C;
result = C + AtrMult * AtrARRAY;
}
}
else { // Short trade
if (C <= result[i-1]) {
if (C <= C[i-1]) { // Short Trade is continuing
LLC = C;
}
else {
LLC = LLC[i-1];
}
result = LLC + AtrMult * AtrARRAY;
if (result > result[i-1]) {
result = result[i-1];
}
}
else { //Short Trade Exit is triggered
iTrade = "LT";
HHC = C;
result = C - AtrMult * AtrARRAY;
}
}
}
}
return result;
}

function ChandelierHL(AtrARRAY, AtrMult) {
// Skip empty values
i = 0;
do {
result = Null;
i++;
}
while( i < BarCount AND (IsNull(O) OR IsNull(H) OR IsNull(L) OR IsNull(C) ) );
First = i;

if (i < BarCount - 1) {
HHC[First] = H[First];
LLC[First] = L[First];

if (H[First + 1] > HHC[First]) {
HHC[First + 1] = H[First + 1];
LLC[First + 1] = LLC[First];
result[First] = H[First] - AtrMult * AtrARRAY[First];
iTrade = "LT";
}
else {
if (L[First + 1] < LLC[First]) {
HHC[First = 1] = HHC[First];
LLC[First + 1] = LLC[First + 1];
result[First] = L[First] + AtrMult * AtrARRAY[First];
iTrade = "ST";
}
else {
HHC[First + 1] = C[First + 1];
LLC[First + 1] = C[First + 1];
result[First] = H[First] - AtrMult * AtrARRAY[First];
iTrade = "LT";
}
}

for( i = First; i < BarCount; i++ ) {
if (iTrade == "LT") {
if (C >= result[i-1]) { // Long Trade is continuing
if (H > H[i-1]) {
HHC = H;
}
else {
HHC = HHC[i-1];
}
result = HHC - AtrMult * AtrARRAY;
if (result < result[i-1]) {
result = result[i-1];
}
}
else { // Long trade Exit triggered
iTrade = "ST";
LLC = L;
result = L + AtrMult * AtrARRAY;
}
}
else { // Short trade
if (C <= result[i-1]) {
if (L <= L[i-1]) { // Short Trade is continuing
LLC = L;
}
else {
LLC = LLC[i-1];
}
result = LLC + AtrMult * AtrARRAY;
if (result > result[i-1]) {
result = result[i-1];
}
}
else { //Short Trade Exit is triggered
iTrade = "LT";
HHC = H;
result = H - AtrMult * AtrARRAY;
}
}
}
}
return result;
}

_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);


Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

Cond3 = Zig(C,z)>Ref(Zig(C,z),-4);
Buy = Cond1 AND Cond3;

Cond4 = Cross(Signal(r1,r2,r3),MACD(r1,r2));

Cond6 = Zig(C,z)<Ref(Zig(C,z),-4);
Sell = Cond4 AND Cond6;
Trigger = WriteIf(Buy, "Buy", "") + WriteIf(Sell, "Sell", "");

_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}}: O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, V=%1.0f\n{{VALUES}}", O, H, L, C, V));

BG = IIf(Buy, colorPaleGreen, IIf(Sell, colorRose, colorDefault));
FG = IIf(Buy, colorDarkGreen, IIf(Sell, colorDarkRed, colorDefault));

if(Status("action") == actionIndicator)
{
Plot(C, "", colorGrey50, styleBar);
PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorGreen, 0,L, Offset=-40);
PlotShapes(IIf(Sell, shapeCircle, shapeNone),colorRed, 0,H, Offset=40);
PlotShapes(shapeHollowDownArrow*Sell,colorYellow,0 ,SellPrice,-05);
PlotShapes(shapeHollowUpArrow*Buy,colorYellow,0,Bu yPrice,-05);

}

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods",100, 2, 300, 1, 100 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorBlue ), ParamStyle("Style") );
_SECTION_END();


In Back testing this strategy it is still showing an error
"Variable entry used without having been initialised (Ln:701. Col:75):confused:
 
Hell

Sorry cannot debug such a big code,
maybe someone else can give it a try.


Thanks


Happy :)
Happy Ji add this is your signature
Hello Friends

I am starting this thread for helping anyone who requires small changes in AFLs or AFL coding done for small / simple requirements that can be clearly defined.

What does not go is conversion . . . from Amibroker to anything else . . . or from anything else to Amibroker . . .

Debugging requested for copy/paste AFLs, Please don't post huge AFLs with zillions of lines of code for debugging

I will not be available for any conversions and I am not interested in debugging some-one else's copy/pasted work and lastly . . .
Not interested in hacking/craking any ones work . . .

Only if have a clearly definable task to be coded I maybe able to help . . . No Promises but will try within my limitations . . .



:) Happy
 
Thanks Dear Monkey business for reminding the conduct code of the thread.....your kind gesture is very much appreciated.....
as for me i have recently purchased the amibroker software and am in a hurry to set up a trading system for myself....also side by side learning the the AFL Language....
thanks and Regards
 
Thanks Dear Monkey business for reminding the conduct code of the thread.....your kind gesture is very much appreciated.....
as for me i have recently purchased the amibroker software and am in a hurry to set up a trading system for myself....also side by side learning the the AFL Language....
thanks and Regards
I am getting error here: line 423 & 427 some problem with %
Code:
xChange1=Cg - Ref(Cg,-1);
Change1 = StrFormat("%1.2f% ",xChange1);
barche1= xChange1>=0;
Comche1= xChange1<0;
xperchange1 = xChange1/100;
perchange1 = StrFormat("%1.2f% ",xperchange1);
positivechange1 = xperchange1>0;
negativechange1 = xperchange1<0;
line 657
Code:
Clr = IIf(sig == BUY, colorLime, colorRed) ;
line 895
Code:
PlotShapes(shapeHollowUpArrow*Buy,colorYellow,0,Bu yPrice,-05);
line 657, Buy seems to be reserve word in Ami 6/6.2
line 895, remove space in Bu y
 

vijkris

Learner and Follower
I am getting error here: line 423 & 427 some problem with %
Code:
xChange1=Cg - Ref(Cg,-1);
Change1 = StrFormat("%1.2f% ",xChange1);
barche1= xChange1>=0;
Comche1= xChange1<0;
xperchange1 = xChange1/100;
perchange1 = StrFormat("%1.2f% ",xperchange1);
positivechange1 = xperchange1>0;
negativechange1 = xperchange1<0;
line 657
Code:
Clr = IIf(sig == BUY, colorLime, colorRed) ;
line 895
Code:
PlotShapes(shapeHollowUpArrow*Buy,colorYellow,0,Bu yPrice,-05);
line 657, Buy seems to be reserve word in Ami 6/6.2
line 895, remove space in Bu y
Line 657 put "buy"
I saw his sure shot trading system Alf before but couldn post the rectified code.
 

Similar threads