AlunParticipant
Average
When using True to activate cumulative positions, is there a simple way to limit the number of positions to a maximum?
COUNTOFPOSITION returns the number of open positions.
COUNTOFLONGSHARES returns the number of open Long positions.
COUNTOFSHORTSHARES returns the number of open Short positions.
Example:
MaxPositionsAllowed = 5
If MyConditions And CountOfPosition < MaxPositionsAllowed Then
Buy 1 contract at market
Endif
Don’t forget that COUNTOFPOSITION is a negative value if you are short on the market and a positive value if you are long. You can use:
abs(countofposition)
to return only a positive value. So Roberto’s code needs to be like the following to work with short position quantities.
MaxPositionsAllowed = 5
If MyConditions And abs(CountOfPosition) < MaxPositionsAllowed Then
Sellshort 1 contract at market
Endif
AlunParticipant
Average
This looks very good – many thanks Roberto and Vonasi!!
Copied to here
Snippet Link Library
Another successful collaboration on the Snippet Log! 🙂
z = n*3/2
And is n*3/2 allowed as a lot size for the Instrument you are trading?
If it were me I would concentrate on making a profit by getting the strategy correct for Long entry / exit and Short entry / exit and use Lot size = 1 for simplicity?
After you are making consistent profit every week for months … then tweak lot size etc??
Sorry @GraHal, I deleted all of his posts here because he had started another topic in the French forum.
You may want to post your reply, in French, there https://www.prorealcode.com/topic/taille-de-position-en-fonction-de-lhoraire-de-trading/.