know the entry price and profit of a multicontracts position

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

know the entry price and profit of a multicontracts position

Postby johnmok » 27 Oct 2011

for easier understanding, let me give you an example.

i have opened a long position at $1219 for 1 contract, and then buy signal comes again.

the strategy add another contract to the long position at $1221, and after that the strategy trigger the add function again, so another contract added at $1223.

so i have three contracts in a long position at the price of 1219, 1221 and 1223.

my question is any keywords can do the job , so that i can know the three contracts entry price, and the profit of each of the three contracts?

i know there are many keywords read the above info, but they read the info between different positions, but not the multiple contracts within the position.

thanks a lot.

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

Re: know the entry price and profit of a multicontracts posi

Postby johnmok » 27 Oct 2011

oh, after i checked the dictionary up, it seems that postradeprofit and postradeentryprice can do the job....

postradeprofit(0,2) for the profit of the first contracts of the position with three contracts in total.
postradeprofit(0,1) for the profit of the second contracts.
postradeprofit(0,0) for the profit of the third contracts.

similar for the postradeentryprice?

correct me if i am wrong, thanks.

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

Re: know the entry price and profit of a multicontracts posi

Postby johnmok » 27 Oct 2011

actually, the reason i raise this question is that, my program seems can't get the profit info of the contract quite well, and keep on buy or sellshort immediately after the stop loss. the stoploss function become useless....

a problem screen shot showed as follows

Image

from the screenshot, you see that there are two problems, the first one is that my third contracts doesn't recorded a loss over my specified target, actually it's a winner trade... but the stoploss happen.

and second problem , after the stoploss, the program immediately sell short again in the next bar(as the K value is still above 80)...

so please help, thanks!
Last edited by johnmok on 28 Oct 2011, edited 1 time in total.

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: know the entry price and profit of a multicontracts posi

Postby SP » 27 Oct 2011

Not related to your code, but you can take a picture by clicking the chart - file - save image as file. I think it is easier and better to watch as using a camera.

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

Re: know the entry price and profit of a multicontracts posi

Postby johnmok » 27 Oct 2011

thanks, another cropped image uploaded :-)

Image

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

Re: know the entry price and profit of a multicontracts posi

Postby johnmok » 28 Oct 2011

problem solved, thanks all.

vking
Posts: 235
Joined: 21 May 2009
Has thanked: 51 times
Been thanked: 41 times

Re: know the entry price and profit of a multicontracts posi

Postby vking » 28 Oct 2011

johnmok - Would you please post the solution if possible. Curious to know about the solution.

Thanks.

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

Re: know the entry price and profit of a multicontracts posi

Postby johnmok » 28 Oct 2011

actually...i just make a silly mistake....

my strategy is something like the rsi value > 80 and then i sell short , and set stop loss to the strategy

and i set the code as

Code: Select all

if myRSIvalue > 80 then sell short next bar market
but the problem is that, for an rsi type strategy, when you have to stop loss the sell short position, the rsi are usually still higher than 80, that means immediately after the stop loss, the condition of rsivalue > 80 will be true, and therefore, sellshort again immediately after stop loss.

the solution is simple, change the code to

Code: Select all

if myRSIvalue cross over 80 then sell short next bar market
then for most case, the system won't enter market again after stop loss, it will wait the rsi value drop below 80, and if the rsi goes up again, the system will then go short.

that solve my problem.


Return to “MultiCharts”