Simple Coding Help - No Promise.

josh1

Well-Known Member
How was the result
Screenshot from 2019-02-13 21-02-35.png

Though all scrips moved 2% or more, those with least positive diff. moved more compared to yesterday. This was a test. So I created one more Long Average range price (20 days).
Code:
Range = (H-L);
//Plot(Range,"Range",ParamColor("Range Color", colorGreen),styleLine);
AveragePrice = (H+L)/2;
RangePercent = Range/AveragePrice * 100;

Plot(RangePercent,"RangePercent",ParamColor("Percent Color", colorBlue),styleLine);
ARP = MA(RangePercent,Param("ARP MA Period",5,3,100,1));
LARP = MA(RangePercent,Param("LARP MA Period",20,10,100,1));
Plot(ARP,"ARP",ParamColor("ARP Color", colorTan),styleLine);
Plot(LARP,"LongARP",ParamColor("LARP Color", colorRed),styleLine);
//id = RangePercent>=ARP;
id = Cross(ARP,LARP);

Filter = 1;
//Filter = id;
AddColumn(RangePercent,"RangePercent");
AddColumn(ARP,"ARP");
Diff = RangePercent - ARP;
AddColumn(Diff,"Diff");
AddColumn(LARP,"LARP");

SetSortColumns(-4)
Below shares are still best for trading. Their LARP is > 3%. Which means they are moving more than 3% w.r.to their price for last 20 days. However volatility has started reducing where diff is negative.
1550073113714.png

NF and BNF are at the bottom along with Goldbees :)
1550073232616.png

Take this sample chart of Siemens. Volatility increases when ARP looks up and crosses LARP and we can get 4-5 days of good trading range in it.
Screenshot from 2019-02-13 21-29-05.png


Edit - I am sure that when NF and BNF become volatile, individual scrips will be much more volatile giving better trading opportunities.
 
Last edited:
View attachment 33373
Though all scrips moved 2% or more, those with least positive diff. moved more compared to yesterday. This was a test. So I created one more Long Average range price (20 days).
Code:
Range = (H-L);
//Plot(Range,"Range",ParamColor("Range Color", colorGreen),styleLine);
AveragePrice = (H+L)/2;
RangePercent = Range/AveragePrice * 100;

Plot(RangePercent,"RangePercent",ParamColor("Percent Color", colorBlue),styleLine);
ARP = MA(RangePercent,Param("ARP MA Period",5,3,100,1));
LARP = MA(RangePercent,Param("LARP MA Period",20,10,100,1));
Plot(ARP,"ARP",ParamColor("ARP Color", colorTan),styleLine);
Plot(LARP,"LongARP",ParamColor("LARP Color", colorRed),styleLine);
//id = RangePercent>=ARP;
id = Cross(ARP,LARP);

Filter = 1;
//Filter = id;
AddColumn(RangePercent,"RangePercent");
AddColumn(ARP,"ARP");
Diff = RangePercent - ARP;
AddColumn(Diff,"Diff");
AddColumn(LARP,"LARP");

SetSortColumns(-4)
Below shares are still best for trading. Their LARP is > 3%. Which means they are moving more than 3% w.r.to their price for last 20 days. However volatility has started reducing where diff is negative.
View attachment 33377
NF and BNF are at the bottom along with Goldbees :)
View attachment 33378
Take this sample chart of Siemens. Volatility increases when ARP looks up and crosses LARP and we can get 4-5 days of good trading range in it.
View attachment 33379

Edit - I am sure that when NF and BNF become volatile, individual scrips will be much more volatile giving better trading opportunities.

@josh1: These additions will allow us to see five days LARP difference whether they are rising or falling. May be something to see in it. Thanks.

Code:
LDiff1 = LARP - Ref(LARP,-1);
LDiff2 = Ref(LARP,-1) - Ref(LARP,-2);
LDiff3 = Ref(LARP,-2) - Ref(LARP,-3);
LDiff4 = Ref(LARP,-3) - Ref(LARP,-4);
LDiff5 = Ref(LARP,-4) - Ref(LARP,-5);

AddColumn(LDiff1,"LARP Diff-1");
AddColumn(LDiff2,"LARP Diff-2");
AddColumn(LDiff3,"LARP Diff-3");
AddColumn(LDiff4,"LARP Diff-4");
AddColumn(LDiff5,"LARP Diff-5");
 
I wrote a code with buy / sell / short / cover signal as below. Buy and short signal are fine but it always shows wrong close signal such as sell signal after a short or cover signal after a buy. Anyone can guild me how to remove it?

Code:
Hh = HHV( H, 27 );

Ll = LLV( L, 27 );

