How to write the code?

Questions about MultiCharts and user contributed studies.
cktsui888
Posts: 11
Joined: 22 Mar 2017
Has thanked: 1 time

How to write the code?

Postby cktsui888 » 23 May 2017

If I want to set the stop loss and then trade after 15 bars,
How to write the code ? (The meaning is after stop loss....the position cannot trade until 15 bars)
Thx!

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How to write the code?

Postby JoshM » 26 May 2017

If I want to set the stop loss and then trade after 15 bars,
How to write the code ? (The meaning is after stop loss....the position cannot trade until 15 bars)
With the PosTradeExitCategory() keyword we can figure out what caused a trade to exit (in this case, we'd be looking for a stop-loss exit category).

If we then store the current bar number when such an exit happens (see CurrentBar), we can then later on compare that stored bar number with the current bar number to see if 15 bars have passed.

I hope this makes sense and helps you get started. :)


Return to “MultiCharts”