Plotting indicator within strategy  [SOLVED]

Questions about MultiCharts and user contributed studies.
Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Plotting indicator within strategy

Postby Dirk8 » 03 Feb 2015

It seems not possible in 'signals' to use something like: if close > movingaverage(close,5) then plot(indicator x).
Within 'indicators' it's not possible to use 'marketposition'.

What I want to become, is that when the marketposition = 1, then I want to plot my stopindicator somewhere under, for example at lowest(low,5).
When marketposition is -1, then I want to plot my stopindicator somewhere up for example highest(high,5).

This is what I already have (thanks to Josh) to plot the lowest(close) nicely. Now I only want the see the lower when the marketposition = 1 or 0.

Code: Select all

Variables:
lowestClose(0), x(0);

if close > 0 then begin

lowestClose = Lowest(Close, 10)[1];

// Remove the old plot
for x = 0 to 10 begin

NoPlot[x](1);

end;

// Plot the new plot
for x = 0 to 9 begin

Plot1[x](lowestClose, "LowestLow");
end;

end;
Any ideas?
Attachments
sp_Stop.JPG
(44.33 KiB) Downloaded 1079 times
Last edited by Dirk8 on 04 Feb 2015, edited 1 time in total.

wegi
Posts: 121
Joined: 02 Jun 2009
Has thanked: 5 times
Been thanked: 12 times

Re: Plotting indicator within strategy

Postby wegi » 04 Feb 2015

Hi,


i transfer all values from a signal script to an indicator script with the i_set / i_getplotvalue function

Code: Select all

//transfer some value from a signal at position 1
i_setplotvalue(1,LH);

Code: Select all

//get the value at position 1 and plot them at an indicator script
myval = i_getplotvalue(1);
plot1(myval, "LH");

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plotting indicator within strategy

Postby Dirk8 » 04 Feb 2015

Hi Wegi, thanks for the idea.

Looked in wiki for more information about the i_setplotvalue but it's not clear where to put this in the signal and indicator.

I tried to put i_setplotvalue(1,Marketposition) as a variable but got: syntax error, unexpected 'identificator, expecting 'data' or 'data'.

First code is the signal, the second is the indicator. With this I got no errors but it's not really what it should be.
It's the Marketposition that I have to get into the indicator, isn't?

Code: Select all

Inputs:
LE_Lookback(100),
LX_Lookback(100),

SE_Lookback(100),
SX_Lookback(100),
StrategyName("SP");

Variables:
le(false),lx(false),
se(false),sx(false),
i_setplotvalue(1);

le = Close > Highest(Close,LE_Lookback)[1];
lx = Close < Lowest(Close,LX_Lookback)[1] ;

se = Close < Lowest(Close,SE_Lookback)[1] ;
sx = Close > Highest(Close,SX_Lookback)[1];

if MarketPosition = 0 then begin

if le and not lx and not se then begin
buy ("Long") next bar open;
end;

if se and sx = false and le = false then begin
sellshort ("Short") next bar open;
end;
end

else if MarketPosition = 1 then begin

if lx then begin
if se then begin
sellshort ("Short ") next bar open;
end;
end;

if lx then begin
sell ("LX") next bar open;
end;

end

else if MarketPosition = -1 then begin

if sx then begin
if le then begin
buy ("Long ") next bar open;
end;
end;

if sx then begin
buytocover ("SX") next bar open;
end;

end;
----------------------------------

Code: Select all

Variables:
lowestClose(0), x(0),
i_getplotvalue(1) ;

if i_getplotvalue = 1 then begin

lowestClose = Lowest(Close, 100)[1];

// Remove the old plot
for x = 0 to 10 begin

NoPlot[x](1);

end;

// Plot the new plot
for x = 0 to 9 begin

Plot1[x](lowestClose, "LowestClose");
end;

end;



User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2944 times

Re: Plotting indicator within strategy

Postby Henry MultiСharts » 05 Feb 2015

Hello Dirk8,

i_setplotvalue and i_getplotvalue were introduced in MultiCharts 9.0 Beta 1. If you are using MultiCharts for TWS 8.9 then these reserved words are not available in this version.

You do not need to declare i_setplotvalue and i_getplotvalue as variables. Here is how the code should look like:

Code: Select all

Inputs:
LE_Lookback(100),
LX_Lookback(100),

