I have an efs study that paints price bars purely based on price action (no indicators). When the current bar makes a higher high than the previous bar, it should paint green, if it makes a lower low, it should paint red. If not (like an inside bar), paint it grey.
The thing is: it doesn't load properly. I changed it because it used to color based on every tick. I added a condition to paint it only on every new bar, but now it doesn't really change the color until I reload the efs.
Can anyboyd help?
Here it is:
function preMain() {
setPriceStudy(true);
setColorPriceBars(true);
setDefaultPriceBarColor(Color.lightgrey);
setStudyTitle("3BR c");
}
function main() {
if (getBarState() == BARSTATE_NEWBAR) {
if(low(-1) < low(-2) && high(-2) > high(-1) && low() > low(-1) ) {
if(close() > high(-1) || high() > high(-1) && !Strategy.isLong() ) {
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
else
{
if(close() > low(-1) || low() > low(-1) && Strategy.isLong() ) { //* inside bar
Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.THISBAR);
}
}
}
else
{
if(high() > high(-1) && !Strategy.isLong()) {
if(low() <= low(-1)) { //* if engulfing candle (NOTE last change: made <= instead of < )
if(close() > open()) { //* removed '=' sign from '>='
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
else
{
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
}
else
{
//* if HH/HL candle
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
}
else
{
if(high(-2) < high(-1) && low(-2) < low(-1) && high() < high(-1) ) {
if(close() < low(-1) || low() < low(-1) && !Strategy.isShort() ) {
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
else
{
if(close() > low(-1) || low() > low(-1) && Strategy.isShort() ) { //* inside bar
Strategy.doCover("Cover Short", Strategy.MARKET, Strategy.THISBAR);
}
}
}
else
{
if(low() < low(-1) && !Strategy.isShort()) {
if(high() >= high(-1)) { //* if engulfing candle (NOTE last change made >= instead of > )
if(close() < open()) { //* removed '=' sign from '<='
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
else
{
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
}
else
{
//* if LL/LH candle
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
}
}
}
}
} //if BARSTATE_NEWBAR
;
if(Strategy.isLong()){
setPriceBarColor(Color.lime);
}
else
{
if(Strategy.isShort()){
setPriceBarColor(Color.red);
}
else
//not Long or Short = default color: grey
{
setPriceBarColor(Color.lightgrey);
}
}
;
return;
}
The thing is: it doesn't load properly. I changed it because it used to color based on every tick. I added a condition to paint it only on every new bar, but now it doesn't really change the color until I reload the efs.
Can anyboyd help?
Here it is:
function preMain() {
setPriceStudy(true);
setColorPriceBars(true);
setDefaultPriceBarColor(Color.lightgrey);
setStudyTitle("3BR c");
}
function main() {
if (getBarState() == BARSTATE_NEWBAR) {
if(low(-1) < low(-2) && high(-2) > high(-1) && low() > low(-1) ) {
if(close() > high(-1) || high() > high(-1) && !Strategy.isLong() ) {
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
else
{
if(close() > low(-1) || low() > low(-1) && Strategy.isLong() ) { //* inside bar
Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.THISBAR);
}
}
}
else
{
if(high() > high(-1) && !Strategy.isLong()) {
if(low() <= low(-1)) { //* if engulfing candle (NOTE last change: made <= instead of < )
if(close() > open()) { //* removed '=' sign from '>='
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
else
{
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
}
else
{
//* if HH/HL candle
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
}
else
{
if(high(-2) < high(-1) && low(-2) < low(-1) && high() < high(-1) ) {
if(close() < low(-1) || low() < low(-1) && !Strategy.isShort() ) {
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
else
{
if(close() > low(-1) || low() > low(-1) && Strategy.isShort() ) { //* inside bar
Strategy.doCover("Cover Short", Strategy.MARKET, Strategy.THISBAR);
}
}
}
else
{
if(low() < low(-1) && !Strategy.isShort()) {
if(high() >= high(-1)) { //* if engulfing candle (NOTE last change made >= instead of > )
if(close() < open()) { //* removed '=' sign from '<='
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
else
{
Strategy.doLong("Long", Strategy.MARKET, Strategy.THISBAR);
}
}
else
{
//* if LL/LH candle
Strategy.doShort("Short", Strategy.MARKET, Strategy.THISBAR);
}
}
}
}
}
} //if BARSTATE_NEWBAR
;
if(Strategy.isLong()){
setPriceBarColor(Color.lime);
}
else
{
if(Strategy.isShort()){
setPriceBarColor(Color.red);
}
else
//not Long or Short = default color: grey
{
setPriceBarColor(Color.lightgrey);
}
}
;
return;
}
Comment