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?
Assignment is allowed only for variables or array elements
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Re: Assignment is allowed only for variables or array elements
See post #1 & post #2
viewtopic.php?t=11713
viewtopic.php?t=11713
Re: Assignment is allowed only for variables or array elements
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.
The code for Maxtradeclose:
The spelling of the Maxtradeclose is consistent throughout the code and in the name. Any idea what's wrong?
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;
Code: Select all
[LegacyColorValue = TRUE];
if marketposition <> 1 then Maxtradeclose = -999999;
if marketposition = 1 and C > Maxtradeclose[1] then Maxtradeclose = C;
- ABC
- Posts: 718
- Joined: 16 Dec 2006
- Location: www.abctradinggroup.com
- Has thanked: 125 times
- Been thanked: 408 times
- Contact:
Re: Assignment is allowed only for variables or array elements
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
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
Re: Assignment is allowed only for variables or array elements
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;
Re: Assignment is allowed only for variables or array elements
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
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;
}
Re: Assignment is allowed only for variables or array elements
Why complicate things with useless functions when it would be enough to use variables?
Best regards
Massimo
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;
Massimo
Re: Assignment is allowed only for variables or array elements
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
Re: Assignment is allowed only for variables or array elements
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.