Simple Coding Help - No Promise.

Code:
// Description: By moneyfroly 
// [url]http://www.traderji.com/advanced-trading-strategies/102339-5-minute-trading-system-if-afl-coded-awesome.html[/url]
// Coded By: Mayur Patel | fb.com/Mayursss

_SECTION_BEGIN("Chart Pane");
	SetChartOptions(0,chartShowArrows|chartShowDates);
	SetChartBkColor(ParamColor("Outer Panel",ColorRGB(30, 30, 30)));
	SetChartBkGradientFill(ParamColor("Upper Chart",colorDarkGrey),ParamColor("LowerChart",colorDarkGrey));
	GraphXSpace=10;
   SetBarFillColor (IIf(C>O,19,IIf(C<O,24,42))); 
   Plot(C,"",IIf(C>O,51,IIf(C<O,33,55)),64);
 
Title = EncodeColor(ColorRGB(127, 179, 213))+  Title = Name() + "     " + EncodeColor(ColorRGB(41, 128, 185)) + Date() +
"      " + EncodeColor(ColorRGB(127, 179, 213)) + "{{INTERVAL}}  " +
	EncodeColor(ColorRGB(127, 179, 213))+ "     Open = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(O,1.2) + 
	EncodeColor(ColorRGB(127, 179, 213))+ "     High = "+ EncodeColor(ColorRGB(41, 128, 185)) + WriteVal(H,1.2) +
	EncodeColor(ColorRGB(127, 179, 213))+ "      Low = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(L,1.2) + 
	EncodeColor(ColorRGB(127, 179, 213))+ "    Close = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(C,1.2)+
	EncodeColor(ColorRGB(127, 179, 213))+ "    Volume = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(V,1);

Plot(V, "Volume", ColorRGB(27, 79, 114),styleHistogram|styleOwnScale|styleThick, 10);
Plot(Day()!=Ref(Day(),-1),"",ColorRGB(25,33,25),styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
_SECTION_END();

_SECTION_BEGIN("Super Trend");
Factor=Param("Factor",4,1,10,0.1);
Pd=Param("ATR Periods",10,1,100,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

      TrendUp[i] = Null;TrendDown[i] = Null; trend[i]=1;
      if (Close[i]>Up[i-1]) {
         trend[i]=1;
         if (trend[i-1] == -1) changeOfTrend = 1;
		}

      else if (Close[i]<Dn[i-1]) {
         trend[i]=-1;
         if (trend[i-1] == 1) changeOfTrend = 1;
      }

      else if (trend[i-1]==1) {
         trend[i]=1;
         changeOfTrend = 0;       
      }

      else if (trend[i-1]==-1) {
         trend[i]=-1;
         changeOfTrend = 0;
      }

      if (trend[i]<0 && trend[i-1]>0) {flag=1;}
      else {flag=0;}
      if (trend[i]>0 && trend[i-1]<0) {flagh=1;}
      else {flagh=0;}
      if (trend[i]>0 && Dn[i]<Dn[i-1]){Dn[i]=Dn[i-1];}
      if (trend[i]<0 && Up[i]>Up[i-1]){ Up[i]=Up[i-1];}
      if (flag==1){  Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);} 
      if (flagh==1){ Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);}
      if (trend[i]==1) {
			TrendUp[i]=Dn[i];
         	if (changeOfTrend == 1) {
            TrendUp[i-1] = TrendDown[i-1];
            changeOfTrend = 0;
         }
      }

      else if (trend[i]==-1) {
         TrendDown[i]=Up[i];
         if (changeOfTrend == 1) {
            TrendDown[i-1] = TrendUp[i-1];
            changeOfTrend = 0;
         }
      }
   } 

Plot(TrendUp,"TrendUp",colorGreen);
Plot(TrendDown,"TrendDown",colorRed);

_SECTION_END();

_SECTION_BEGIN("Power Trade");

//Includes
NewDay  =Day()!=Ref(Day(),-1); 
PH	    = TimeFrameGetPrice( "H", inDaily, -1 );
PL	    = TimeFrameGetPrice( "L", inDaily, -1 );
PC     = TimeFrameGetPrice( "C", inDaily, -1 );
DayO   = TimeFrameGetPrice( "O", inDaily, 0 );

