Please suggest how to round all available cash to maximum shares to trade

Questions about MultiCharts and user contributed studies.
Airke07
Posts: 10
Joined: 20 Apr 2021

Please suggest how to round all available cash to maximum shares to trade

Postby Airke07 » 30 Dec 2023

Hello,

I aim to make my system trade all of my available cash in IBRK account. Currently the system trades as folows:

InitialCapital+Netprofit (where InitialCapital is set manually - code below).

Unfortunately the algorithm can't calculate total net profit correctly and lots of cash is left unused. So I just want to simplify the code ,so that the system just takes all available capital and rounds to the total possible number of shares it can buy. Please kindly suggest the proper code. I am so frustrated as whater I try just doesn't seem to work.

PositionSize = InitialCapital + NetProfit; // always trades 100% of capital + netprofit made by strategy already
TradeSize = Round(PositionSize / Close[1], 0); // Round to the whole number of shares

Thank you very much and Happy New 2024!

Adi

Airke07
Posts: 10
Joined: 20 Apr 2021

Re: Please suggest how to round all available cash to maximum shares to trade

Postby Airke07 » 03 Jan 2024

Any suggestions please?

User avatar
BB123
Posts: 69
Joined: 24 Nov 2023
Has thanked: 23 times
Been thanked: 11 times

Re: Please suggest how to round all available cash to maximum shares to trade

Postby BB123 » 03 Jan 2024

Hi Adi

Not sure if this will help... But it sounds like you want to take total account available equity and use ALL of it to place a position.. Though that sounds DANGEROUS (hearing danger zone song from top gun in my head right now--- also archer "danger zone")... Try using GetRTAccountEquity as a key word..

There is also GetRTUnrealizedPL to use as a keyword-- though im not sure that is what you want...

Airke07
Posts: 10
Joined: 20 Apr 2021

Re: Please suggest how to round all available cash to maximum shares to trade

Postby Airke07 » 07 Jan 2024

Thanks so much BB!
These are new for me, I will definitely try!
Hi Adi

Not sure if this will help... But it sounds like you want to take total account available equity and use ALL of it to place a position.. Though that sounds DANGEROUS (hearing danger zone song from top gun in my head right now--- also archer "danger zone")... Try using GetRTAccountEquity as a key word..

There is also GetRTUnrealizedPL to use as a keyword-- though im not sure that is what you want...

User avatar
BB123
Posts: 69
Joined: 24 Nov 2023
Has thanked: 23 times
Been thanked: 11 times

Re: Please suggest how to round all available cash to maximum shares to trade

Postby BB123 » 07 Jan 2024

Adi feel free to reach out anytime.. Im also new to PL and MC... But i have been coding for a while in other languages and whatever knowledge i have-- im more then happy to at least try to help...


Return to “MultiCharts”