Margin calculations in Strategy Tester

 

Hello everyone,

I am having problems with the strategy tester and would like to verify my point of view on the issue.

I am backtesting an EA and I get following log output in the journal. Could somebody shed some light on this maybe, because i simply dont understand why this situation comes up?


Please see the screenshots:



Are there any settings I am missing???

 

Obviously the margin doesn't match your volume/leverage.

Check your code, are you sure your log information are the good ones ?

 
Alain Verleyen:

Obviously the margin doesn't match your volume/leverage.

Check your code, are you sure your log information are the good ones ?

Yes I am.

***

 
Dominik Egert :

Yes I am.

***

Please insert the code correctly - when editing your message, use the button Code

 
Vladimir Karputov:

Please insert the code correctly - when editing your message, use the button

Well, I know about that button. Thank you for pointing me in this direction.

You have just removed the curcial information, that was highligted in the screenshot and was asked for.

This Information cannot be posted in a code section, therefore I will post a new screenshot.

Thakn you for your attention.

Please do not remove this screenshot.

Logfile output verification.

 
Dominik Egert :


What prevents you from inserting the code correctly? Why do you place the code IN THE FORM OF A PICTURE ???

 
Vladimir Karputov:

What prevents you from inserting the code correctly? Why do you place the code IN THE FORM OF A PICTURE ???

It is not about the code, but about the lines where the code is written to verify the output of the log...

As you can see, there is a highlight. Ive explained this in my post with the new screenshot. If you take a close look at the initial screenshot from the journal/log, you will find the output shows file, function, line and then the value thats being printed to the journal/log. - Since ive been asked if the log is correct, ive posted exactly this as a screenshot.

Cant you see the highliting in the screenshot? - How would I post this as a code-section?


Here is the ful function in a code-section as you wished for.

