I want to test an indicator that changes colour when going long or short. How can I program it with reference to the colour change to buy or sell a contract.
Need more information / parameters , code for indicators would help , i will give it a go
The indicator I am testing is Ron Blacks Swing Line Indicator. Thanks
Here is the code:
//PRC_SwingLine Ron Black | indicator
//20.09.2017
//Nicolas @ http://www.prorealcode.com
//Sharing ProRealTime knowledge
if upsw=1 then
if high>hH then
hH=high
endif
if low>hL then
hL=low
endif
if high<hL then
upsw=0
lL=low
lH=high
endif
endif
if upsw=0 then
if low<lL then
lL=low
endif
if high<lH then
lH=high
endif
if low>lH then
upsw=1
hH=high
hL=low
endif
endif
if upsw=1 then
swingline=hL
r=0
g=255
b=255
else
swingline=lH
r=255
g=0
b=255
endif
return swingline coloured(r,g,b) style(line,2) as “Swing Line”
use the <> symbol to post code and a screenshot of indi on a chart would be nice , Some clear definition of EXACTLY what you require would be nice as well
If you require a sell/buy on indicator colourchange you will need more than just an indicator also >> a pro order code required
Hint its pretty hard to produce an accurate precision pro order code on ambiguous non existant plan … details required
//PRC_SwingLine Ron Black | indicator
//20.09.2017
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
if upsw=1 then
if high>hH then
hH=high
endif
if low>hL then
hL=low
endif
if high<hL then
upsw=0
lL=low
lH=high
endif
endif
if upsw=0 then
if low<lL then
lL=low
endif
if high<lH then
lH=high
endif
if low>lH then
upsw=1
hH=high
hL=low
endif
endif
if upsw=1 then
swingline=hL
r=0
g=255
b=255
else
swingline=lH
r=255
g=0
b=255
endif
return swingline coloured(r,g,b) style(line,2) as "Swing Line"
The magenta and green lines weaving through the candles are the indicator
The magenta and green lines weaving through the candles are the indicator
Still not a precise request but ive assumed this is what you require , you need to get better at defining parameters , still very ambiguous . Anyway as i expected what ive written chops you up in all but strong trending periods . More filter required imo
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = CALL "PRC_SwingLine Ron Black"
indicator2 = CALL "PRC_SwingLine Ron Black"
c1 = (indicator1[1] < indicator2)
IF c1 THEN
BUY 1 SHARES AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = CALL "PRC_SwingLine Ron Black"
indicator4 = CALL "PRC_SwingLine Ron Black"
c2 = (indicator3[1] > indicator4)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator5 = CALL "PRC_SwingLine Ron Black"
indicator6 = CALL "PRC_SwingLine Ron Black"
c3 = (indicator5[1] > indicator6)
IF c3 THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
// Conditions to exit short positions
indicator7 = CALL "PRC_SwingLine Ron Black"
indicator8 = CALL "PRC_SwingLine Ron Black"
c4 = (indicator7[1] < indicator8)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
Thanks very much for your help. I will include other parameters to strengthen the code, as I am aware how to do that. It was the colour changes that had me confused. Sorry for the ambiguity, will try and be clearer next time.
This is probably a better easier way to produce code
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// indicator shortcut
z = CALL "PRC_SwingLine Ron Black"
// Conditions to enter long positions
indicator1 = z
indicator2 = z
c1 = (indicator1[1] < indicator2)
IF c1 THEN
BUY 1 SHARES AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = z
indicator4 = z
c2 = (indicator3[1] > indicator4)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator5 = z
indicator6 = z
c3 = (indicator5[1] > indicator6)
IF c3 THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
// Conditions to exit short positions
indicator7 = z
indicator8 = z
c4 = (indicator7[1] < indicator8)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
Or even go a step further . Just trying to reduce lines and characters in code , this is all good practice for me
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// indicator shortcut
z = CALL "PRC_SwingLine Ron Black"
// Conditions to enter long positions
c1 = z[1] < z
IF c1 THEN
BUY 1 SHARES AT MARKET
ENDIF
// Conditions to exit long positions
c2 = z[1] > z
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
c3 = z[1] > z
IF c3 THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
// Conditions to exit short positions
c4 = z[1] < z
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
Colours don’t exist, they are just a graphical way to make prices/lines clearer.
If a candlestick is blue (or green or white) you know it’s a BULLish one. A piece of code can only tell it because you let it compare the closing price to the opening one, if it’s greater it must be BULLish!
So to know if a n SMA line is green you simply have to test whether the current closing price is greater than the one of the previous candlestick
Sma = average[20](close)
IF Sma > Sma[1] THEN //Green/Blue/White colour (Bullish)
.
.
ELSE //Red/Black colour (Bearish)
.
.
ENDIF