SE_Lookback(100),
SX_Lookback(100),
StrategyName("SP");

Variables:
le(false),lx(false),
se(false),sx(false);

le = Close > Highest(Close,LE_Lookback)[1];
lx = Close < Lowest(Close,LX_Lookback)[1] ;

se = Close < Lowest(Close,SE_Lookback)[1] ;
sx = Close > Highest(Close,SX_Lookback)[1];

if MarketPosition = 0 then begin

if le and not lx and not se then begin
buy ("Long") next bar open;
end;

if se and sx = false and le = false then begin
sellshort ("Short") next bar open;
end;
end

else if MarketPosition = 1 then begin

if lx then begin
if se then begin
sellshort ("Short ") next bar open;
end;
end;

if lx then begin
sell ("LX") next bar open;
end;

end

else if MarketPosition = -1 then begin

if sx then begin
if le then begin
buy ("Long ") next bar open;
end;
end;

if sx then begin
buytocover ("SX") next bar open;
end;

end;

i_setplotvalue(1, MarketPosition);

Code: Select all

Variables:
lowestClose(0), x(0);

if i_getplotvalue(1) = 1 then begin

lowestClose = Lowest(Close, 100)[1];

// Remove the old plot
for x = 0 to 10 begin

NoPlot[x](1);

end;

// Plot the new plot
for x = 0 to 9 begin

Plot1[x](lowestClose, "LowestClose");
end;

end;

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plotting indicator within strategy

Postby Dirk8 » 05 Feb 2015

MC for TWS is just for trial, I'm already using MC 64 v9.0 build 10360.

If I put i_setplotvalue(1, MarketPosition); just below the formula as you showed, the compiler gives: unknow function.

So, I seems I don't have the beta version?

What's best to do? Other program possibility or download the beta?

And when will this function be available in the MC for TWS?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2944 times

Re: Plotting indicator within strategy

Postby Henry MultiСharts » 05 Feb 2015

You do not need a different version - MC 64 v9.0 build 10360 is the latest one and has all of the newest features. "Unknown Function" error appears when you are using the code with i_setplotvalue and i_getplotvalue in MultiCharts for TWS that does not support this functionality (there is no ETA for updating MC for TWS to ver 9). Please use the proper PowerLanguage Editor from MC 64 v9.0 build 10360 (File->New->PowerLanguage Editor).

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plotting indicator within strategy

Postby Dirk8 » 05 Feb 2015

Indeed, no error now. Tough, the result is not as hoped (see chart). The goal is the have the shortExit-signal-line for the last 10 bars when the marketposition is short.

Code: Select all


Variables:
HighestHigh(0), x(0);

if i_getplotvalue(1) = -1 then begin

HighestHigh = Highest(high, 10)[1];

// Remove the old plot
for x = 0 to 10 begin

NoPlot[x](1);
end;

// Plot the new plot
for x = 0 to 9 begin

Plot1[x](highestHigh, "HighestHigh") ;

end;
end;
Like this it's almost the case. Not yet. Suggestions?
Attachments
shortexit.JPG
(42.11 KiB) Downloaded 1081 times

User avatar
TJ
Posts: 7284
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 992 times
Been thanked: 2071 times

Re: Plotting indicator within strategy  [SOLVED]

Postby TJ » 05 Feb 2015

::
Like this it's almost the case. Not yet. Suggestions?
Go to Format Study,

Change the Plot Type to "Left Tick".

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plotting indicator within strategy

Postby Dirk8 » 05 Feb 2015

Go to Format Study,

Change the Plot Type to "Left Tick".

Amazing, it works! :-)
Super supportforum. MC rules, hehe

User avatar
TJ
Posts: 7284
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 992 times
Been thanked: 2071 times

Re: Plotting indicator within strategy

Postby TJ » 05 Feb 2015

you can also simplify the code this way:
(it will run a tiny tiny tiny bit faster)

Code: Select all


Variables:
HighestHigh(0), x(0);

if i_getplotvalue(1) = -1 then
BEGIN

HighestHigh = Highest(high, 10)[1];


// Plot the new plot
for x = 0 to 9 begin

Plot1[x](highestHigh, "HighestHigh") ;

end;

if Barstatus = 2 then NoPlot[9](1);

END;

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plotting indicator within strategy

Postby Dirk8 » 05 Feb 2015

Will use that then.
Merci


Return to “MultiCharts”