about code of adding to winning positions...

Questions about MultiCharts and user contributed studies.
User avatar
johnmok
Posts: 85
Joined: 18 Oct 2011
Has thanked: 30 times
Been thanked: 8 times

about code of adding to winning positions...

Postby johnmok » 25 Oct 2011

hi all, another part of the program is about adding to winning position.

my plan is to add two more contracts to the original position, which made a maximum of three in total. the conditions is to add one more contract every US$50 profit from the previous contract, the code are as follows, but after adding the following code, nothing happen, the strategy can't add to position.

any ideas? thanks!

Code: Select all

input: add_position_profit(50);

if marketposition = 1 and currentcontracts = 1 then
begin
if PosTradeProfit(0,0) >= add_position_profit then
buy next bar market;
end;

if marketposition = -1 and currentcontracts = 1 then
begin
if PosTradeProfit(0,0) >= add_position_profit then
sellshort next bar market;
end;

if marketposition = 1 and currentcontracts = 2 then
begin
if PosTradeProfit(0,1) >= add_position_profit then
buy next bar market;
end;

if marketposition = -1 and currentcontracts = 2 then
begin
if PosTradeProfit(0,1) >= add_position_profit then
sellshort next bar market;
end;

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: about code of adding to winning positions...

Postby furytrader » 25 Oct 2011

This may sound like a silly question, but when you check Format Strategies --> Strategy Properties ... do you have the checkbox marked "Allow Up To N Entries Orders In The Same Direction as The Currently Held Position" checked?

User avatar
johnmok
Posts: 85
Joined: 18 Oct 2011
Has thanked: 30 times
Been thanked: 8 times

Re: about code of adding to winning positions...

Postby johnmok » 25 Oct 2011

oh...i am sorry, you are correct, i haven't check that box. after checking the box, the script works...

thanks! :-)


Return to “MultiCharts”