About scripts for adding to winning positions  [SOLVED]

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 scripts for adding to winning positions  [SOLVED]

Postby johnmok » 17 Feb 2020

Hi all,

i want to have add position for a long strategy, using the following scripts, but doesn't work.

Code: Select all

input: AddFunction(True), StopLoss(50); if AddFunction then begin if marketposition = 1 then begin if (High - entryprice) > StopLoss then buy("L-Add") next bar market; end;
it seems that whenever the price > entryprice + 50, it keep buying contract every next bar....
what i want is that, after entering a trade, say like buy at 15000, then the system keep adding at price like 15050, 15100, 15150, etc.
adding every 50 points.

Image

you may notice that from the entry point, after the price move up for 50pts, the signal keep buying one more contract every bar afterward( 5mins chart)

i noticed that maybe i've got some wrong understanding about "entryprice", i thought that "entryprice" will return the value of the buy price of the latest long contract, but it seems not, it can only returns the first long contract's buy price from the chart above.....

so i modified part of the code, like using new variable "addlevel" and add a loop like " addlevel = addlevel+50" to manually calculate the latest reference level, but the result is that the add Function completely failed to work....the modified script and screenshot shown below for your reference.

Code: Select all

input: AddFunction(True), StopLoss(50); var: addlevel(entryprice); if AddFunction then begin if marketposition = 1 then begin if (High - addlevel) > StopLoss then buy("L-Add") next bar market; addlevel = addlevel + StopLoss; end;
Image

ps:

1. the EOD exit signal is just a signal that close all existing opening position on daily session close, no big deal with the problem.
2. AddFunction is a switch that turn on and off the add function of the strategy
3. variable StopLoss is a constant in this case, so it's just a value "50"

any idea guys? thank you!
Last edited by johnmok on 17 Feb 2020, edited 8 times in total.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: About scripts for adding to winning positions

Postby TJ » 17 Feb 2020

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

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

Re: About scripts for adding to winning positions

Postby johnmok » 17 Feb 2020

See post #1 & #2 . . . & post #4
viewtopic.php?t=11713
thanks TJ!! :mrgreen:

got the post amended :lol:

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

Re: About scripts for adding to winning positions

Postby johnmok » 20 Feb 2020

Problem solved by using

PosTradeEntryPrice

Thanks guys


Return to “MultiCharts”