//Signals
IsGapUp= DayO>PC;
IsGapDn= DayO<PC;

PB_1= NewDay AND IsGapUp AND C>PH AND (O==L) ;
PB_2= NewDay AND IsGapUp AND C>PH ;
PB_3= NewDay AND IsGapDn AND C>PH AND (trend==1 AND O<TrendUp);
NormalBuy= trend==1 AND L<=TrendUp AND Min(O,C)>=TrendUp;

PS_1= NewDay AND IsGapDn AND C<PL AND (O==H) ;
PS_2= NewDay AND IsGapDn AND C<PL ;
PS_3= NewDay AND IsGapUp AND C<PL AND (trend==-1 AND O>TrendDown);
NormalShort= trend==-1 AND H>=TrendDown AND Max(O,C)<=TrendDown;

Buy=PB_1 OR PB_2 OR PB_3 OR NormalBuy;
Short= PS_1 OR PS_2 OR PS_3 OR NormalShort;
Cover=Sell=TimeNum()>=152500;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short= ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

//Shapes
Shape=IIf( PB_1 OR PS_1, shapeDigit1,IIf(PB_2 OR PS_2,shapeDigit2,IIf(PB_3 OR PS_3,shapeDigit3, shapeNone )));
PlotShapes(Shape, IIf(Buy,colorLime,colorOrange )); 
PlotShapes(IIf(Buy,shapeUpArrow,IIf(Short,shapeDownArrow, shapeNone )) , IIf(Buy,colorDarkGreen,colorDarkRed ),0, IIf( Buy, Low, High ) ); 

//Explore
Filter=Buy OR Short;
PowerSig= IIf(PB_1,1,IIf(PS_1,-1,IIf(PB_2,2,IIf(PS_2,-2,IIf(PB_3,3,IIf(PS_3,-3,0))))));
NormalSig= IIf(Buy,1,IIf(Short,-1,0));
AddColumn(PowerSig," Power Signals",1,colorWhite,IIf(PB_1 OR PB_2 OR PB_3,colorDarkGreen,IIf(PS_1 OR PS_2 OR PS_3,colorDarkRed,colorWhite)));
AddColumn(NormalSig," Normal Signals",1,colorWhite,IIf(NormalBuy,colorGreen,IIf(NormalShort,colorRed,colorWhite)));
_SECTION_END();
 
Last edited by a moderator:

amitrandive

Well-Known Member
I want the stock in nr7 EOD and strategy recently developed by 5 min setup should be clubbed
Code:
_SECTION_BEGIN("NR7");

/*********** NR7 System for Chart and Exploration ***********************/

R = H - L;
NR7 = False;
NR4 = False;
m7 = m4 = idm7 = idm4 = idm = 0;

for(i = 7; i < BarCount; i++)
{
if( R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] AND R[i] < R[i - 4] AND R[i] < R[i - 5] AND R[i] < R[i - 6]) 
{
NR7[i] = True;
m7[i] = 1;
}
}

for(i = 4; i < BarCount; i++)
{
if((R[i] < R[i - 1] AND R[i] < R[i -2] AND R[i] < R[i - 3] ) AND NOT NR7[i])
{
NR4[i] = True;
m4[i] = 1;
}
}
IDNR7 = Inside() * NR7;
IDNR4 = Inside() * NR4;
ID = Inside();
idm7 = IIf(IDNR7, 1, 0);
idm4 = IIf(IDNR4, 1, 0);
idm = IIf(id, 1, 0);

for(i = 1; i < BarCount; i++)
{
if(IDNR7[i] == IDNR7[i - 1]) idm7[i] = idm7[i] + idm7[i - 1];
if(IDNR4[i] == IDNR4[i - 1]) idm4[i] = idm4[i] + idm4[i - 1];
if(NR7[i] == NR7[i - 1]) m7[i] = m7[i] + m7[i - 1];
if(NR4[i] == NR4[i - 1]) m4[i] = m4[i] + m4[i - 1];
if(ID[i] == ID[i - 1]) idm[i] = idm[i] + idm[i - 1];
}

