Login Page - Create Account

Support Board


Date/Time: Sat, 20 Apr 2024 14:59:35 +0000



[User Discussion] - Negative numbers

View Count: 1712

[2018-09-27 04:41:36]
User701453 - Posts: 176
I need some math coding assistance with determining when a negative number is greater then another negative number.
I reviewed this documentation, but found no examples for dealing with negative numbers.
http://www.sierrachart.com/index.php?page=doc/cpp_Operators.php

I`m trying to determine when open Profit/Loss is greater then the max lost

example:
double OPL = (PositionData.OpenProfitLoss / sc.CurrencyValuePerTick); //converted to ticks
double MaxL =-fabs(MaxLoss_Value.GetInt()); //40 ticks input converted to "-40"

If (OPL >= MaxL)//this is always returning true even if OPL is zero

{
// Do work here to close out the trade
}
Date Time Of Last Edit: 2018-09-27 05:06:10
[2018-09-27 16:52:01]
User701453 - Posts: 176
No one has ever needed to compare negative numbers before while coding in ASCIL?
[2018-09-28 14:52:43]
User701453 - Posts: 176
Interesting no responses.

I guess even SC support has never needed to compare negative numbers before in ASCIL..
[2018-09-28 15:47:58]
User907968 - Posts: 802
If OPL is zero, then if(OPL >= MaxL) will return true, as 0 is greater than -40.

What happens if OPL = -41? Does it still return true?

Did you try if(OPL <= MaxL)?
[2018-09-28 17:32:04]
User701453 - Posts: 176
Yes, it still returns true with -41.
[2018-09-28 22:23:26]
bradh - Posts: 853
Your PositionData.OpenProfitLoss is a positive number if you have Profits, it is a negative number if you have losses. If you want to know if you exceeded your max loss for the day (e.g. 40) check to see if PositionData.OpenProfitLoss < -40.
[2018-09-28 22:56:03]
User701453 - Posts: 176
Thanks,
But I am internally tracking profit and lost per trade within my strat, not directly from the trading account.
In other words, I pull the last completed trade profit or lost from the trading account, do calculations for display and other things and store the data internally.

The Max profit or Loss set by an input by the user. The internally held P&L is compared to the input value. Above or below the max and strat stops trading.

This give the me the option to reset all the P&L values,within the strat by just disabling and re-enabling the strat.

If I use the current closed P&L for the account for the entire day, from the trading account.The strat will never be able to trade again for that session.

Sure I could set Max to some crazy high number,but that is not the requirement and defeats the underlying purpose.Would also destroy other coded options and features within the strat.

I have tried (OPL >= Max) and tried(OPL <= Max).
They both returns a True in ASCIL.
I must admit that I`m shocked that comparing negative numbers has never been addressed or encountered before in ASCIL.
Date Time Of Last Edit: 2018-09-28 23:19:00
[2018-09-29 08:00:47]
@sstfrederik - Posts: 403
There is no issues comparing negative numbers, maybe you have overlooked something. It happens.

zero is greater than -40 so nothing wrong there.

Just run your code and output some of the variables to yr message log. You will see soon enough what your issue really is.
[2018-10-01 17:27:12]
User701453 - Posts: 176
Finally got the negative comparisons to work.

Using VS 2017 inline debugger, with breaks and the immediate window, I was able to change values and modify code blocks.

Thanks for the assistance from everyone very much appreciated.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account