Stop trading for the day after profit reached

Questions about MultiCharts and user contributed studies.
kinginhk
Posts: 10
Joined: 14 Jul 2022
Has thanked: 3 times

Stop trading for the day after profit reached

Postby kinginhk » 15 Jul 2022

hi all,

I'm a beginner coder and new here, have only started using MC and dipping my toes into making algos for leveraged fx since the past 2 months. Thanks in advance for all the help.
I have a few questions hope someone could help me show a way:

1. i'm using SetStopContract SetStopLoss and SetPercentTrailing in every one of my signals. however, i realized that my trade entry conditions might well be valid at the same bar that stop losses or trailing stops are triggered, how can i code in to ignore that entry signal please?

2. considering i'm trading a few currencies all with their own signals as a portfolio, how can i code an exit all positions at market and stop trading all signals for the day once my overall potfolio makes a certain percentage gain?

3. I tried using portfolio trader to backtest the portfolio of fx trades, but i can't find where to input the max leverage i can use at any one time, say 10x of capital at the time.

4. finally, for autotrading settings, should i use native or emulate bid ask then send limit (or market) orders? my trades are mostly trying to make around 10pips only, so each pip lost from bid ask is important to me.

FYI, i'm using saxo as my broker, if anyone has some tips to provide, please do reply to my post, thank you very much!

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Stop trading for the day after profit reached

Postby rrams » 16 Jul 2022

Hello kingin Hong Kong?,
1. You can code a condition in your signal not to enter a new position until after a certain number of bars past the last closing trade using:

Code: Select all

if (BarsSinceExit(1)>2 or MarketPosition(1)=0) // means two bars after exit or a flat position
2. You can either add logic to every one of the signals in the portfolio to exit and not take new trades after the days gains reach a certain level or write just one Portfolio Money Management signal to do the same thing and add it to the Portfolio Settings:
mms.png
(10.45 KiB) Not downloaded yet
3. You adjust the Margin per Contract. A margin value of 20% of contract cost equals five to one leverage. 10% equals ten to one, 1% equals one hundred to one. Absolute Margin value from QuoteManager symbol settings is used when not all forex pairs have the same leverage.
mpc.png
(6.13 KiB) Not downloaded yet
4. You would want to use native limit and stop orders if they are allowed by the broker's API.

kinginhk
Posts: 10
Joined: 14 Jul 2022
Has thanked: 3 times

Re: Stop trading for the day after profit reached

Postby kinginhk » 16 Jul 2022

Thank you Rrams for helping me out. indeed i'm in hk.

As I am still a beginner here, could you please help give a bit more details please? especially for the codes needed?

1. my algo allows up to 3 trades in the same direction, thus barsSinceExit or MarketPosition =0 would not work for me.

2. would you know the code or function for the daily profit please? I think NetProfit function gives all profits since inception, not the daily one. I also don't know how to code the stop trading for the day, which is till 5pm EST for fx i believe. I would prefer coding it into each signal, to give me more flexibility.

Thank you very much!

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Stop trading for the day after profit reached

Postby rrams » 17 Jul 2022

Here is a function you can add to your chart signal to determine whether daily profit target or max loss is reached.
Daily_PnL_Limit.pla
(2.06 KiB) Downloaded 106 times
It only works on a single symbol.

It would not be productive if I provided more complex code to handle multiple symbols with multiple position entries. That would not be a good idea for a beginning coder to try to implement, even if you are already a successful discretionary trader. Everyone panics and gets angry when things go wrong. You need to start with one symbol and one position until you thoroughly understand and trust every aspect of the trading system. Then you can add one complexity at a time.

kinginhk
Posts: 10
Joined: 14 Jul 2022
Has thanked: 3 times

Re: Stop trading for the day after profit reached

Postby kinginhk » 18 Jul 2022

thanks tons Rrams

kinginhk
Posts: 10
Joined: 14 Jul 2022
Has thanked: 3 times

Re: Stop trading for the day after profit reached

Postby kinginhk » 18 Jul 2022

sorry, another beginner's question. Considering i'm trading FX pairs (eg. EURJPY), which could be different from my MC settings for base currency, which is USD. Are those NetProfit and OpenPositionProfit functions giving me amounts in base currency, ie. USD? or in EUR? or JPY?

thanks!


Return to “MultiCharts”