MarkerIDNR7 = MarkerIDNR4 = shapeStar ;

Marker7 = shapeDigit7;
NR7Color = colorBrightGreen;

Marker4 = shapeDigit4;
NR4Color = colorLightOrange;

MarkerID = shapeHollowCircle;
IDColor = colorYellow;

IDNR7Color = colorBrightGreen;
IDNR4Color = colorLightOrange;

MarkerDist = L * 0.995;
IDNRDist = H * 1.03;

if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}}, {{DATE}} ({{INTERVAL}}): {{VALUES}}") + ", Range=" + Prec(R + 0.00001, 2) + "," 
+ WriteIf(IDNR7, EncodeColor(colorBrightGreen) + WriteIf(idm7 > 1, StrLeft(NumToStr(idm7), 4), "") + " IDNR7 ", "")
+ WriteIf(IDNR4, EncodeColor(colorLightOrange) + WriteIf(idm4 > 1, StrLeft(NumToStr(idm4), 4), "") + " IDNR4 ", "") 
+ WriteIf(NR7 AND NOT ID, EncodeColor(colorBrightGreen) + WriteIf(m7 > 1, StrLeft(NumToStr(m7), 4), "") + " NR7 ", "")
+ WriteIf(NR4 AND NOT ID, EncodeColor(colorLightOrange) + WriteIf(m4 > 1, StrLeft(NumToStr(m4), 4), "") + " NR4 ", "")
+ WriteIf(ID AND NOT NR7 AND NOT NR4, EncodeColor(colorTurquoise) + WriteIf(idm > 1, StrLeft(NumToStr(idm), 4), "") + " Inside Day ", ""));

PlotOHLC(O, H, L, C, "Close", colorLightGrey, styleBar);
PlotShapes(IIf(IDNR7, MarkerIDNR7, shapeNone), IDNR7Color, 0, IDNRDist);
PlotShapes(IIf(IDNR4 AND NOT IDNR7, MarkerIDNR4, shapeNone), IDNR4Color, 0, IDNRDist);
PlotShapes(IIf(NR7 AND NOT ID, Marker7, shapeNone), NR7Color, 0, MarkerDist);
PlotShapes(IIf(NR4 AND NOT NR7 AND NOT ID, Marker4, shapeNone), NR4Color, 0, MarkerDist);
PlotShapes(IIf(ID AND NOT NR7 AND NOT NR4, MarkerID, shapeNone), IDColor, 0, IDNRDist);
}

if(Status("action") == actionExplore)
{
Filter = (m7 > 0) OR (m4 > 0) OR (idm > 0);

SetOption("NoDefaultColumns", True);

AddColumn(DateTime(), "DATE", formatDateTime, colorDefault, colorDefault, 96);
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 120);
AddColumn(R, "Range", 6.2, colorDefault, colorDefault, 84);
AddColumn(IIf(idm, 48 + idm, 32), "INSIDE", formatChar, colorYellow, IIf(idm, colorLightBlue, colorDefault));
AddColumn(IIf(m4, 48 + m4, 32), "NR4", formatChar, colorYellow, IIf(m4, colorBlue, colorDefault));
AddColumn(IIf(m7, 48 + m7, 32), "NR7", formatChar, colorYellow, IIf(m7, colorGreen, colorDefault));
}

/************************** END OF AFL CODE *****************************/

_SECTION_END();


/*********************************************/

Those stocks in nr7 filtered and apply this afl as a scanner to buy
Code:
// Description: By moneyfroly 
// [url]http://www.traderji.com/advanced-trading-strategies/102339-5-minute-trading-system-if-afl-coded-awesome.html[/url]
// Coded By: Mayur Patel | fb.com/Mayursss

_SECTION_BEGIN("Chart Pane");
	SetChartOptions(0,chartShowArrows|chartShowDates);
	SetChartBkColor(ParamColor("Outer Panel",ColorRGB(30, 30, 30)));
	SetChartBkGradientFill(ParamColor("Upper Chart",colorDarkGrey),ParamColor("LowerChart",colorDarkGrey));
	GraphXSpace=10;
   SetBarFillColor (IIf(C>O,19,IIf(C<O,24,42))); 
   Plot(C,"",IIf(C>O,51,IIf(C<O,33,55)),64);
 
