Help with Study

Questions about MultiCharts and user contributed studies.
Kamisyed
Posts: 8
Joined: 25 Feb 2014
Has thanked: 1 time
Been thanked: 3 times

Help with Study

Postby Kamisyed » 25 Feb 2014

I have the following Long-Only Study:
Buy Signal: EMA3 crosses above EMA8
Exit Signal: EMA3 crosses below EMA8

Money Management:
Starting Account Balance: 10,000
% Account Size at Risk per Trade: 1%
Position Size: (Account Size * Risk%) / (((EMA3-EMA8)/EMA8)*2)
Max Position Size: 10% of Account Size

Study Code is as follows:
Input: OriginalStake(10000); { starting capital }
Input: Risk(0.01);

Vars: CurrentBalance(0), PositionSize(0); maxshares(0);

CurrentBalance = OriginalStake + NetProfit;
PositionSize = (CurrentBalance * Risk)/((XAverage(Close,3)-XAverage(Close,8))/(XAverage(Close,8))*2);
maxshares = (CurrentBalance * 0.1 / close);

condition1 = XAverage(Close,3) crosses above XAverage(Close,8);
condition2 = XAverage(Close,3) crosses below XAverage(Close,8);

if condition1 then buy next bar PositionSize Shares at open;
if condition2 then sell next bar at open;

// Stop loss //

if marketposition > 0 and positionprofit <= 0 then
begin
setstoploss(C*(1-((XAverage(Close,3)-XAverage(Close,8))/XAverage(Close,8)));
end;


I get the following error when compiling:
Line 8 column 0 which is:
maxshares = (CurrentBalance * .1/Close);

What am I doing Wrong?? I've fried my brain trying to figure it out (not a programmer!)

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

Re: Help with Study

Postby Henry MultiСharts » 25 Feb 2014

Hello Kamisyed,

There were multiple errors in the code:
maxshares is a reserved word and cannot be used as a variable name;
variables are enumerated using a comma;
missing brackets;
missing order of attributes for order generation command;
wrong order of attributes for order generation command.

Working code:

Code: Select all

Input: OriginalStake(10000); { starting capital }
Input: Risk(0.01);

Vars: CurrentBalance(0), PositionSize(0), var_maxshares(0);

CurrentBalance = OriginalStake + NetProfit;
PositionSize = (CurrentBalance * Risk)/((XAverage(Close,3)-XAverage(Close,8))/(XAverage(Close,8))*2);
var_maxshares = (CurrentBalance * 0.1 / close);

condition1 = XAverage(Close,3) crosses above XAverage(Close,8);
condition2 = XAverage(Close,3) crosses below XAverage(Close,8);

if condition1 then buy PositionSize shares next bar at open limit;
if condition2 then sell next bar at open limit;

// Stop loss //

if marketposition > 0 and positionprofit <= 0 then
begin
setstoploss(C*(1-((XAverage(Close,3)-XAverage(Close,8))/XAverage(Close,8))));
end;
There are very basic things that are covered by most of the guidelines.
You can find useful information about coding on the Power Language at this web page under Additional information sources:
https://www.multicharts.com/trading-sof ... on_Sources
Complete list of PowerLanguage Keywords can be found at this page under PowerLanguage Keyword Reference section:
https://www.multicharts.com/trading-sof ... /Main_Page

Here is a good guide for getting started with programming on PowerLanguage https://dl.dropbox.com/u/27918922/Getti ... nguage.pdf 
 
[FAQ] EasyLanguage / PowerLanguage: viewtopic.php?f=16&t=6929

MultiCharts/EasyLanguage learning strategies: viewtopic.php?f=1&t=11741


Return to “MultiCharts”