RSS Negative Risk aka in Profit?

Currently reading:
 RSS Negative Risk aka in Profit?

Status
Not open for further replies.

Crax Bot

Staff member
Administrator
Amateur
LV
0
Joined
Nov 5, 2021
Threads
15,352
Likes
1,923
Credits
33,933©
Cash
0$
Code:
double Total_Current_Risk()
{

    double res = 0;
    for (int i = 0; i < OrdersTotal(); i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderStopLoss() != 0)
        {
            double m_point = MarketInfo(OrderSymbol(), MODE_POINT);
            double m_lotstep = MarketInfo(OrderSymbol(), MODE_LOTSTEP);
            double m_TickValue = MarketInfo(OrderSymbol(), MODE_TICKVALUE);
            double m_sl = 0;
            if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP)
            {
                m_sl = (OrderOpenPrice() - OrderStopLoss()) / m_point;
            }
            else
            {
                m_sl = (OrderStopLoss() - OrderOpenPrice()) / m_point;
            }
            res += NormalizeDouble((OrderLots() * (m_sl * m_TickValue)) + OrderCommission() + OrderSwap(), 2);
        }
    }
    Print("Account Balance: ", AccountBalance(), " -- Total Current Risk (with swap and commission): ", res, " -- Net Balance: ", AccountBalance() - res);
    return res;
}

void OnTick()

Account Balance 500 USD
let say i buy instrument at 100 USD
stop loss 90
risk 100 - 90 = -10 USD

instrument goes up in my favor,
current price 120
open active trade is in profit,
trailing stop loss moved to 110

will Total_Current_Risk() return 100-110 = -10 ?

Net Balance: ", AccountBalance() - res

500 - -10 = 510 USD?

1 post - 1 participant

Read full topic
 
Status
Not open for further replies.
Top Bottom