Title = EncodeColor(ColorRGB(127, 179, 213))+  Title = Name() + "     " + EncodeColor(ColorRGB(41, 128, 185)) + Date() +
"      " + EncodeColor(ColorRGB(127, 179, 213)) + "{{INTERVAL}}  " +
	EncodeColor(ColorRGB(127, 179, 213))+ "     Open = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(O,1.2) + 
	EncodeColor(ColorRGB(127, 179, 213))+ "     High = "+ EncodeColor(ColorRGB(41, 128, 185)) + WriteVal(H,1.2) +
	EncodeColor(ColorRGB(127, 179, 213))+ "      Low = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(L,1.2) + 
	EncodeColor(ColorRGB(127, 179, 213))+ "    Close = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(C,1.2)+
	EncodeColor(ColorRGB(127, 179, 213))+ "    Volume = "+ EncodeColor(ColorRGB(41, 128, 185))+ WriteVal(V,1);

Plot(V, "Volume", ColorRGB(27, 79, 114),styleHistogram|styleOwnScale|styleThick, 10);
Plot(Day()!=Ref(Day(),-1),"",ColorRGB(25,33,25),styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
_SECTION_END();

_SECTION_BEGIN("Super Trend");
Factor=Param("Factor",4,1,10,0.1);
Pd=Param("ATR Periods",10,1,100,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

      TrendUp[i] = Null;TrendDown[i] = Null; trend[i]=1;
      if (Close[i]>Up[i-1]) {
         trend[i]=1;
         if (trend[i-1] == -1) changeOfTrend = 1;
		}

      else if (Close[i]<Dn[i-1]) {
         trend[i]=-1;
         if (trend[i-1] == 1) changeOfTrend = 1;
      }

      else if (trend[i-1]==1) {
         trend[i]=1;
         changeOfTrend = 0;       
      }

      else if (trend[i-1]==-1) {
         trend[i]=-1;
         changeOfTrend = 0;
      }

      if (trend[i]<0 && trend[i-1]>0) {flag=1;}
      else {flag=0;}
      if (trend[i]>0 && trend[i-1]<0) {flagh=1;}
      else {flagh=0;}
      if (trend[i]>0 && Dn[i]<Dn[i-1]){Dn[i]=Dn[i-1];}
      if (trend[i]<0 && Up[i]>Up[i-1]){ Up[i]=Up[i-1];}
      if (flag==1){  Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);} 
      if (flagh==1){ Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);}
      if (trend[i]==1) {
			TrendUp[i]=Dn[i];
         	if (changeOfTrend == 1) {
            TrendUp[i-1] = TrendDown[i-1];
            changeOfTrend = 0;
         }
      }

      else if (trend[i]==-1) {
         TrendDown[i]=Up[i];
         if (changeOfTrend == 1) {
            TrendDown[i-1] = TrendUp[i-1];
            changeOfTrend = 0;
         }
      }
   } 

Plot(TrendUp,"TrendUp",colorGreen);
Plot(TrendDown,"TrendDown",colorRed);

_SECTION_END();

_SECTION_BEGIN("Power Trade");

//Includes
NewDay  =Day()!=Ref(Day(),-1); 
PH	    = TimeFrameGetPrice( "H", inDaily, -1 );
PL	    = TimeFrameGetPrice( "L", inDaily, -1 );
PC     = TimeFrameGetPrice( "C", inDaily, -1 );
DayO   = TimeFrameGetPrice( "O", inDaily, 0 );

//Signals
IsGapUp= DayO>PC;
IsGapDn= DayO<PC;

PB_1= NewDay AND IsGapUp AND C>PH AND (O==L) ;
PB_2= NewDay AND IsGapUp AND C>PH ;
PB_3= NewDay AND IsGapDn AND C>PH AND (trend==1 AND O<TrendUp);
NormalBuy= trend==1 AND L<=TrendUp AND Min(O,C)>=TrendUp;