p1 = hh - ( hh - ll ) * 0.5;

Color1 =(ParamColor("(Highest Hi )",colorRed));

Plot( Hh, "p1:", Color1, styleLine +styleNoTitle);



Color2 =(ParamColor("hh - ( hh - ll ) * 0.5",colorViolet));

Plot( p1, "p1:", Color2, styleLine+styleNoTitle );



Color3 =(ParamColor("( ll )",colorWhite));

Plot( Ll, "p1:", Color3, styleLine+styleNoTitle );

macdvalue= EMA(C,12)-EMA(C,26);







buy1 = OBV()>EMA(OBV(),20);

sell1= EMA(OBV(),20)>OBV() ;



buy2 = RSI(15)>EMA(rsi(15),39);

sell2= EMA(rsi(15),39)>rsi(15) ;



buy3 = Ref(MACDvalue,-1)< MACDvalue ;

sell3= Ref(MACDvalue,-1)> MACDvalue;





closebuy =  Cross(Ref(ll,-1),C) OR Cross(p1,C) ;

closeshort = Cross(C,Ref(hh,-1)) OR Cross(C,p1) ;



Buy= buy1 AND  buy2 AND buy3 ;





Short= sell1 AND  Sell2 AND sell3 ;

Sell= Closebuy ;

Cover= closeshort ;



Buy=ExRem(Buy,Sell);

Sell=ExRem(Sell,Buy);

Short=ExRem(Short,Cover);

Cover=ExRem(Cover,Short);

Long=Flip(Buy,Sell);

Shrt=Flip(Short,Cover);

Relax = NOT Long AND NOT Buy AND NOT shrt AND NOT Sell AND NOT Sell AND NOT Cover;



BuyPrice=ValueWhen(Buy,C);

SellPrice=ValueWhen(Sell,C);

ShortPrice=ValueWhen(Short,C);

CoverPrice=ValueWhen(Cover,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(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                    

PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);



PlotShapes(IIf(Sell, shapeStar, shapeNone),colorgreen, 0, L, Offset=-15);

PlotShapes(IIf(Cover, shapeStar, shapeNone),colorred, 0,L, Offset=-15);



_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();

for(i=BarCount-1;i>1;i--)

{

if(Buy == 1)

{

entry = C;

sig = "BUY";





bars = i;

i = 0;

}

if(Sell == 1)

{

sig = "CLOSE BUY";

entry = C;





bars = i;

i = 0;

}

if(short == 1)

{

sig = "SHORT";

entry = C;





bars = i;

i = 0;

}

if(Cover == 1)

{

sig = " CLOSE SHORT";

entry = C;





bars = i;

i = 0;

}

}

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

{

PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);
}
 
I wrote a code with buy / sell / short / cover signal as below. Buy and short signal are fine but it always shows wrong close signal such as sell signal after a short or cover signal after a buy. Anyone can guild me how to remove it?

Code:
Hh = HHV( H, 27 );

Ll = LLV( L, 27 );

p1 = hh - ( hh - ll ) * 0.5;

Color1 =(ParamColor("(Highest Hi )",colorRed));

Plot( Hh, "p1:", Color1, styleLine +styleNoTitle);



Color2 =(ParamColor("hh - ( hh - ll ) * 0.5",colorViolet));

Plot( p1, "p1:", Color2, styleLine+styleNoTitle );



Color3 =(ParamColor("( ll )",colorWhite));

Plot( Ll, "p1:", Color3, styleLine+styleNoTitle );

macdvalue= EMA(C,12)-EMA(C,26);







buy1 = OBV()>EMA(OBV(),20);

sell1= EMA(OBV(),20)>OBV() ;



buy2 = RSI(15)>EMA(rsi(15),39);

sell2= EMA(rsi(15),39)>rsi(15) ;



buy3 = Ref(MACDvalue,-1)< MACDvalue ;

sell3= Ref(MACDvalue,-1)> MACDvalue;





closebuy =  Cross(Ref(ll,-1),C) OR Cross(p1,C) ;

closeshort = Cross(C,Ref(hh,-1)) OR Cross(C,p1) ;



Buy= buy1 AND  buy2 AND buy3 ;





Short= sell1 AND  Sell2 AND sell3 ;

Sell= Closebuy ;

Cover= closeshort ;



Buy=ExRem(Buy,Sell);

Sell=ExRem(Sell,Buy);

Short=ExRem(Short,Cover);

Cover=ExRem(Cover,Short);

Long=Flip(Buy,Sell);

Shrt=Flip(Short,Cover);

Relax = NOT Long AND NOT Buy AND NOT shrt AND NOT Sell AND NOT Sell AND NOT Cover;



