Assignment is allowed only for variables or array elements

Questions about MultiCharts and user contributed studies.
Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Assignment is allowed only for variables or array elements

Postby Splint » 04 Oct 2018

At the end of a system I'm compiling I get an message assignment is allowed only for variables or array elements. Multicharts is not happy with MaxTradeClose.

//-----Functions Used in the Code---------
{---Function MaxTradeClose---}
if marketposition <> 1 then Maxtradeclose=-999999;
if marketposition=1 and C>Maxtradeclose[1] then Maxtradeclose=C;
{---Function MinTradeClose---}
if marketposition <>-1 then Mintradeclose=999999;
if marketposition=-1 and C<Mintradeclose[1] then Mintradeclose=C;
{---Function MaxTradeHigh---}
if marketposition <> 1 then Maxtradehigh=-999999;
if marketposition=1 and H>Maxtradehigh[1] then Maxtradehigh=H;
{---Function MinTradeLow---}
if marketposition <>-1 then Mintradelow=999999;
if marketposition=-1 and L<Mintradelow[1] then Mintradelow=L;

The code for Maxtradeclose:
[LegacyColorValue = TRUE];
if marketposition <> 1 then Maxtradeclose=-999999;
if marketposition=1 and C>Maxtradeclose[1] then Maxtradeclose=C;

The spelling of the Maxtradeclose is consistent throughout the code and in the name. Any idea what's wrong?

User avatar
TJ
Posts: 7210
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2052 times

Re: Assignment is allowed only for variables or array elements

Postby TJ » 04 Oct 2018

See post #1 & post #2
viewtopic.php?t=11713

Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Re: Assignment is allowed only for variables or array elements

Postby Splint » 04 Oct 2018

At the end of a system I'm compiling I get an message assignment is allowed only for variables or array elements. Multicharts is not happy with MaxTradeClose.

Code: Select all

//-----Functions Used in the Code---------

{---Function MaxTradeClose---}
if marketposition <> 1 then Maxtradeclose = -999999;
if marketposition = 1 and C > Maxtradeclose[1] then Maxtradeclose = C;

{---Function MinTradeClose---}
if marketposition <> -1 then Mintradeclose = 999999;
if marketposition = -1 and C < Mintradeclose[1] then Mintradeclose = C;

{---Function MaxTradeHigh---}
if marketposition <> 1 then Maxtradehigh = -999999;
if marketposition = 1 and H > Maxtradehigh[1] then Maxtradehigh = H;

{---Function MinTradeLow---}
if marketposition <> -1 then Mintradelow = 999999;
if marketposition = -1 and L < Mintradelow[1] then Mintradelow = L;
The code for Maxtradeclose:

Code: Select all

[LegacyColorValue = TRUE];

if marketposition <> 1 then Maxtradeclose = -999999;
if marketposition = 1 and C > Maxtradeclose[1] then Maxtradeclose = C;
The spelling of the Maxtradeclose is consistent throughout the code and in the name. Any idea what's wrong?

User avatar
ABC
Posts: 631
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 356 times
Contact:

Re: Assignment is allowed only for variables or array elements

Postby ABC » 04 Oct 2018

Splint,

is Maxtradeclose a function on your end? Where does the code starting with "//-----Functions Used in the Code---------" reside, is it in a system or in a separate function?

Regards,

ABC

Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Re: Assignment is allowed only for variables or array elements

Postby Splint » 05 Oct 2018

The this is how the code appears. It was written for TS but I'm trying to adjust the code for MC. I realized while writing this that the problematic code is not part of the signal but a foot note containing the functions. There are still a few bugs which need to be ironed out so if anyone's interested in helping with that, I'd be grateful. A side note, in the navigator window of the editor, I see the fx icons have either red font or black font, does this mean there is a problem with the function? Anyway, I thought converting TS code to MS code might be an easy start in learning Powerlanguage.

Code: Select all

{Long Entry}
IF MarketPosition=0 THEN
BEGIN
IF CCI(20) crosses above 170 THEN Buy next bar at market;
END;

{Long Exits}
IF MarketPosition=1 THEN
BEGIN
sell("L 24 ch") Lowest(L,24) Stop;
IF C > 3 * AvgTrueRange(25) + EntryPrice THEN sell ("L3/10Ch") Lowest(L, 10)
Stop;
IF MaxTradeHigh >= EntryPrice + 4 * AvgTrueRange(25) THEN sell ("L2Atr")
EntryPrice + 2 * AvgTrueRange(25) Stop;
IF C > 6 * AvgTrueRange(25) + EntryPrice THEN sell ("L6/4Ch") Lowest(L, 4) Stop;
IF MaxTradeClose > EntryPrice + 1 * AvgTrueRange(25) and MaxTradeClose >
MaxTradeClose[3] and Adx(14) < Adx(14)[3] THEN sell ("LDev") Lowest(L,1) Stop;
END;