PS_1= NewDay AND IsGapDn AND C<PL AND (O==H) ;
PS_2= NewDay AND IsGapDn AND C<PL ;
PS_3= NewDay AND IsGapUp AND C<PL AND (trend==-1 AND O>TrendDown);
NormalShort= trend==-1 AND H>=TrendDown AND Max(O,C)<=TrendDown;

Buy=PB_1 OR PB_2 OR PB_3 OR NormalBuy;
Short= PS_1 OR PS_2 OR PS_3 OR NormalShort;
Cover=Sell=TimeNum()>=152500;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short= ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

//Shapes
Shape=IIf( PB_1 OR PS_1, shapeDigit1,IIf(PB_2 OR PS_2,shapeDigit2,IIf(PB_3 OR PS_3,shapeDigit3, shapeNone )));
PlotShapes(Shape, IIf(Buy,colorLime,colorOrange )); 
PlotShapes(IIf(Buy,shapeUpArrow,IIf(Short,shapeDownArrow, shapeNone )) , IIf(Buy,colorDarkGreen,colorDarkRed ),0, IIf( Buy, Low, High ) ); 

//Explore
Filter=Buy OR Short;
PowerSig= IIf(PB_1,1,IIf(PS_1,-1,IIf(PB_2,2,IIf(PS_2,-2,IIf(PB_3,3,IIf(PS_3,-3,0))))));
NormalSig= IIf(Buy,1,IIf(Short,-1,0));
AddColumn(PowerSig," Power Signals",1,colorWhite,IIf(PB_1 OR PB_2 OR PB_3,colorDarkGreen,IIf(PS_1 OR PS_2 OR PS_3,colorDarkRed,colorWhite)));
AddColumn(NormalSig," Normal Signals",1,colorWhite,IIf(NormalBuy,colorGreen,IIf(NormalShort,colorRed,colorWhite)));
_SECTION_END();
Takes lot of time and effort for combining EOD and Intraday code.Too many parameters.Will try if able to find time.
 

nac

Well-Known Member
Coding help only for writing afl or you guys help with excel too?

If yes for Excel, check this thread

Calculating turnover manually at the end of the year is hectic. Really appreciate some help in writing formulas in excel.

Thank you.
 
Hi,

Can you help me code this in amibroker?

50ma Play

Chart Setup:
- RSI(30) with 30,50,70
- 50 simple Moving Average
- BB (50, 0.2)
- 250 simple Moving Average (to represent weekly 50Ma)
- green/red arrows represent crosses up/down of the weekly 50MA

The idea is to catch the bounce at 50ma, in conjunction with the cross of RSI(30) above the 50 line. The "Kiss of 50ma" on weekly chart will yield better results, thus we plotted the 250ma. The green/red arrows represent crosses up/down of the weekly 50MA.

We open BUY trade with these 2 most important conditions:
1. RSI(30) must be over the 50 line
2. Price must be as close as possible, and above the 50MA weekly.

Parabolic State is defined as when the RSI(30) weekly > RSI(30) daily. This is when big moves are happening at Parabolic State.

Thanks
 
Hi Ami experts... It really feels happy to see an afl coding community which is active. Most of the other sites/forums visited are close or atleast I found those. Thanks a lot to traderji and seniors who are helping out by sharing knowledge.

I'm trying to code simple Ichimoku with exit @ fixed targets and fixed SL's but I'm unable to code this simple one, can someone share sample code snippet for exiting at fixed targets & stops based on %.

I can post my code here and ask, but nothing works in that code, so I thought why to post something which don't work even half good. So, if any seniors/experts have sample code setup for exiting at fixed targets & stops based on % please share. I'm not looking for strategy, just sample codes to rework on my afl. Thanks in advance.
 
Filter = Close > 0;
_SECTION_BEGIN("RSI");

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


/* Create date: 20 Dec 2009
The Stochastic %K(Slow) crosses above the Stochastic %D(Slow) on the current bar */

Buy =Cross( StochK( 14, 3 ), StochD( 14, 3, 3 ) )AND StochK( 14, 3 ) > 20 OR
/* Create date: 20 Dec 2009
The MACD crosses above the Signal on the current bar */

