# 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

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); // 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
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

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

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); lx = Close < Lowest(Close,LX_Lookback) ; se = Close < Lowest(Close,SE_Lookback) ; sx = Close > Highest(Close,SX_Lookback); 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); // 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; ```

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

### Re: Plotting indicator within strategy

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); lx = Close < Lowest(Close,LX_Lookback) ; se = Close < Lowest(Close,SE_Lookback) ; sx = Close > Highest(Close,SX_Lookback); 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); // 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

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?

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

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

### Re: Plotting indicator within strategy

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

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); // 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

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

### Re: Plotting indicator within strategy  [SOLVED]

::
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

Go to Format Study,

Change the Plot Type to "Left Tick".

Amazing, it works! Super supportforum. MC rules, hehe

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

### Re: Plotting indicator within strategy

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); // Plot the new plot for x = 0 to 9 begin Plot1[x](highestHigh, "HighestHigh") ; end; if Barstatus = 2 then NoPlot(1); END; ``` Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

### Re: Plotting indicator within strategy

Will use that then.
Merci