{Short Entry}
IF MarketPosition=0 THEN
BEGIN
IF CCI(20) crosses below -170 THEN Sell("S Entry") Open;
END;

{Short Exits}
IF MarketPosition= -1 THEN BEGIN
buytocover("S 24 Ch") Highest(H,24) Stop;
IF C < EntryPrice - 3 * AvgTrueRange(25) THEN buytocover ("S3/10Ch") Highest(H,10)
Stop;
IF MinTradeLow <= EntryPrice - 4 * AvgTrueRange(25) THEN buytocover("S2Atr")
EntryPrice - 2 * AvgTrueRange(25) Stop;
IF C < EntryPrice - 6 * AvgTrueRange(25) THEN buytocover ("S6/4Ch") Highest(H,4) Stop;
IF MinTradeClose < EntryPrice - 1 * AvgTrueRange(25) and MinTradeClose <
MinTradeClose[5] and Adx(14) < Adx(14)[5] THEN buytocover("SDev") Highest(H,5) Stop;
END;

//-----Functions Used in the Code---------

{---Function MaxTradeClose---}
if marketposition <> 1 then Maxtradeclose=-999999;
if marketposition=1 and C>Maxtradeclose[1] then Maxtradeclose=C;

{---Function MinTradeClose---}
if marketposition <>-1 then Mintradeclose=999999;
if marketposition=-1 and C<Mintradeclose[1] then Mintradeclose=C;

{---Function MaxTradeHigh---}
if marketposition <> 1 then Maxtradehigh=-999999;
if marketposition=1 and H>Maxtradehigh[1] then Maxtradehigh=H;

{---Function MinTradeLow---}
if marketposition <>-1 then Mintradelow=999999;
if marketposition=-1 and L<Mintradelow[1] then Mintradelow=L;

User avatar
c0ntango
Posts: 25
Joined: 13 Sep 2018
Has thanked: 2 times
Been thanked: 2 times
Contact:

Re: Assignment is allowed only for variables or array elements

Postby c0ntango » 08 Oct 2018

Hey, Splint!

Here's the fixed code for you. You need to create 4 new functions with the function names described in the comments in the bottom and compile them. Leave them commented out though.

Unfortunately my initial assessment of the system is that it does not going to generate beautiful profits for you. Let me know if you need any help with that.

-Ben


Code: Select all


{Long Entry}
IF MarketPosition=0 THEN
BEGIN
IF CCI(20) crosses above 170 THEN Buy next bar at market;
END;

{Long Exits}
IF MarketPosition=1 THEN
BEGIN
sell("L 24 ch") next bar Lowest(L,24) Stop;

IF C > 3 * AvgTrueRange(25) + EntryPrice THEN sell ("L3/10Ch") next bar at Lowest(L, 10) Stop;

IF MaxTradeHigh >= EntryPrice + 4 * AvgTrueRange(25) THEN sell ("L2Atr") next bar at
EntryPrice + 2 * AvgTrueRange(25) Stop;

IF C > 6 * AvgTrueRange(25) + EntryPrice THEN sell ("L6/4Ch") next bar at Lowest(L, 4) Stop;

IF MaxTradeClose > EntryPrice + 1 * AvgTrueRange(25) and MaxTradeClose >
MaxTradeClose[3] and Adx(14) < Adx(14)[3] THEN sell ("LDev") next bar at Lowest(L,1) Stop;
END;

{Short Entry}
IF MarketPosition=0 THEN
BEGIN
IF CCI(20) crosses below -170 THEN Sell("S Entry") next bar Open;
END;

{Short Exits}
IF MarketPosition= -1 THEN
BEGIN
buytocover("S 24 Ch") next bar Highest(H,24) Stop;
IF C < EntryPrice - 3 * AvgTrueRange(25) THEN buytocover ("S3/10Ch") next bar Highest(H,10)
Stop;

IF MinTradeLow <= EntryPrice - 4 * AvgTrueRange(25) THEN buytocover("S2Atr") next bar
EntryPrice - 2 * AvgTrueRange(25) Stop;

IF C < EntryPrice - 6 * AvgTrueRange(25) THEN buytocover ("S6/4Ch") next bar Highest(H,4) Stop;

IF MinTradeClose < EntryPrice - 1 * AvgTrueRange(25) and MinTradeClose <
MinTradeClose[5] and Adx(14) < Adx(14)[5] THEN buytocover("SDev") next bar Highest(H,5) Stop;
END;