Cross( MACD( 12, 26 ), Signal( 12, 26, 9 ) ) /*AND
/* Create date: 20 Dec 2009
The Simple MA (Medium) crosses above the Simple MA (Long) on the current bar */

/*Volume > 250000 */OR
Cross(RSI ( periods ), MA ( P, Periods));
Sell = Cross( StochD( 14, 3, 3 ), StochK( 14, 3 ) )AND StochK( 14, 3 ) < 80 OR
Cross( Signal( 12, 26, 9 ), MACD( 12, 26 ) )/*AND
/* Create date: 20 Dec 2009
The Close Price of the current bar is greater than the Simple MA (Long) of 1 bar ago */

/* Create date: 20 Dec 2009
The Simple MA (Medium) crosses above the Simple MA (Long) on the current bar */

/*Volume > 250000*/ OR
Cross(MA ( P, Periods),RSI ( periods ) );
Short = Sell;
Cover = Buy;
need help seniors and experts (happy singh ji and other experts) i need buy/ sell signals when red line cross blue line on price charts
 
Hi Experts n Seniors,

Below is my code and I tried numerous times to get the code exit at calculated Stop or target levels - almost for 15 days-but no luck..I know for some simple thing I spent over 15days .But exit is always happening @ Low or High or Close of the exit candle. thats why seeking help here

For example,Long @ 195, SL: 191 Target:201.5
As trade progresses we get a candle as O: 200 H: 205 L:197 C:202 , this is our exit candle as target is reached and it should exit at 201.5. Instead, either close 202 or High 205 is shown as exit value ( on chart & backtest results too).

Kindly rectify the problem in below code to exit @ exact target or stops for both Long and short positions. Thanks a lot for this favor..Here is the code...

Code:
_SECTION_BEGIN("Ichimoku check ");
P1 = Param("Conversion Period", 9, 2, 200, 1, 0);
C1 = ParamColor("Conversion Color", colorBlue);
CL = (HHV(H,P1)+LLV(L,P1))/2;

P2 = Param("Base Period", 26, 2, 200, 1, 0);
C2 = ParamColor("Base Color", colorRed);
BL = (HHV(H,P2)+LLV(L,P2))/2;

C3 = ParamColor("Leading A Color", colorBrightGreen);
LSA = (CL+BL)/2;

P4 = Param("Leading B Span", 52, 2, 200, 1, 0);
C4 = ParamColor("Leading B Color", colorPink);
LSB = (HHV(H,P4)+LLV(L,P4))/2;

P3 = Param("Leading Span Displacement", 26, 2, 200, 1, 0);

P5 = Param("Lagging Displacement", -26, 2, 200, 1, 0);
C5 = ParamColor("Lagging Color", colorGreen);

DayC = TimeFrameGetPrice("C", inDaily, -1); // close

Buy=Sell=Short=Cover=0;

Buyc = C > Ref(LSA, -P3) AND C > Ref( LSB, -P3) AND CL > BL;

Shortc =  C < Ref(LSA, -P3) AND C < Ref( LSB, -P3) AND CL < BL;



Buy = Ref(Buyc, -1) ==1 ; 
Short = Ref(Shortc, -1) ==1 ;

Buytemp = Cross(CL ,BL);
Shorttemp = Cross(BL , CL);



SetTradeDelays(0,0,0,0);

Buyprice1 = ValueWhen(Buy, O);
Shortprice1 = ValueWhen(Short, O);
StoplossPercent = (DayC/100)*Param("Stoploss Percent", 0.5, 0, 100, 0.01);
Targ1= Param("First Profit target", 1.6, 0, 100, 0.01);

BuyTarget= Buyprice1 + ( StoplossPercent*Targ1) ;
ShortTarget = shortprice1 - ( StoplossPercent*Targ1) ;
Buystop= Buyprice1 - StoplossPercent;
shortstop= Shortprice1 + StoplossPercent;

//bt=0;
//sl=0;