BuyPrice=ValueWhen(Buy,C);

SellPrice=ValueWhen(Sell,C);

ShortPrice=ValueWhen(Short,C);

CoverPrice=ValueWhen(Cover,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(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                

PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);



PlotShapes(IIf(Sell, shapeStar, shapeNone),colorgreen, 0, L, Offset=-15);

PlotShapes(IIf(Cover, shapeStar, shapeNone),colorred, 0,L, Offset=-15);



_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();

for(i=BarCount-1;i>1;i--)

{

if(Buy == 1)

{

entry = C;

sig = "BUY";





bars = i;

i = 0;

}

if(Sell == 1)

{

sig = "CLOSE BUY";

entry = C;





bars = i;

i = 0;

}

if(short == 1)

{

sig = "SHORT";

entry = C;





bars = i;

i = 0;

}

if(Cover == 1)

{

sig = " CLOSE SHORT";

entry = C;





bars = i;

i = 0;

}

}

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

{

PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);
}
@hungboss1: Check out my post #5,786, in this thread, you will get your answers.
 
Sorry can you explain clearly because I just modified and combined many codes from internet in order to make this code. I am actually not a coder so I do not understand why this problem happened

@hungboss1: Go line by line and compare your similar lines, check for syntax. Also, remove/comment out Long and Shrt part and re-check your Relax. If you have assimilated that means you know its sequences, hence should be easy for you.
 
I tried to remove Long Shrt part and fix Relax as below. Most of strategies I have seen only use Buy and Short and the code in your post #5786 also. It does not have any relax time. I think problem is closebuy and closeshort part but really do not know how to fix it. Try code Sell=ExRem(Sell,Cover); Cover=ExRem(Cover,sell); as well but does not work.


Code:
macdvalue= EMA(C,12)-EMA(C,26);

buy1 = OBV()>EMA(OBV(),20);
sell1= EMA(OBV(),20)>OBV() ;

buy2 = RSI(15)>EMA(rsi(15),39);
sell2= EMA(rsi(15),39)>rsi(15) ;

buy3 = Ref(MACDvalue,-1)< MACDvalue ;
sell3= Ref(MACDvalue,-1)> MACDvalue;


Buy= buy1 AND  buy2 AND buy3  ;


Short= sell1 AND  Sell2 AND sell3;


closebuy =  Cross(Ref(p1,0),C )  ;
closeshort = Cross(C, Ref(p1,0)) ;

Sell= Closebuy ;
Cover= closeshort ;

Buy=ExRem(Buy,sell);
Sell=ExRem(Sell,buy);
Short=ExRem(Short,cover);
Cover=ExRem(Cover,short);


Relax =  NOT Buy AND NOT Sell AND NOT Short AND NOT Cover;

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,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(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                     
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Sell, shapeStar, shapeNone),colorgreen, 0, L, Offset=-15);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorred, 0,L, Offset=-15);
 
I tried to remove Long Shrt part and fix Relax as below. Most of strategies I have seen only use Buy and Short and the code in your post #5786 also. It does not have any relax time. I think problem is closebuy and closeshort part but really do not know how to fix it. Try code Sell=ExRem(Sell,Cover); Cover=ExRem(Cover,sell); as well but does not work.


Code:
macdvalue= EMA(C,12)-EMA(C,26);

buy1 = OBV()>EMA(OBV(),20);
sell1= EMA(OBV(),20)>OBV() ;

buy2 = RSI(15)>EMA(rsi(15),39);
sell2= EMA(rsi(15),39)>rsi(15) ;

buy3 = Ref(MACDvalue,-1)< MACDvalue ;
sell3= Ref(MACDvalue,-1)> MACDvalue;


Buy= buy1 AND  buy2 AND buy3  ;


Short= sell1 AND  Sell2 AND sell3;


closebuy =  Cross(Ref(p1,0),C )  ;
closeshort = Cross(C, Ref(p1,0)) ;

Sell= Closebuy ;
Cover= closeshort ;

Buy=ExRem(Buy,sell);
Sell=ExRem(Sell,buy);
Short=ExRem(Short,cover);
Cover=ExRem(Cover,short);


Relax =  NOT Buy AND NOT Sell AND NOT Short AND NOT Cover;

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,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(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                    
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Sell, shapeStar, shapeNone),colorgreen, 0, L, Offset=-15);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorred, 0,L, Offset=-15);
@hungboss1: I suggest - try plotting all those conditions as lines (buy1, buy2, buy3 etc etc etc) first on your chart to see when are the conditions being met. The "Relax" statement has no relevance, since it is not being used to do any evaluations other than within the statement, unless you are using it in some other part of the code. Thanks.
 

Similar threads