{
//-----Functions Used in the Code---------

{---Function MaxTradeClose---}
if marketposition <> 1 then Maxtradeclose=-999999;
if marketposition=1 and C>Maxtradeclose[1] then Maxtradeclose=C;

{---Function MinTradeClose---}
if marketposition <>-1 then Mintradeclose=999999;
if marketposition=-1 and C<Mintradeclose[1] then Mintradeclose=C;

{---Function MaxTradeHigh---}
if marketposition <> 1 then Maxtradehigh=-999999;
if marketposition=1 and H>Maxtradehigh[1] then Maxtradehigh=H;

{---Function MinTradeLow---}
if marketposition <>-1 then Mintradelow=999999;
if marketposition=-1 and L<Mintradelow[1] then Mintradelow=L;

}

maxmax68
Posts: 160
Joined: 20 Nov 2012
Has thanked: 52 times
Been thanked: 47 times

Re: Assignment is allowed only for variables or array elements

Postby maxmax68 » 08 Oct 2018

Why complicate things with useless functions when it would be enough to use variables?

Code: Select all


Vars:
Maxtradeclose(-999999),
Mintradeclose(999999),
Maxtradehigh(-999999),
Mintradelow(999999);

if marketposition <> 1 then Maxtradeclose=-999999;
if marketposition=1 and C>Maxtradeclose[1] then Maxtradeclose=C;

if marketposition <>-1 then Mintradeclose=999999;
if marketposition=-1 and C<Mintradeclose[1] then Mintradeclose=C;

if marketposition <> 1 then Maxtradehigh=-999999;
if marketposition=1 and H>Maxtradehigh[1] then Maxtradehigh=H;

if marketposition <>-1 then Mintradelow=999999;
if marketposition=-1 and L<Mintradelow[1] then Mintradelow=L;

{Long Entry}
IF MarketPosition=0 THEN
BEGIN
IF CCI(20) crosses above 170 THEN Buy next bar at market;
END;

{Long Exits}
IF MarketPosition=1 THEN
BEGIN
sell("L 24 ch") next bar Lowest(L,24) Stop;

IF C > 3 * AvgTrueRange(25) + EntryPrice THEN sell ("L3/10Ch") next bar at Lowest(L, 10) Stop;

IF MaxTradeHigh >= EntryPrice + 4 * AvgTrueRange(25) THEN sell ("L2Atr") next bar at
EntryPrice + 2 * AvgTrueRange(25) Stop;

IF C > 6 * AvgTrueRange(25) + EntryPrice THEN sell ("L6/4Ch") next bar at Lowest(L, 4) Stop;

IF MaxTradeClose > EntryPrice + 1 * AvgTrueRange(25) and MaxTradeClose >
MaxTradeClose[3] and Adx(14) < Adx(14)[3] THEN sell ("LDev") next bar at Lowest(L,1) Stop;
END;

{Short Entry}
IF MarketPosition=0 THEN
BEGIN
IF CCI(20) crosses below -170 THEN Sell("S Entry") next bar Open;
END;

{Short Exits}
IF MarketPosition= -1 THEN
BEGIN
buytocover("S 24 Ch") next bar Highest(H,24) Stop;
IF C < EntryPrice - 3 * AvgTrueRange(25) THEN buytocover ("S3/10Ch") next bar Highest(H,10)
Stop;

IF MinTradeLow <= EntryPrice - 4 * AvgTrueRange(25) THEN buytocover("S2Atr") next bar
EntryPrice - 2 * AvgTrueRange(25) Stop;

IF C < EntryPrice - 6 * AvgTrueRange(25) THEN buytocover ("S6/4Ch") next bar Highest(H,4) Stop;

IF MinTradeClose < EntryPrice - 1 * AvgTrueRange(25) and MinTradeClose <
MinTradeClose[5] and Adx(14) < Adx(14)[5] THEN buytocover("SDev") next bar Highest(H,5) Stop;
END;
Best regards
Massimo

User avatar
c0ntango
Posts: 25
Joined: 13 Sep 2018
Has thanked: 2 times
Been thanked: 2 times
Contact:

Re: Assignment is allowed only for variables or array elements

Postby c0ntango » 09 Oct 2018

Yeah, the code is not particularly beautiful, but at least it works now. Since it doesn't do much other than shred money in a live trading context, I didn't figure it would be worth more attention :D

Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Re: Assignment is allowed only for variables or array elements

Postby Splint » 13 Oct 2018

Thanks everyone for your help with this. I didn't code this myself, found it online years ago and thought it might be worth back testing. If nothing else I can compare the code which will help me learn Powerlanguage. Thanks again.


Return to “MultiCharts”