//exit code
/*
for(i=1;i<BarCount;i++){
if(Buy[i] && bstop[i] >0){ bt=BuyTarget[i];Buystop=bstop[i];sig=1;} else Buy[i]=0;
if(H[i]>=bt[i]){Sell[i]=1;SellPrice[i]=bt;}
if(L[i]<=bstop[i]){Sell[i]=1;SellPrice[i]=Buystop;} }

/*b1=IIf(Ref(High[i],0)>bt,1,0);
b2=IIf(Ref(Low[i],0)<Buystop,1,0);
SellPrice=IIf(b1==1,bt,IIf(b2==1,Buystop,0));
Sell= b1 OR b2;
fbt=IIf(bt>0,bt,0);
}
 */

//SellPrice=IIf(b1==1,ValueWhen(Sell[i],bt,1),IIf(b2==1,ValueWhen(Sell[i],Buystop,1),0));
//Chkb1=WriteIf(b2==1,"SL ran","Target ran");
 


for( i = 0; i < BarCount; i++ ){
/*if(Buystop[i]>0 && Buy[i]){
bt=BuyTarget[i];
sl=Buystop[i];
sig="Buy";
} */
if((Buytarget[i] >0 AND High[i] > Buytarget[i]) OR (Buystop[i] >0 AND Low[i]<Buystop[i])) {
Sell[i]=1;
SellPrice[i]=IIf(High[i] > Buytarget[i],Buytarget[i],IIf(Low[i]<Buystop[i],Buystop[i],0));
} else Sell[i]=0; 
}
 
Buy=ExRem(Buy,Sell) AND ExRem(Buy,Buytemp);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover) AND ExRem(Short,Shorttemp);
Cover=ExRem(Cover,Short);



YARROW = ParamToggle("Buy Sell Arrow", "Deactivate|Activate",0);

if(YARROW==0)
{
//BUY SHORT ARROW
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-15);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-25);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-20); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=15);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=25);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-20);

PlotShapes(IIf(Sell, shapeStar, shapeNone),colorViolet, 0,H, Offset= 20);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorOrange, 0,L, Offset=-20); 

}

Pricelevel = ParamToggle("Price Level", "Deactivate|Activate",0);

YBDIS = HighestVisibleValue(High) - LowestVisibleValue( Low);
BSPARA = Param("BUY SELL DIST",0.08,0.01,0.5,0.01);
Ydist = YBDIS *BSPARA; 

if(Pricelevel==0)
{

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

{ 
if( Buy[i] ) PlotText( "Buy\n@" + BuyPrice[i]+ "\n1St = "+BuyTarget[i]+"\nSL = "+Buystop[i], i, L[ i ]-Ydist[i],  colorWhite,colorBlue);
if( Sell[i] ){ PlotText( "Exit Long\n@" + SellPrice[i], i, H[ i ]+Ydist[i], colorWhite, colorViolet );
if(Buy[i]) {Plot(Buystop[i],"bstop",colorWhite,styleLine,Null,Null);}
//PlotText("chk\n@"+Chkb1,i, H[ i ]+Ydist[i], colorWhite, colorViolet );
}
if( Short[i] ) PlotText(  "\n1St = "+ShortTarget[i]+ "\nshort\n@" + ShortPrice[i], i, H[ i ]+Ydist[i], colorWhite, colorDarkRed ); 
if( Cover[i] ) PlotText( "Exit Short\n@" + CoverPrice[i], i, L[ i ]-Ydist[i], colorWhite, colorOrange ); 
}
}

Plot(CL,"Tenkan-sen (Conversion Line)", C1, styleLine); 
Plot(BL, "Kijun-sen (Base Line)", C2, styleLine);
Plot(LSA, "Senkou Span A (Leading Span A)", C3, styleLine, 0, 0, P3);
Plot(LSB, "Senkou Span B (Leading Span B)", C4, styleLine, 0, 0, P3);
Plot(C, "Chikou Span (Lagging Span)", C5, styleLine, 0, 0, P5);
PlotOHLC (LSA,LSA,LSB,LSB,"Cloud",IIf(LSA>LSB,ColorBlend(C3, colorWhite, 0.6),	ColorBlend(C4,colorWhite, 0.4)),styleCloud, 0, 0, P3, -2);
_SECTION_END();

_SECTION_BEGIN("Price");
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( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
Thanks again...
 

Similar threads