//+------------------------------------------------------------------+
//| send_order()                                                     |
//+------------------------------------------------------------------+
const ulong send_order(MqlTradeRequest &request)
{
    // Local init
    MqlTradeCheckResult check_result    = {0};
    MqlTradeResult      result          = {0};
    ZeroMemory(check_result);
    ZeroMemory(result);


    // Test newly created order
    if(!OrderCheck(request, check_result))
    { 
        #ifdef LIB_DEBUG
                DBG_MSG_VAR(request.action);
                DBG_MSG_VAR(request.magic);
                DBG_MSG_VAR(request.order);
                DBG_MSG_VAR(request.symbol);
                DBG_MSG_VAR(request.volume);
                DBG_MSG_VAR(request.price);
                DBG_MSG_VAR(request.stoplimit);
                DBG_MSG_VAR(request.sl);
                DBG_MSG_VAR(request.tp);
                DBG_MSG_VAR(request.deviation);
                DBG_MSG_VAR(request.type);
                DBG_MSG_VAR(request.type_filling);
                DBG_MSG_VAR(request.type_time);
                DBG_MSG_VAR(request.expiration);
                DBG_MSG_VAR(request.comment);
                DBG_MSG_VAR(request.position);
                DBG_MSG_VAR(request.position_by);
    
                DBG_MSG_VAR(check_result.retcode);
                DBG_MSG_VAR(check_result.balance);
                DBG_MSG_VAR(check_result.equity);
                DBG_MSG_VAR(check_result.margin);
                DBG_MSG_VAR(check_result.margin_free);
                DBG_MSG_VAR(check_result.margin_level);
                DBG_MSG_VAR(check_result.comment);
        #endif
        return(check_result.retcode); 
    }
    else
    {
        const ulong pos_request = request.position;
        // Send order to server
        if(OrderSend(request, result))
        {
            // Verify result
            if(result.order > 0)
            { request.position = result.order; }
            else if(result.deal > 0)
            { request.position = result.deal; }
            
            switch(request.action)
            {
                case TRADE_ACTION_PENDING:  
                case TRADE_ACTION_REMOVE:   
                case TRADE_ACTION_CLOSE_BY: 
                case TRADE_ACTION_DEAL:     
                    
                    // Add to pending wait
                    lib_fw::global_pending_server_requests++;
                    #ifdef LIB_DEBUG
                        DBG_MSG("********* New pending order ****************");
                        DBG_MSG_VAR(lib_fw::global_pending_server_requests);
                        DBG_MSG_VAR(request.action);
                                        DBG_MSG_VAR(request.type);
                        DBG_MSG_VAR(request.order);
                                        DBG_MSG_VAR(request.position);
                                        DBG_MSG_VAR(request.position_by);
                                        DBG_MSG_VAR(result.retcode);
                                        DBG_MSG_VAR(result.deal);
                                        DBG_MSG_VAR(result.order);
                        DBG_MSG_VAR(pos_request);
                        DBG_MSG_VAR(request.magic);
                    #endif
                    

                case TRADE_ACTION_SLTP:     
                case TRADE_ACTION_MODIFY:
                    break;
            }
/*
            static int last_pendings = NULL;
            if(lib_fw::global_position_pending != last_pendings)
            { DebugBreak(); last_pendings = lib_fw::global_position_pending; }
*/
        }
                else if(result.retcode == TRADE_RETCODE_REQUOTE)
                { 
                        const double    price_deviation = request.price - ((request.type == ORDER_TYPE_SELL) ? result.bid : result.ask);
                        const int               digits = (int)SymbolInfoInteger(request.symbol, SYMBOL_DIGITS);
                        request.price   = MathRound(request.price - price_deviation, digits);
                        request.sl              = MathRound(MathAbs(request.sl - price_deviation), digits) * inline_BooleanDouble(request.sl > (1.0 / MathPow(10, digits)));
                        request.tp              = MathRound(MathAbs(request.tp - price_deviation), digits) * inline_BooleanDouble(request.tp > (1.0 / MathPow(10, digits)));

/*
                        #ifdef LIB_DEBUG
                                DBG_MSG_VAR(SymbolInfoDouble(request.symbol, SYMBOL_ASK));
                                DBG_MSG_VAR(SymbolInfoDouble(request.symbol, SYMBOL_BID));
                                DBG_MSG_VAR(request.action);
                                DBG_MSG_VAR(request.magic);
                                DBG_MSG_VAR(request.order);
                                DBG_MSG_VAR(request.symbol);
                                DBG_MSG_VAR(request.volume);
                                DBG_MSG_VAR(request.price);
                                DBG_MSG_VAR(request.stoplimit);
                                DBG_MSG_VAR(request.sl);
                                DBG_MSG_VAR(request.tp);
                                DBG_MSG_VAR(request.deviation);
                                DBG_MSG_VAR(request.type);
                                DBG_MSG_VAR(request.type_filling);
                                DBG_MSG_VAR(request.type_time);
                                DBG_MSG_VAR(request.expiration);
                                DBG_MSG_VAR(request.comment);
                                DBG_MSG_VAR(request.position);
                                DBG_MSG_VAR(request.position_by);
                
                                DBG_MSG_VAR(result.retcode);
                                DBG_MSG_VAR(result.deal);
                                DBG_MSG_VAR(result.order);
                                DBG_MSG_VAR(result.volume);
                                DBG_MSG_VAR(result.price);
                                DBG_MSG_VAR(result.bid);
                                DBG_MSG_VAR(result.ask);
                                DBG_MSG_VAR(result.comment);
                                DBG_MSG_VAR(result.request_id);
                                DBG_MSG_VAR(result.retcode_external);
                        #endif
*/
                }

        #ifdef LIB_DEBUG
                else
                {
            DBG_MSG_VAR(SymbolInfoDouble(request.symbol, SYMBOL_ASK));
            DBG_MSG_VAR(SymbolInfoDouble(request.symbol, SYMBOL_BID));
                        DBG_MSG_VAR(request.action);
                        DBG_MSG_VAR(request.magic);
                        DBG_MSG_VAR(request.order);
                        DBG_MSG_VAR(request.symbol);
                        DBG_MSG_VAR(request.volume);
                        DBG_MSG_VAR(request.price);
                        DBG_MSG_VAR(request.stoplimit);
                        DBG_MSG_VAR(request.sl);
                        DBG_MSG_VAR(request.tp);
                        DBG_MSG_VAR(request.deviation);
                        DBG_MSG_VAR(request.type);
                        DBG_MSG_VAR(request.type_filling);
                        DBG_MSG_VAR(request.type_time);
                        DBG_MSG_VAR(request.expiration);
                        DBG_MSG_VAR(request.comment);
                        DBG_MSG_VAR(request.position);
                        DBG_MSG_VAR(request.position_by);
        
                        DBG_MSG_VAR(result.retcode);
                        DBG_MSG_VAR(result.deal);
                        DBG_MSG_VAR(result.order);
                        DBG_MSG_VAR(result.volume);
                        DBG_MSG_VAR(result.price);
                        DBG_MSG_VAR(result.bid);
                        DBG_MSG_VAR(result.ask);
                        DBG_MSG_VAR(result.comment);
                        DBG_MSG_VAR(result.request_id);
                        DBG_MSG_VAR(result.retcode_external);
                }
        #endif


        // Return
        return(result.retcode);
    }

    // Return
    return((ulong)EMPTY_VALUE);
}
 
Dominik Egert :


It's simple - highlight the desired part with color:

                        DBG_MSG_VAR(result.deal);
                        DBG_MSG_VAR(result.order);
                        DBG_MSG_VAR(result.volume);
                        DBG_MSG_VAR(result.price);
                        DBG_MSG_VAR(result.bid);
                        DBG_MSG_VAR(result.ask);
                        DBG_MSG_VAR(result.comment);
                        DBG_MSG_VAR(result.request_id);
                        DBG_MSG_VAR(result.retcode_external);
                }
        #endif
 
Vladimir Karputov:

It's simple - highlight the desired part with color:

And where are the code line numbers now??

It is impossible to post them, as desired....

let me show you in another screenshot....


 
Dominik Egert :

And where are the code line numbers now??

It is impossible to post them, as desired....

let me show you in another screenshot....


Each feature is unique. There are no two functions with the same name in one code :) Therefore, it is enough to show the function. It's very simple.

It is all the more foolish to focus on the line number - everyone can use different styles of the styler and therefore the line numbers will be different.
 
Vladimir Karputov:

Each feature is unique. There are no two functions with the same name in one code :) Therefore, it is enough to show the function. It's very simple.

OK. So I am giving to much information? Is my verification of the log output to much in detail?

Reason: